Home > Enterprise >  The value contained in %rsp register
The value contained in %rsp register

Time:01-07

So I'm dealing with these Assembly codes:

enter image description here

With the address of %rsp = 0x7FFFFFFFDE88 before calling foo

After calling the function foo, a new element is pushed to the stack frame %rsp so the address of %rsp is now should be 0x7FFFFFFFDE80 and it should contain the address of the instruction right after the callq instruction. In the entry of the function foo, it sub $0x38 to %rsp to push more elements, so %rsp is now 0x7FFFFFFFDE48. I have some question with the instruction 67e: When movq $0x2, (%rsp), is it moved to the address of 0x7FFFFFFFDE48, which is the start of %rsp?

CodePudding user response:

Yes. Here's what the stack would look like:

0x7FFFFFFFDE48: 02 00 00 00 00 00 00 00
0x7FFFFFFFDE50: 03 00 00 00 00 00 00 00
0x7FFFFFFFDE58: 05 00 00 00 00 00 00 00
0x7FFFFFFFDE60: 07 00 00 00 00 00 00 00
0x7FFFFFFFDE68: ?? ?? ?? ?? ?? ?? ?? ?? (Your code never wrote to this memory)
0x7FFFFFFFDE70: ?? ?? ?? ?? ?? ?? ?? ?? (Your code never wrote to this memory)
0x7FFFFFFFDE78: ?? ?? ?? ?? ?? ?? ?? ?? (Your code never wrote to this memory)
0x7FFFFFFFDE80: D5 06 00 00 00 00 00 00 (return address)
0x7FFFFFFFDE88: ?? ?? ?? ?? ?? ?? ?? ?? (Your code never wrote to this memory)

Notice that at line 6d0: e8 95 ff ff ff callq 66a <foo> the address after that is 6d5. If you subtract 6d5 from 66a you get 0xFFFFFF95 (which when sign-extended is the relative distance between the first line of code in foo).

  • Related