X86 memory addressing with function parameters

So, if I have a procedure in which the first formal parameter is int[] , and I list this loop, I am confused by why one part of the code works where the other is not. I must do it:

 #where ebp+8 is the location of the pointer, and ecx is the counter mov edx, [ebp+ecx*4+8] 

This gives me gibberish value for edx, but this code works fine

 mov edx, [ebp+8] mov edx, [edx+ecx*4] 

I do not understand the difference between these statements.

+4
source share
1 answer

They are different:

In the first code:

 mov edx, [ebp+ecx*4+8] 

You are booting from the address: ebp+ecx*4+8

In the second code:

 mov edx, [ebp+8] mov edx, [edx+ecx*4] 

First you load the value stored in ebp+8 . Then you use it as the base address for the second download file.

In other words, the base address is stored in the memory location pointed to by ebp + 8 . It is not actually stored in the ebp register itself.

+4
source

All Articles