Actualmente estoy jugando con C, C++ y ASM. Veo que siempre hay una diferencia de 12 entre los valores de substracción de ebp. Mi código desensamblado:El valor de resta de dirección siempre es 12? ¿El tamaño de las variables es leve?
Código:
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
Pero por qué? Int toma 4 bytes y corta solo 2 bytes. Entonces, ¿por qué hay una diferencia de 12? Por favor ayuda.
EDIT: Parece ser el mismo en el código asm publicado. Lo he configurado en la configuración.
_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
Como se puede ver, también hay diferencia de 12.
Probablemente alineación. –
Pero si el punto de partida es ebp-20 y el tamaño es de 32 bits, estará en otra variable en la dirección ebp-8 .... ¿No es así? – user35443
¿Qué compilador, qué versión del compilador, qué conmuta? Además, publique una función completa y su conjunto asociado. –