Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- extern printf
- global main
- section .data
- format db "%d ", 10, 0
- section .text
- call main
- ret
- factorial:
- push ebp
- mov ebp, esp
- cmp dword[ebp + 8], 0;n == 0
- jne recursive_return
- mov eax, 1
- jmp epilogue
- recursive_return:
- mov eax, [ebp + 8]
- sub eax, 1;n - 1
- push eax
- call factorial
- add esp, 4
- mov ebx, eax
- mov eax, [ebp + 8];n
- cdq; edx:eax
- imul eax, ebx;n * factorial(n - 1)
- epilogue:
- leave
- ret
- main:
- push ebp
- mov ebp, esp
- push 7;n argument
- call factorial
- add esp, 4
- push eax
- push format
- call printf
- add esp, 8
- leave
- mov eax, 0
- ret
Add Comment
Please, Sign In to add comment