Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extern printf
- SECTION .data
- p1_fmt: db 0xA,`\nOutput: %d\n`, 0xA, 0
- SECTION .text
- global main
- main:
- ;-------------------------------------------------------------------------------------------------------------------
- fibonacci:
- push ebp ;Build Stack Frame(?)
- mov ebp, esp
- sub esp, 16
- mov eax, [ebp+8]; ;what is this, and what does it do?
- cmp eax, 2
- jae recur
- xor edx, edx ;Set contents of edx to zero, why?
- jmp done
- ;-------------------------------------------------------------------------------------------------------------------
- recur:
- sub eax, 2
- push eax ; compute fib(n-2)
- call fibonacci
- mov [ebp-8], eax ; save returned value in 8-byte local variable...
- mov [ebp-4], edx ; ...in Little-Endian byte order.
- mov eax, [ebp+8] ; get argument again
- dec eax
- push eax ; compute fib(n-1)
- call fibonacci
- mov [ebp-16], eax ; save returned value in 8-byte local variable...
- mov [ebp-12], edx ; ...in Little-Endian byte order.
- mov eax, [ebp-8]
- mov edx, [ebp-4] ; retrieve 1st computed value
- add eax, [ebp-16]
- adc edx, [ebp-12] ; add 2nd computed value
- ;-------------------------------------------------------------------------------------------------------------------
- done:
- pop edx
- push edx
- push p1_fmt ;push address of format string
- call printf ;Call C function
- add esp, 12 ;adjust ESP to remove parameter
- mov esp, ebp
- pop ebp
- ret ;return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement