Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- %include "io.inc"
- global main
- section .text
- ;
- ; arg1 = n
- ;
- sum:
- push ebp ; save caller EBP
- mov ebp, esp
- cmp dword [ebp + 8], 0 ; if (arg1 > 0)
- jng .false ; jump if not greater
- .true____unused_label: ; arg1 > 0
- mov edx, [ebp + 8] ; copy arg1 to newarg1
- dec edx ; newarg1--
- push edx ; push newarg1
- call sum ; recursion call. Result will be in EAX
- add esp, 4 ; drop pushed newarg1 after call
- add eax, [ebp + 8] ; result += arg1
- jmp .end ;
- .false: ; arg1 <= 0
- mov eax, 0 ; result = 0
- .end:
- ; mov esp, ebp ; useless sh*t
- pop ebp ; restore caller EBP
- ret ; return back to caller, EAX already contains result
- main:
- push 5
- call sum ; 5 + 4 + 3 + 2 + 1 + 0 = 15
- PRINT_DEC 4, eax
- ; system call exit()
- xor eax, eax
- mov al, 1
- xor ebx, ebx
- int 0x80
Add Comment
Please, Sign In to add comment