So I was reading chapter 3 of CSAPP (3.7.4 Local Storage on the Stack).
In Figure 3.31, there is this snippet of code:
long caller() {
long arg1 = 534;
long arg2 = 1057;
long sum = swap_add(&arg1, &arg2);
long diff = arg1 - arg2;
return sum * diff;
}
and its generated assembly:
caller:
subq $16, %rsp
movq $534, (%rsp)
movq $1057, 8(%rsp)
leaq 8(%rsp), %rsi
movq %rsp, %rdi
call swap_add
movq (%rsp), %rdx
subq 8(%rsp), %rdx
imulq %rdx, %rax
addq $16, %rsp
ret
My question is that why not use pushq $1057
then pushq $534
here.
I'm also aware that if we want to allocate space for some variable and leave it uninitialized, we should decreament $rsp
directly as here. But I can't relate this fact with my question here.