$\require{cancel}$
power
int pow(int base, int exponent) { int rv; if (exponent == 0) { rv = 1 } else { rv = base * pow(base, exponent-1) } return rv; } int main() { cout << pow(2, 10) << endl; return 0; }
push rbp ; save the current base pointer mov rbp, rsp ; set the base pointer to point to the current stack pointer push rsi ; not needed but we want to look at it.
The Stack | |
---|---|
Register | Value |
sp on enter | return address |
bp | old bp |
sp | rsi |
extern
in the main file.
nasm -f elf64 -g MY_IO.asm -o MY_IO.o nasm -f elf64 -g pow2.asm -o pow2.o ld -g pow2.o MY_IO.o -o pow2