If x is located at EBP − 8 on the stack, one cannot just
use:
mov eax, ebp - 8
Why? The value that MOV stores into EAX must be computed by the as-
sembler (that is, it must in the end be a constant). However, there is an
instruction that does the desired calculation. It is called LEA (for Load Ef-
fective Address). The following would calculate the address of x and store
it into EAX:
lea eax, [ebp - 8]
Now EAX holds the address of x and could be pushed on the stack when
calling function foo. Do not be confused, it looks like this instruction is
reading the data at [EBP−8]; however, this is not true. The LEA instruction
never reads memory! It only computes the address that would be read
by another instruction and stores this address in its first register operand.