假设这段代码:
int add(int a, int b){
int c = a+b;
return c;
}
int main(){
printf("%d\n", add(3,4));
}
以下通常是在汇编中如何实现的:
- push 4 to stack
- push 3 to stack
- push return address which is the address of the next instruction, `print()` to stack
- call add
- do addition and push c on the stack
- pop c from stack ??
- return to main
那么返回值会发生什么,它不能在add框架上,因为它会在最后被清除。它会被放入堆栈main吗?
让我们假设这些值被推送到大头钉而不是寄存器。