%include "IO_DEFS.asm" ; Because my memory is not working ; x /11g $rsp section .data base dd 2 power dd 10 section .bss buffer resb 16 section .text global _start Power: ; parameters: ; rdi: the base ; esi: the power ; set up for the function. 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. ; if power == 0 test esi, esi jnz power_recurse mov rax, 1 ; rax = 0 jmp power_exit power_recurse: dec esi ; power-- call Power ; rax = power(base, power) mul edi ; rax = base * rax power_exit: ; at this point, rax contains the return value ; right now the stack contains ra, rbp, esi pop rsi ; remove esi from the stack pop rbp ; restore the base pointer ret _start: mov edi, [base] mov esi, [power] call Power ; print the result lea edi, [buffer + 15] mov byte [edi], 0x0A convert: dec edi ; edi-- Carter page 23 mov edx, 0 ; edx = 0 mov ecx, 10 ; ecx = 10 div ecx ; eax = edx:eax/ecx edx = edx:eax%ecx ; carter page 44 add dl, '0' ; dl + '0' add ascii 0 to the digit mov [edi], dl ; store the new character in edi buffer[14] = digit test eax, eax ; check for any bits of eax not zero ; carter page 51 jnz convert mov esi, edi ; edi needs the start position of the string. lea edx, [buffer+16] ; edx needs the length of the string ; the last character in the buffer. sub edx, edi ; starting poisition - end position mov eax, SYS_WRITE mov edi, STDOUT ; set the destination to stdout syscall ; Exit mov eax, SYS_EXIT mov edx, SUCCESS syscall