Created
December 19, 2018 01:07
-
-
Save seisvelas/d04b8c1aa9af3fc1a9263723a33a94a4 to your computer and use it in GitHub Desktop.
Recursive power function for MacOS nasm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
section .data | |
section .text | |
global start | |
global power | |
power: | |
; ro ro fite | |
push rbp | |
mov rbp, rsp | |
mov r12, [rbp+16] ; 3 (base) | |
mov r13, [rbp+24] ; 4 (power) | |
imul rdi, r12 | |
cmp r13, 1 ; if r13==1 return | |
je return | |
dec r13 | |
push r13 | |
push r12 | |
call power ; woah recuuuuurrrssiOnN | |
return: | |
mov rsp, rbp ; realign the stuck after we f-d it up by pushing | |
pop rbp | |
ret | |
start: | |
push 4 ; rsp+24 | |
push 3 ; rsp+16 | |
mov rdi, 1 | |
call power | |
mov rax, 0x2000001 ; exit() | |
syscall |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment