I'm trying to understand how to locate local variables in memory. I have disassembled a c code and I have the address of the instructions. I want the memory location where that variable is stored. I tried to access the instruction address of i in c code but the variable is not located there. I think it is located at a "offset" from the base pointer. But I don't know about the concept of offset. Any help will be appreciated.
C code:
int main()
{
int i = 10;
int j = -1;
int k = 4;
int l = 9;
int m;
m = (i-j) + (k-l);
}
Disassembled code
int main()
{
003E13A0 push ebp
003E13A1 mov ebp,esp
003E13A3 sub esp,0FCh
003E13A9 push ebx
003E13AA push esi
003E13AB push edi
003E13AC lea edi,[ebp-0FCh]
003E13B2 mov ecx,3Fh
003E13B7 mov eax,0CCCCCCCCh
003E13BC rep stos dword ptr es:[edi]
int i = 10;
003E13BE mov dword ptr [i],0Ah
int j = -1;
003E13C5 mov dword ptr [j],0FFFFFFFFh
int k = 4;
003E13CC mov dword ptr [k],4
int l = 9;
003E13D3 mov dword ptr [l],9
int m;
m = (i-j) + (k-l);
003E13DA mov eax,dword ptr [i]
003E13DD sub eax,dword ptr [j]
003E13E0 mov ecx,dword ptr [k]
003E13E3 sub ecx,dword ptr [l]
003E13E6 add eax,ecx
003E13E8 mov dword ptr [m],eax
}
003E13EB xor eax,eax
003E13ED pop edi
003E13EE pop esi
003E13EF pop ebx
003E13F0 mov esp,ebp
003E13F2 pop ebp
003E13F3 ret
Registers
EAX = 001A9478 EBX = 7EFDE000 ECX = 001A8868 EDX = 00000001 ESI = 00000000 EDI = 00000000 EIP = 00BE13A0 ESP = 003BF990 EBP = 003BF9DC EFL = 00000214