From 1ee35701fc18883afee72dd80251f74f78fa0e75 Mon Sep 17 00:00:00 2001 From: overflowerror Date: Sat, 22 Aug 2020 19:33:55 +0200 Subject: [PATCH] added 32 bit asm version --- asm/Makefile | 6 ++++++ asm/fib32.asm | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 asm/Makefile create mode 100644 asm/fib32.asm 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