Local variables offset from the stack pointer

I am trying to learn more about the stack pointer and the base. The following sample build code is from the objdump binary compiled by gcc on IA32.

08048e0b <func_3>: 8048e0b: 55 push %ebp 8048e0c: 89 e5 mov %esp,%ebp 8048e0e: 83 ec 28 sub $0x28,%esp 8048e11: 8d 45 f0 lea -0x10(%ebp),%eax 8048e14: 89 44 24 0c mov %eax,0xc(%esp) 8048e18: 8d 45 f4 lea -0xc(%ebp),%eax 8048e1b: 89 44 24 08 mov %eax,0x8(%esp) 8048e1f: c7 44 24 04 65 9b 04 movl $0x8049b65,0x4(%esp) 

I know that the %ebp base pointer is used to refer to function parameters and local variables. Are usually positive offsets the parameters passed to the function, and negative offsets are local variables?

On line 8048e18: 8d 45 f4 lea -0xc(%ebp),%eax What is -0xc (% ebp), referring to?

+4
source share
1 answer

The arguments to the function are based on ( %ebp) + (positive value) in your case you have 1 argument.

and (%ebp) - (positive value) are local variables, and you have 2 in your case.

see the following image :

enter image description here

You can read about the calling convention .

+6
source

All Articles