IT공부/IT서적

[윤성우 열혈 C프로그래밍] 디버깅 빌드, 어셈블리 코드 - Chapter 4

shine94 2025. 1. 12. 20:58

 

#include <stdio.h>

int main(void)
{
006E1870  push        ebp  
006E1871  mov         ebp,esp  
006E1873  sub         esp,0F0h  
006E1879  push        ebx  
006E187A  push        esi  
006E187B  push        edi  
006E187C  lea         edi,[ebp-30h]  
006E187F  mov         ecx,0Ch  
006E1884  mov         eax,0CCCCCCCCh  
006E1889  rep stos    dword ptr es:[edi]  
006E188B  mov         ecx,offset _0118A949_Notation@c (06EC008h)  
006E1890  call        @__CheckForDebuggerJustMyCode@4 (06E132Ah)  
006E1895  nop  
	// 0x로 시작하면 16진수
	// 0으로 시작하면 8진수
	int num1 = 0xA7, num2 = 0x43;
006E1896  mov         dword ptr [num1],0A7h  
006E189D  mov         dword ptr [num2],43h  
	int num3 = 032, num4 = 024;
006E18A4  mov         dword ptr [num3],1Ah  
006E18AB  mov         dword ptr [num4],14h  

	printf("0xA7의 10진수 정수 값: %d\n", num1);
006E18B2  mov         eax,dword ptr [num1]  
006E18B5  push        eax  
006E18B6  push        offset string "0xA7\xc0\xc7 10\xc1\xf8\xbc\xf6 \xc1\xa4\xbc\xf6 \xb0\xaa: %d\n" (06E7B30h)  
006E18BB  call        _printf (06E10D2h)  
006E18C0  add         esp,8  
	printf("0x43의 10진수 정수 값: %d\n", num2);
006E18C3  mov         eax,dword ptr [num2]  
006E18C6  push        eax  
006E18C7  push        offset string "0x43\xc0\xc7 10\xc1\xf8\xbc\xf6 \xc1\xa4\xbc\xf6 \xb0\xaa: %d\n" (06E7B50h)  
006E18CC  call        _printf (06E10D2h)  
006E18D1  add         esp,8  
	printf("032의 10진수 정수 값: %d\n", num3);
006E18D4  mov         eax,dword ptr [num3]  
006E18D7  push        eax  
006E18D8  push        offset string "032\xc0\xc7 10\xc1\xf8\xbc\xf6 \xc1\xa4\xbc\xf6 \xb0\xaa: %d\n" (06E7B70h)  
006E18DD  call        _printf (06E10D2h)  
006E18E2  add         esp,8  
	printf("024의 10진수 정수 값: %d\n", num4);
006E18E5  mov         eax,dword ptr [num4]  
006E18E8  push        eax  
006E18E9  push        offset string "024\xc0\xc7 10\xc1\xf8\xbc\xf6 \xc1\xa4\xbc\xf6 \xb0\xaa: %d\n" (06E7B90h)  
006E18EE  call        _printf (06E10D2h)  
006E18F3  add         esp,8  

	printf("%d-%d=%d\n", num1, num2, num1 - num2);
006E18F6  mov         eax,dword ptr [num1]  
006E18F9  sub         eax,dword ptr [num2]  
006E18FC  push        eax  
006E18FD  mov         ecx,dword ptr [num2]  
006E1900  push        ecx  
006E1901  mov         edx,dword ptr [num1]  
006E1904  push        edx  
006E1905  push        offset string "%d-%d=%d\n" (06E7BB0h)  
006E190A  call        _printf (06E10D2h)  
006E190F  add         esp,10h  
	printf("%d+%d=%d\n", num1, num2, num1 + num2);
006E1912  mov         eax,dword ptr [num1]  
006E1915  add         eax,dword ptr [num2]  
006E1918  push        eax  
006E1919  mov         ecx,dword ptr [num2]  
006E191C  push        ecx  
006E191D  mov         edx,dword ptr [num1]  
006E1920  push        edx  
006E1921  push        offset string "%d+%d=%d\n" (06E7BBCh)  
006E1926  call        _printf (06E10D2h)  
006E192B  add         esp,10h  

	return 0;
006E192E  xor         eax,eax  
}
006E1930  pop         edi  
006E1931  pop         esi  
006E1932  pop         ebx  
006E1933  add         esp,0F0h  
006E1939  cmp         ebp,esp  
006E193B  call        __RTC_CheckEsp (06E124Eh)  
006E1940  mov         esp,ebp  
006E1942  pop         ebp  
006E1943  ret

 

#include <stdio.h>

int main(void)
{
009A1870  push        ebp  
009A1871  mov         ebp,esp  
009A1873  sub         esp,0D8h  
009A1879  push        ebx  
009A187A  push        esi  
009A187B  push        edi  
009A187C  lea         edi,[ebp-18h]  
009A187F  mov         ecx,6  
009A1884  mov         eax,0CCCCCCCCh  
009A1889  rep stos    dword ptr es:[edi]  
009A188B  mov         ecx,offset _3DA47307_FloatError@c (09AC008h)  
009A1890  call        @__CheckForDebuggerJustMyCode@4 (09A132Ah)  
009A1895  nop  
	int i;
	float num = 0.0;
009A1896  xorps       xmm0,xmm0  
009A1899  movss       dword ptr [num],xmm0  

	for (i = 0; i < 100; i++)
009A189E  mov         dword ptr [i],0  
009A18A5  jmp         __$EncStackInitStart+34h (09A18B0h)  
009A18A7  mov         eax,dword ptr [i]  
009A18AA  add         eax,1  
009A18AD  mov         dword ptr [i],eax  
009A18B0  cmp         dword ptr [i],64h  
009A18B4  jge         __$EncStackInitStart+52h (09A18CEh)  
		num += 0.01;
009A18B6  cvtss2sd    xmm0,dword ptr [num]  
009A18BB  addsd       xmm0,mmword ptr [__real@3f847ae147ae147b (09A7B50h)]  
009A18C3  cvtsd2ss    xmm0,xmm0  
009A18C7  movss       dword ptr [num],xmm0  
009A18CC  jmp         __$EncStackInitStart+2Bh (09A18A7h)  

	printf("0.1을 100번 더한 결과: %f\n", num);
009A18CE  cvtss2sd    xmm0,dword ptr [num]  
009A18D3  sub         esp,8  
009A18D6  movsd       mmword ptr [esp],xmm0  
009A18DB  push        offset string "0.1\xc0\xbb 100\xb9\xf8 \xb4\xf5\xc7\xd1 \xb0\xe1\xb0\xfa: %f\n" (09A7B30h)  
009A18E0  call        _printf (09A10D2h)  
009A18E5  add         esp,0Ch  

	return 0;
009A18E8  xor         eax,eax  
}
009A18EA  pop         edi  
009A18EB  pop         esi  
009A18EC  pop         ebx  
009A18ED  add         esp,0D8h  
009A18F3  cmp         ebp,esp  
009A18F5  call        __RTC_CheckEsp (09A124Eh)  
009A18FA  mov         esp,ebp  
009A18FC  pop         ebp  
009A18FD  ret

 

00D21870  push        ebp  
00D21871  mov         ebp,esp  
00D21873  sub         esp,0E4h  
00D21879  push        ebx  
00D2187A  push        esi  
00D2187B  push        edi  
00D2187C  lea         edi,[ebp-24h]  
00D2187F  mov         ecx,9  
00D21884  mov         eax,0CCCCCCCCh  
00D21889  rep stos    dword ptr es:[edi]  
00D2188B  mov         ecx,offset _987BC43D_BitAndOperation@c (0D2C008h)  
00D21890  call        @__CheckForDebuggerJustMyCode@4 (0D2132Ah)  
00D21895  nop  
	int num1 = 15;				// 0000 0000  0000 0000  0000 0000  0000 1111
00D21896  mov         dword ptr [num1],0Fh  
	int num2 = 20;				// 0000 0000  0000 0000  0000 0000  0001 0100
00D2189D  mov         dword ptr [num2],14h  
	int num3 = num1 & num2;		// 0000 0000  0000 0000  0000 0000  0000 0100 ->  num1과 num2의 비트 단위 & 연산
00D218A4  mov         eax,dword ptr [num1]  
00D218A7  and         eax,dword ptr [num2]  
00D218AA  mov         dword ptr [num3],eax  
	printf("AND 연산의 결과 : %d\n", num3);
00D218AD  mov         eax,dword ptr [num3]  
00D218B0  push        eax  
00D218B1  push        offset string "AND \xbf\xac\xbb\xea\xc0\xc7 \xb0\xe1\xb0\xfa : %d\n" (0D27B30h)  
00D218B6  call        _printf (0D210D2h)  
00D218BB  add         esp,8  
	return 0;
00D218BE  xor         eax,eax  
}
00D218C0  pop         edi  
00D218C1  pop         esi  
00D218C2  pop         ebx  
00D218C3  add         esp,0E4h  
00D218C9  cmp         ebp,esp  
00D218CB  call        __RTC_CheckEsp (0D2124Eh)  
00D218D0  mov         esp,ebp  
00D218D2  pop         ebp  
00D218D3  ret

 

#include <stdio.h>

int main(void)
{
00DF1870  push        ebp  
00DF1871  mov         ebp,esp  
00DF1873  sub         esp,0E4h  
00DF1879  push        ebx  
00DF187A  push        esi  
00DF187B  push        edi  
00DF187C  lea         edi,[ebp-24h]  
00DF187F  mov         ecx,9  
00DF1884  mov         eax,0CCCCCCCCh  
00DF1889  rep stos    dword ptr es:[edi]  
00DF188B  mov         ecx,offset _6E2C9688_BitXorOperation@c (0DFC008h)  
00DF1890  call        @__CheckForDebuggerJustMyCode@4 (0DF132Ah)  
00DF1895  nop  
	int num1 = 15;				// 0000 0000  0000 0000  0000 0000  0000 1111
00DF1896  mov         dword ptr [num1],0Fh  
	int num2 = 20;				// 0000 0000  0000 0000  0000 0000  0001 0100
00DF189D  mov         dword ptr [num2],14h  
	int num3 = num1 ^ num2;		// 0000 0000  0000 0000  0000 0000  0000 0100
00DF18A4  mov         eax,dword ptr [num1]  
00DF18A7  xor         eax,dword ptr [num2]  
00DF18AA  mov         dword ptr [num3],eax  
	printf("XOR 연산의 결과 : %d\n", num3);
00DF18AD  mov         eax,dword ptr [num3]  
00DF18B0  push        eax  
00DF18B1  push        offset string "XOR \xbf\xac\xbb\xea\xc0\xc7 \xb0\xe1\xb0\xfa : %d\n" (0DF7B30h)  
00DF18B6  call        _printf (0DF10D2h)  
00DF18BB  add         esp,8  
	return 0;
00DF18BE  xor         eax,eax  
}
00DF18C0  pop         edi  
00DF18C1  pop         esi  
00DF18C2  pop         ebx  
00DF18C3  add         esp,0E4h  
00DF18C9  cmp         ebp,esp  
00DF18CB  call        __RTC_CheckEsp (0DF124Eh)  
00DF18D0  mov         esp,ebp  
00DF18D2  pop         ebp  
00DF18D3  ret

 

#include <stdio.h>

int main(void)
{
00C61870  push        ebp  
00C61871  mov         ebp,esp  
00C61873  sub         esp,0D8h  
00C61879  push        ebx  
00C6187A  push        esi  
00C6187B  push        edi  
00C6187C  lea         edi,[ebp-18h]  
00C6187F  mov         ecx,6  
00C61884  mov         eax,0CCCCCCCCh  
00C61889  rep stos    dword ptr es:[edi]  
00C6188B  mov         ecx,offset _1F6144B2_BitNotOperation@c (0C6C008h)  
00C61890  call        @__CheckForDebuggerJustMyCode@4 (0C6132Ah)  
00C61895  nop  
	int num1 = 15;
00C61896  mov         dword ptr [num1],0Fh  
	int num2 = ~num1;
00C6189D  mov         eax,dword ptr [num1]  
00C618A0  not         eax  
00C618A2  mov         dword ptr [num2],eax  
	printf("NOT 연산의 결과: %d\n", num2);
00C618A5  mov         eax,dword ptr [num2]  
00C618A8  push        eax  
00C618A9  push        offset string "NOT \xbf\xac\xbb\xea\xc0\xc7 \xb0\xe1\xb0\xfa: %d\n" (0C67B30h)  
00C618AE  call        _printf (0C610D2h)  
00C618B3  add         esp,8  
	return 0;
00C618B6  xor         eax,eax  
}
00C618B8  pop         edi  
00C618B9  pop         esi  
00C618BA  pop         ebx  
00C618BB  add         esp,0D8h  
00C618C1  cmp         ebp,esp  
00C618C3  call        __RTC_CheckEsp (0C6124Eh)  
00C618C8  mov         esp,ebp  
00C618CA  pop         ebp  
00C618CB  ret

 

#include <stdio.h>

int main(void)
{
00E71870  push        ebp  
00E71871  mov         ebp,esp  
00E71873  sub         esp,0F0h  
00E71879  push        ebx  
00E7187A  push        esi  
00E7187B  push        edi  
00E7187C  lea         edi,[ebp-30h]  
00E7187F  mov         ecx,0Ch  
00E71884  mov         eax,0CCCCCCCCh  
00E71889  rep stos    dword ptr es:[edi]  
00E7188B  mov         ecx,offset _FCB93912_BitLeftShift@c (0E7C008h)  
00E71890  call        @__CheckForDebuggerJustMyCode@4 (0E7132Ah)  
00E71895  nop  
	int num = 15;
00E71896  mov         dword ptr [num],0Fh  

	int result1 = num << 1;
00E7189D  mov         eax,dword ptr [num]  
00E718A0  shl         eax,1  
00E718A2  mov         dword ptr [result1],eax  
	int result2 = num << 2;
00E718A5  mov         eax,dword ptr [num]  
00E718A8  shl         eax,2  
00E718AB  mov         dword ptr [result2],eax  
	int result3 = num << 3;
00E718AE  mov         eax,dword ptr [num]  
00E718B1  shl         eax,3  
00E718B4  mov         dword ptr [result3],eax  

	printf("1칸 이동 결과 : %d", result1);
00E718B7  mov         eax,dword ptr [result1]  
00E718BA  push        eax  
00E718BB  push        offset string "1\xc4\xad \xc0\xcc\xb5\xbf \xb0\xe1\xb0\xfa : %d" (0E77B30h)  
00E718C0  call        _printf (0E710D2h)  
00E718C5  add         esp,8  
	printf("1칸 이동 결과 : %d", result2);
00E718C8  mov         eax,dword ptr [result2]  
00E718CB  push        eax  
00E718CC  push        offset string "1\xc4\xad \xc0\xcc\xb5\xbf \xb0\xe1\xb0\xfa : %d" (0E77B30h)  
00E718D1  call        _printf (0E710D2h)  
00E718D6  add         esp,8  
	printf("1칸 이동 결과 : %d", result3);
00E718D9  mov         eax,dword ptr [result3]  
00E718DC  push        eax  
00E718DD  push        offset string "1\xc4\xad \xc0\xcc\xb5\xbf \xb0\xe1\xb0\xfa : %d" (0E77B30h)  
00E718E2  call        _printf (0E710D2h)  
00E718E7  add         esp,8  

	return 0;
00E718EA  xor         eax,eax  
}
00E718EC  pop         edi  
00E718ED  pop         esi  
00E718EE  pop         ebx  
00E718EF  add         esp,0F0h  
00E718F5  cmp         ebp,esp  
00E718F7  call        __RTC_CheckEsp (0E7124Eh)  
00E718FC  mov         esp,ebp  
00E718FE  pop         ebp  
00E718FF  ret