It clearly depends on your hardware architecture and your compiler. On x86 x86 using gcc your code compiles to:
.file "call.c" .text .globl add .type add, @function add: .LFB0: .cfi_startproc pushq %rbp .cfi_def_cfa_offset 16 movq %rsp, %rbp .cfi_offset 6, -16 .cfi_def_cfa_register 6 movl %edi, -20(%rbp) movl %esi, -24(%rbp) movl -24(%rbp), %eax movl -20(%rbp), %edx leal (%rdx,%rax), %eax movl %eax, -4(%rbp) movl -4(%rbp), %eax ; return value placed in EAX leave ret .cfi_endproc .LFE0: .size add, .-add .globl main .type main, @function main: .LFB1: .cfi_startproc pushq %rbp .cfi_def_cfa_offset 16 movq %rsp, %rbp .cfi_offset 6, -16 .cfi_def_cfa_register 6 subq $16, %rsp movl $3, %esi movl $2, %edi call add movl %eax, -4(%rbp) ; the result of add is stored in sum leave ret .cfi_endproc .LFE1: .size main, .-main .ident "GCC: (Ubuntu 4.4.3-4ubuntu5) 4.4.3" .section .note.GNU-stack,"",@progbits
Here, the compiler uses the EAX register to pass the result of add caller.
You can read x86 calling conventions on Wikipedia .
NPE
source share