Test environment: WINXP tc2.0 VC ++ 6.0
# Include <stdio. h>
Int Main ( Int Argc, Char * Argv [])
{
Int I = Zero X 1234 ;
Int J = Zero X 5678 ;
Printf ( " I = % x \ n " , I );
Printf ( " J = % x \ n " , J );
Printf ( " Main = % x " , Main );
Scanf (& I, & J );
Return 0 ;
}
Corresponding assemblyCode:
Var_ I = byte PTR- 4
Var_j = word PTR- 2
Argc = word PTR 4
Argv = DWORD PTR 6
Envp = dword ptr 0ah
PushBP
MoVBP, SP
SubSP,4
MoVWord PTR [bp + var_ I], 1234 H
MoV[Bp + var_j], 5678 H
PushWord PTR [bp + var_ I]
MoVAx, 194 H
From the assembly code above, we can see that the address of the variables first defined in C in the stack is relatively low, and the address in the variable stack defined later is high.
In vc6.0
Int A = Zero X 12345678 ;
Int B = Zero X 1234 ;
Assembly Code
6 : Int I = 0x1234 ;
00401028 MoV Dword ptr [EBP- 4 ], 1234 H
7 : Int J = 0x5678 ;
0040102f MoV Dword ptr [EBP- 8 ], 5678 H
MoV [EBP + var_24], 12345678 H ; A
MoV [EBP + var_28], 1234 H ; B
Conclusion: In C ++ and C in vc6.0, the requested variable address is high, and the requested address is low. This is similar to applying for a first entry to the stack, and then applying for a later entry to the stack.
This seems to be related to the compiler.