Alex Rivera | Logout

What is the use of "push %ebp; movl %esp, %ebp" generated by GCC for x86?

Asked 2010-03-25T12:54:30.530
36

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

push %ebp
movl %esp, %ebp
Edit
Report

1 Answer

9
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.

answered 2010-03-25T13:05:46.083

Your Answer