I am a little bit confused about the difference between
leal -4(%ebp), %eax
and
movl -4(%ebp), %eax
Can someone explain this to me?
LEA (load effective address) just computes the address of the operand, it does not actually dereference it. Most of the time, it's just doing a calculation like a combined multiply-and-add for, say, array indexing.
In this case, it's doing a simple numeric subtraction: leal -4(%ebp), %eax
just assigns to the %eax
register the value of %ebp - 4
. It's equivalent to a single sub
instruction, except a sub
requires the destination to be the same as one of the sources.
The movl
instruction, in contrast, accesses the memory location at %ebp - 4
and stores that value into %eax
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With