From 99fcc633ec17f0291d7db174ca60a7632e2df72b Mon Sep 17 00:00:00 2001 From: Joe Hunkeler Date: Thu, 24 Sep 2015 00:18:11 -0400 Subject: Add prog4 -- Inefficient while loop + stack play --- Makefile | 14 +++++++++++++- prog4.asm | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 prog4.asm diff --git a/Makefile b/Makefile index e79294d..5f91a2b 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -all: prog1 prog2 +all: prog1 prog2 prog3 prog4 prog1: prog1.o ld -m elf_i386 -o $@ $< @@ -12,6 +12,18 @@ prog2: prog2.o prog2.o: prog2.asm nasm -f elf -g -o $@ $< +prog3: prog3.o + ld -m elf_i386 -o $@ $< + +prog3.o: prog3.asm + nasm -f elf -g -o $@ $< + +prog4: prog4.o + ld -m elf_i386 -o $@ $< + +prog4.o: prog4.asm + nasm -f elf -g -o $@ $< + .PHONY: clean clean: rm -rf *.o prog[0-9] diff --git a/prog4.asm b/prog4.asm new file mode 100644 index 0000000..0a49cd8 --- /dev/null +++ b/prog4.asm @@ -0,0 +1,65 @@ +; begin playing around with variables! +section .bss + fart_count: resb 4 + +section .data + fart_max: db 255 + +section .text + global _start + +dofarts: + push ebp + mov ebp, esp + add ebp, 4 + + ; set the fart_count to zero + mov DWORD [fart_count], 0 + + ; save eax to the stack because we're gonna use it + push eax + + jmp dofarts.keepgoing + +dofarts.stop: + ;clean up and return + pop eax + pop ebp + ret + +dofarts.keepgoing: + ; put fart_count into a register (i wish i could do mem,mem) + mov eax, [fart_count] + + ; increment the fart_count + add dword[fart_count], 1 + + ; has fart_count reached fart_max? + jge dofarts.check + ; else, stop... this is redundant... + jmp dofarts.stop + +dofarts.check: + ; is fart_count (eax) fart_max? + cmp eax, [fart_max] + ; if so, stop + jge dofarts.stop + ; else keep going + jmp dofarts.keepgoing + + +_start: + push ebp + mov ebp, esp + + call dofarts + mov ebx, [fart_count] + add ebx, [fart_max] + + mov esp, ebp + pop ebp + + mov eax, 1 + ;mov ebx, 0 + int 80h + ret -- cgit