Reputation: 1625
So if I have a procedure where the first formal parameter is an int[]
and I'm enumerating through that loop, I'm confused about why one piece of code works where another doesn't. I should be able to do this:
#where ebp+8 is the location of the pointer, and ecx is the counter
mov edx, [ebp+ecx*4+8]
This gives me a gibberish value for edx, but this code works fine
mov edx, [ebp+8]
mov edx, [edx+ecx*4]
I don't understand the difference between those statements.
Upvotes: 4
Views: 360
Reputation: 471229
They are different:
In the first code:
mov edx, [ebp+ecx*4+8]
You are loading from the address: ebp+ecx*4+8
In the second code:
mov edx, [ebp+8]
mov edx, [edx+ecx*4]
You first load the value stored at ebp+8
. Then you use it as the base address for the second load.
In other words, the base address is stored at the memory location pointed to by ebp + 8
. It is not actually stored in the ebp
register itself.
Upvotes: 4