What is the use of “push

前端 未结 6 1630
我寻月下人不归
我寻月下人不归 2020-12-23 09:38

What effect these two instructions cause in the assembly code generated by gcc for x86 machines:

push %ebp
movl %esp, %ebp
6条回答
  •  孤城傲影
    2020-12-23 10:06

    push %ebp
    

    This will push the 32 bit (extended) base pointer register on the stack, i.e. the stack pointer (%esp) is subtracted by four, then the value of %ebp is copied to the location that the stack pointer points to.

    movl %esp, %ebp
    

    This copies the stack pointer register to the base pointer register.

    The purpose of copying the stack pointer to the base pointer is to create a stack frame, i.e. an area on the stack where a subroutine can store local data. The code in the subroutine would use the base pointer to reference the data.

提交回复
热议问题