Click to See Complete Forum and Search --> : local variables vc++ 9.0 asm listing


ryt
May 9th, 2008, 09:27 AM
hello,
I made this c++ program and created asm listing:

int main(){
int var = 3;
return 0;
}

asm listing:
...
_TEXT SEGMENT
_var$ = -8 ; size = 4
_main PROC
...
mov DWORD PTR _var$[ebp], 3
...

I dont understand fully this local variable in asm. There is "mov DWORD PTR", asm puts 3 in location size DWORD. "[ebp]" tells to store it at stack frame. "_var$" is an equate and tells to store it -8 from stack frame through indexing ( [_var$+ebp] ).
What I dont understand why at -8, why not at -4 since it is a first local variable. What is the meaning of $. And why asm stores equates in _TEXT ?

staticVoid
May 17th, 2008, 10:20 AM
variables shouldn't be initialized in text segment - they should be in .data.

first all parameters are passed to the stack and then the return address of the function, then the previous ebp is pushed to the stack and
mov ebp, esp
instruction follows. the address to the first local should be ebp - 4, this is the C calling convention anyway( __cdecl ).