Dear all,
Where are global , static , and automatic variables stored in memory?
Thanks in advance.
Where are global , static , and automatic variables stored in memory?
Thanks in advance.
void MyFunction(int a)
{
static int x = 0;
printf("my number: ");
printf("%d, %d\n", a, x);
}
when compiled and disassembled in windows environment
BSS SEGMENT
?x@?1??MyFunction@@9@9 DD 01H DUP (?) ; `MyFunction'::`2'::x
_BSS ENDS
_DATA SEGMENT
$SG796 DB 'my number: ', 00H
$SG797 DB '%d, %d', 0aH, 00H
_DATA ENDS
PUBLIC _MyFunction
EXTRN _printf:NEAR
; Function compile flags: /Odt
_TEXT SEGMENT
_a$ = 8 ; size = 4
_MyFunction PROC NEAR
; Line 4
push ebp
mov ebp, esp
; Line 6
push OFFSET FLAT:$SG796
call _printf
add esp, 4
; Line 7
mov eax, DWORD PTR ?x@?1??MyFunction@@9@9
push eax
mov ecx, DWORD PTR _a$[ebp]
push ecx
push OFFSET FLAT:$SG797
call _printf
add esp, 12 ; 0000000cH
; Line 8
pop ebp
ret 0
_MyFunction ENDP
_TEXT ENDS
void MyFunction(int a)
{
static int x = 0;
printf("my number: ");
printf("%d, %d\n", a, x);
}
when compiled and disassembled in windows environment
BSS SEGMENT
?x@?1??MyFunction@@9@9 DD 01H DUP (?) ; `MyFunction'::`2'::x
_BSS ENDS
_DATA SEGMENT
$SG796 DB 'my number: ', 00H
$SG797 DB '%d, %d', 0aH, 00H
_DATA ENDS
PUBLIC _MyFunction
EXTRN _printf:NEAR
; Function compile flags: /Odt
_TEXT SEGMENT
_a$ = 8 ; size = 4
_MyFunction PROC NEAR
; Line 4
push ebp
mov ebp, esp
; Line 6
push OFFSET FLAT:$SG796
call _printf
add esp, 4
; Line 7
mov eax, DWORD PTR ?x@?1??MyFunction@@9@9
push eax
mov ecx, DWORD PTR _a$[ebp]
push ecx
push OFFSET FLAT:$SG797
call _printf
add esp, 12 ; 0000000cH
; Line 8
pop ebp
ret 0
_MyFunction ENDP
_TEXT ENDS
Comment