4

Take:

void callee(void);
long call_and_ret_saved(long ToSave){
    callee();
    return ToSave;
}

where the generated assembly will need to save the value of the ToSave argument in order to be able to return it after the call to callee.

Both gcc and clang generate:

call_and_ret_saved:
    pushq   %rbx
    movq    %rdi, %rbx
    call    callee
    movq    %rbx, %rax
    popq    %rbx
    ret

for it. Why not simply push %rdi; call callee; pop %rax; ret; ? Does using the call-preserved register make the return value available sooner or something?

Michael Petch
  • 46,082
  • 8
  • 107
  • 198
Petr Skocik
  • 58,047
  • 6
  • 95
  • 142

0 Answers0