mirror of
https://github.com/sigmasternchen/fibonacci
synced 2025-03-14 23:58:57 +00:00
added 32 bit asm version
This commit is contained in:
parent
4ddc3602a3
commit
1ee35701fc
2 changed files with 63 additions and 0 deletions
6
asm/Makefile
Normal file
6
asm/Makefile
Normal file
|
@ -0,0 +1,6 @@
|
|||
|
||||
all: fib32
|
||||
|
||||
fib32: fib32.asm
|
||||
nasm -f elf32 fib32.asm
|
||||
gcc -m32 -no-pie fib32.o -o $@
|
57
asm/fib32.asm
Normal file
57
asm/fib32.asm
Normal file
|
@ -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
|
Loading…
Reference in a new issue