게임프로그래밍/게임 프로그래머 입문 올인원

[게임 프로그래머 입문 올인원] 분기문, 반복문

shine94 2024. 12. 18. 19:07

* if, if-else, if-else if-else, switch

#include <iostream>
using namespace std;

int choice = 3;

int main(void)
{
00731000  push        ebp  
00731001  mov         ebp,esp  
00731003  push        ecx  
	// if문 이용
	if (choice == 0)
00731004  cmp         dword ptr [choice (0734060h)],0  
0073100B  jne         main+30h (0731030h)  
		cout << "가위" << endl;
0073100D  push        offset std::endl<char,std::char_traits<char> > (07315E0h)  
00731012  push        733130h  
00731017  mov         eax,dword ptr [__imp_std::cout (073305Ch)]  
0073101C  push        eax  
0073101D  call        std::operator<<<std::char_traits<char> > (0731160h)  
00731022  add         esp,8  
00731025  mov         ecx,eax  
00731027  call        dword ptr [__imp_std::basic_ostream<char,std::char_traits<char> >::operator<< (0733038h)]  
0073102D  nop  
0073102E  jmp         main+0ABh (07310ABh)  
	else if (choice == 1)
00731030  cmp         dword ptr [choice (0734060h)],1  
00731037  jne         main+5Dh (073105Dh)  
		cout << "바위" << endl;
00731039  push        offset std::endl<char,std::char_traits<char> > (07315E0h)  
0073103E  push        733138h  
00731043  mov         ecx,dword ptr [__imp_std::cout (073305Ch)]  
00731049  push        ecx  
0073104A  call        std::operator<<<std::char_traits<char> > (0731160h)  
0073104F  add         esp,8  
00731052  mov         ecx,eax  
00731054  call        dword ptr [__imp_std::basic_ostream<char,std::char_traits<char> >::operator<< (0733038h)]  
0073105A  nop  
0073105B  jmp         main+0ABh (07310ABh)  
	else if (choice == 2)
0073105D  cmp         dword ptr [choice (0734060h)],2  
00731064  jne         main+8Ah (073108Ah)  
		cout << "보" << endl;
00731066  push        offset std::endl<char,std::char_traits<char> > (07315E0h)  
0073106B  push        733140h  
00731070  mov         edx,dword ptr [__imp_std::cout (073305Ch)]  
00731076  push        edx  
00731077  call        std::operator<<<std::char_traits<char> > (0731160h)  
0073107C  add         esp,8  
0073107F  mov         ecx,eax  
00731081  call        dword ptr [__imp_std::basic_ostream<char,std::char_traits<char> >::operator<< (0733038h)]  
00731087  nop  
00731088  jmp         main+0ABh (07310ABh)  
	else
		cout << "잘못 입력" << endl;
0073108A  push        offset std::endl<char,std::char_traits<char> > (07315E0h)  
0073108F  push        733144h  
00731094  mov         eax,dword ptr [__imp_std::cout (073305Ch)]  
00731099  push        eax  
0073109A  call        std::operator<<<std::char_traits<char> > (0731160h)  
0073109F  add         esp,8  
007310A2  mov         ecx,eax  
007310A4  call        dword ptr [__imp_std::basic_ostream<char,std::char_traits<char> >::operator<< (0733038h)]  
007310AA  nop  

	// switch 문 이용
	switch (choice)
007310AB  mov         ecx,dword ptr [choice (0734060h)]  
007310B1  mov         dword ptr [ebp-4],ecx  
007310B4  cmp         dword ptr [ebp-4],0  
007310B8  je          main+0C8h (07310C8h)  
007310BA  cmp         dword ptr [ebp-4],1  
007310BE  je          main+0ECh (07310ECh)  
007310C0  cmp         dword ptr [ebp-4],2  
007310C4  je          main+10Fh (073110Fh)  
007310C6  jmp         main+133h (0731133h)  
	{
	case 0:
		cout << "가위" << endl;
007310C8  push        offset std::endl<char,std::char_traits<char> > (07315E0h)  
007310CD  push        733150h  
007310D2  mov         edx,dword ptr [__imp_std::cout (073305Ch)]  
007310D8  push        edx  
007310D9  call        std::operator<<<std::char_traits<char> > (0731160h)  
007310DE  add         esp,8  
007310E1  mov         ecx,eax  
007310E3  call        dword ptr [__imp_std::basic_ostream<char,std::char_traits<char> >::operator<< (0733038h)]  
007310E9  nop  
		break;
007310EA  jmp         main+155h (0731155h)  
	case 1:
		cout << "바위" << endl;
007310EC  push        offset std::endl<char,std::char_traits<char> > (07315E0h)  
007310F1  push        733158h  
007310F6  mov         eax,dword ptr [__imp_std::cout (073305Ch)]  
007310FB  push        eax  
007310FC  call        std::operator<<<std::char_traits<char> > (0731160h)  
00731101  add         esp,8  
00731104  mov         ecx,eax  
00731106  call        dword ptr [__imp_std::basic_ostream<char,std::char_traits<char> >::operator<< (0733038h)]  
0073110C  nop  
		break;
0073110D  jmp         main+155h (0731155h)  
	case 2:
		cout << "보" << endl;
0073110F  push        offset std::endl<char,std::char_traits<char> > (07315E0h)  
00731114  push        733160h  
00731119  mov         ecx,dword ptr [__imp_std::cout (073305Ch)]  
0073111F  push        ecx  
00731120  call        std::operator<<<std::char_traits<char> > (0731160h)  
00731125  add         esp,8  
00731128  mov         ecx,eax  
0073112A  call        dword ptr [__imp_std::basic_ostream<char,std::char_traits<char> >::operator<< (0733038h)]  
00731130  nop  
		break;
00731131  jmp         main+155h (0731155h)  
	default:
		cout << "잘못 입력" << endl;
00731133  push        offset std::endl<char,std::char_traits<char> > (07315E0h)  
00731138  push        733164h  
0073113D  mov         edx,dword ptr [__imp_std::cout (073305Ch)]  
00731143  push        edx  
00731144  call        std::operator<<<std::char_traits<char> > (0731160h)  
00731149  add         esp,8  
0073114C  mov         ecx,eax  
0073114E  call        dword ptr [__imp_std::basic_ostream<char,std::char_traits<char> >::operator<< (0733038h)]  
00731154  nop  
		break;
	}

	return 0;
00731155  xor         eax,eax  
}
00731157  mov         esp,ebp  
00731159  pop         ebp  
0073115A  ret

 

* while, for, do-while

#include <iostream>
using namespace std;

int cnt;

int main(void)
{
00B91000  push        ebp  
00B91001  mov         ebp,esp  
	cnt = 0;
00B91003  mov         dword ptr [cnt (0B933C8h)],0  
	
	while (cnt < 3)
00B9100D  cmp         dword ptr [cnt (0B933C8h)],3  
00B91014  jge         main+25h (0B91025h)  
	{
		cnt++;
00B91016  mov         eax,dword ptr [cnt (0B933C8h)]  
00B9101B  add         eax,1  
00B9101E  mov         dword ptr [cnt (0B933C8h)],eax  
	}
00B91023  jmp         main+0Dh (0B9100Dh)  

	for (cnt = 0; cnt < 5; cnt++)
00B91025  mov         dword ptr [cnt (0B933C8h)],0  
00B9102F  jmp         main+40h (0B91040h)  
00B91031  mov         ecx,dword ptr [cnt (0B933C8h)]  
00B91037  add         ecx,1  
00B9103A  mov         dword ptr [cnt (0B933C8h)],ecx  
00B91040  cmp         dword ptr [cnt (0B933C8h)],5  
00B91047  jge         main+4Bh (0B9104Bh)  
	{
	}
00B91049  jmp         main+31h (0B91031h)  

	return 0;
00B9104B  xor         eax,eax  
}
00B9104D  pop         ebp  
00B9104E  ret

 

 

 

 

* 해당 글은 게임 프로그래머 입문 올인원 강의를 보고 정리한 글입니다.

   강의_바로가기

 

[게임 프로그래머 입문 올인원] C++ & 자료구조/알고리즘 & STL & 게임 수학 & Windows API & 게임 서버

Rookiss | 어디부터 시작할지 막막한 게임 프로그래밍 입문자를 위한 All-In-One 커리큘럼입니다. C++, 자료구조/알고리즘, STL, 게임 수학, Windows API, 게임 서버 입문으로 이어지는 알찬 커리큘럼으로

www.inflearn.com