How is return address specified in stack?

后端 未结 4 688
耶瑟儿~
耶瑟儿~ 2021-01-02 09:19

This is what I see by disassemble for the statement function(1,2,3);:

movl   $0x3,0x8(%esp)
movl   $0x2,0x4(%esp)
movl   $0x1,(%esp)
call   0x40         


        
4条回答
  •  南笙
    南笙 (楼主)
    2021-01-02 09:47

    On an x86 processor (as for your assembly language example), the call instruction pushes the return address on the stack and transfers control to the function.

    So on entry to a function, the stack pointer is pointing at a return address, ready for ret to pop it into the program counter (EIP / RIP).


    Not all processor architectures put the return address on the stack- often there's a set of one or more registers designed to hold return addresses. On ARM processors, the BL instruction places the return address in a specific register (LR, or the 'link register') and transfers control to the function.

    The ia64 processor does something similar, except that there are several possible registers (b0-b7) that can receive the return address and one will be specified in the instruction (with b0 being the default).

提交回复
热议问题