I don't understand this. I was fiddling with accessing local variables without using their "names", purely in the interests of education. I got this far:
I made it naked so the output assembly code is a little more legible (to me at least). Anyways, in the MSDN docs, it says that "The locals area begins at ebp-2. To access local variables, calculate an offset from ebp by subtracting the appropriate value from ebp."
__declspec(naked) long aFunc()
mov ebp, esp
sub esp, 4
mov [ebp - 2], 1
mov eax, [ebp - 2]
mov esp, ebp
So here's me subtracting 2 from ebp with no avail.
"Ok" I thought. A long is 4 bytes, right? So I try to subtract 4, also with no desired results.
So I give up, replace it with 'var' and view the compiler's assembly output with the symbol names switched off.
8 is the number I'm looking for and I can't figure out why.
Why 8? What else is on the stack? The return address is out of the way right? I thought that's why it starts at ebp-2?