5

I am trying to learn more about the stack and base pointer. The following sample assembly code is from an objdump of a binary compiled by gcc on an 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 base pointer %ebp is used to reference the function parameters and local variables. Normally the positive offsets are parameters passed to the function and the negative offsets are local variables?

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

1 Answer 1

9

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

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

see the following image:

enter image description here

You may read about calling convention as well.

Sign up to request clarification or add additional context in comments.

1 Comment

So you're saying -0xc(%ebp),%eax is an argument to my function? I thought that the parentheses around %ebp meant that this will be (address contained in %ebp) - 0xc?

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.