Ich spiele gerade mit C, C++ und ASM. Ich kann sehen, dass es immer einen Unterschied von 12 zwischen den Ebb-Subtraktionswerten gibt. Mein zerlegten Code:Adresse Substraktionswert ist immer 12? Ist die Größe der Variablen gering?
Code:
int main()
{
int abc = 10;
int def = 20;
short int a = 1;
long int b = 1000;
//PlayFloat();
GetValue();
return 0;
}
Disassebled:
push ebp
mov ebp,esp
sub esp,0F0h
push ebx
push esi
push edi
lea edi,[ebp+FFFFFF10h]
mov ecx,3Ch
mov eax,0CCCCCCCCh
rep stos dword ptr es:[edi]
;int abc = 10;
mov dword ptr [ebp-8],0Ah
;int def = 20;
mov dword ptr [ebp-14h],14h
;short int a = 1;
mov eax,1
mov word ptr [ebp-20h],ax
;long int b = 1000;
mov dword ptr [ebp-2Ch],3E8h
;//PlayFloat();
;GetValue();
call 004110EB
;return 0;
xor eax,eax
Aber warum? Int dauert 4 Bytes und kurz nur 2 Bytes. Warum gibt es also einen Unterschied von 12? Bitte helfen Sie.
EDIT: Es scheint in freigegebenen Asm-Code identisch zu sein. Ich habe es in den Einstellungen festgelegt.
_TEXT SEGMENT
_b$ = -44 ; size = 4
_a$ = -32 ; size = 2
_def$ = -20 ; size = 4
_abc$ = -8 ; size = 4
_main PROC ; COMDAT
; 18 : {
push ebp
mov ebp, esp
sub esp, 240 ; 000000f0H
push ebx
push esi
push edi
lea edi, DWORD PTR [ebp-240]
mov ecx, 60 ; 0000003cH
mov eax, -858993460 ; ccccccccH
rep stosd
; 19 : int abc = 10;
mov DWORD PTR _abc$[ebp], 10 ; 0000000aH
; 20 : int def = 20;
mov DWORD PTR _def$[ebp], 20 ; 00000014H
; 21 : short int a = 1;
mov eax, 1
mov WORD PTR _a$[ebp], ax
; 22 : long int b = 1000;
mov DWORD PTR _b$[ebp], 1000 ; 000003e8H
; 23 :
; 24 : //PlayFloat();
; 25 :
; 26 : GetValue();
call _GetValue
; 27 : return 0;
xor eax, eax
; 28 : }
pop edi
pop esi
pop ebx
add esp, 240 ; 000000f0H
cmp ebp, esp
call __RTC_CheckEsp
mov esp, ebp
pop ebp
ret 0
_main ENDP
_TEXT ENDS
Wie Sie sehen können, gibt es auch Unterschied von 12.
Wahrscheinlich Ausrichtung. –
Aber wenn der Startpunkt ebp-20 ist und die Größe 32 Bit ist, wird es in einer anderen Variable auf der Adresse ebp-8 sein. Oder nicht? – user35443
Welcher Compiler, welche Version des Compilers, welche Switches? Stellen Sie außerdem eine vollständige Funktion und die zugehörige Assembly bereit. –