pgubook-readers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Pgubook-readers] Quick question regarding addressing


From: Jonathan Bartlett
Subject: Re: [Pgubook-readers] Quick question regarding addressing
Date: Fri, 17 Jun 2005 12:09:22 -0700 (PDT)

> Does saying 4(%ebp) mean the same as %ebp?

No.  4(%ebp) means to take the value of %ebp, add 4 to it, and then use
that as a memory address to load the real value from.

> For example, would the following two lines mean the same thing?
>
> movl 4(%ebp), %eax
>
> ...or....
>
> movl %ebp, %eax

Let's say that %ebp has the value of 5 in it.  The first one will add 4 to
%ebp, giving 9, and then look in the computer at memory address number 9
and load whatever is in there into %eax (note that this would actually
kill your application because that is out-of-bounds, but this is just an
example ;] ).

The second one would simply load the number 5 into %eax, without ever
looking into memory at all.

> If %esp = %ebp, then could you also use:
>
> movl 4(%ebp), %eax
>
> ...or...
>
> popl %eax
>
> ..or...
>
> movl %ebp, %eax

No.  Besides the issue I mentioned before, popl has additional
significance: It modified %esp.

So pushl %eax is equivalent to:
subl $4, %esp
movl %eax, (%esp)

and popl %eax is equivalent to:
movl (%esp), %eax
addl $4, %esp

Hope that helps.

Jon




reply via email to

[Prev in Thread] Current Thread [Next in Thread]