diff --git a/asm/Makefile b/asm/Makefile new file mode 100644 index 0000000..7e44f28 --- /dev/null +++ b/asm/Makefile @@ -0,0 +1,6 @@ + +all: fib32 + +fib32: fib32.asm + nasm -f elf32 fib32.asm + gcc -m32 -no-pie fib32.o -o $@ diff --git a/asm/fib32.asm b/asm/fib32.asm new file mode 100644 index 0000000..a9ecc79 --- /dev/null +++ b/asm/fib32.asm @@ -0,0 +1,57 @@ +section .text + +global main +extern printf + +fib: + pop ebx + pop ecx + pop eax + pop edx + sub esp, 12 + push ebx + + cmp ecx, 0 + je fibend + +fibloop: + mov ebx, eax + add ebx, edx + + push ecx ; ecx is not callee-saved in the linux abi + + push ebx + push edx + push eax + push format + + call printf + + add esp, 8 + pop eax + pop edx + + pop ecx + + dec ecx + jnz fibloop +fibend: + ret + +main: + mov ebx, 1 + push ebx + push ebx + mov ebx, 5 + push ebx + + call fib + + add esp, 12 + + mov eax, 0 ; return 0 + ret + +section .data +format: + db '%d + %d = %d', 10, 0