I came across “pushq %rsp” and I couldn’t figure out the exact operations CPU does.
On x86-64 Assembly,
.text
.globl pushtest pushtest:
movq %rsp, %rax
pushq %rsp
popq %rdx
subq %rdx, %rax
ret
the return value %rax is 0, by subtracting the new value of %rsp in %rdx from the old value of %rsp in %rax.
But formal definition of push instruction is:
- decrement %rsp by 8
- push the designated value (in this case, the value of %rsp) onto the stack.
So when we do “pushq %rsp,” doesn’t it decrements the %rsp first, then push the decremented %rsp value onto the stack, which would result in the subtraction being 8 instead of 0?