I am trying to correctly understand where and how I push and pop callee-saved registers like ebx onto/off the stack to restore them for later use.
Is this code correctly restoring the ebx register?
global main
extern printf
section .text:
print:
mov eax, 0x1
add eax, ebx
push eax
push message
call printf
add esp, 8
ret
main:
mov ebx, 0x1
push ebx
call print
pop ebx
ret
message db "result = %d", 10, 0
Should I pop ebx directly after usage like so?:
global main
extern printf
section .text:
print:
push ebx
mov ebx, 0x1
mov eax, 0x1
add eax, ebx
push eax
push message
call printf
add esp, 8
pop ebx
ret
main:
call print
ret
message db "result = %d", 10, 0