전체 코드
#include <iostream>
using namespace std;
int a = 1;
int b = 2;
bool isSame;
bool isDifferent;
bool isGreater;
bool isSmaller;
bool test;
int hp = 0;
bool isInvincible = true;
int main()
{
#pragma region 비교 연산
isSame = (a == b);
isDifferent = (a != b);
isGreater = (a > b);
isSmaller = (a < b);
#pragma endregion
#pragma region 논리 연산
test = !isSame;
test = (hp <= 0 && isInvincible == false);
test = (hp > 0 || isInvincible == true);
#pragma endregion
cout << "isSame: " << isSame << endl;
cout << "isDifferent: " << isDifferent << endl;
cout << "isGreater: " << isGreater << endl;
cout << "isSmaller: " << isSmaller << endl;
cout << "test: " << test << endl;
return 0;
}
1️⃣ 비교 연산자 (Relational Operators)
✔️ 비교 연산자란?
- 두 값을 비교하여 조건이 맞는지 확인하는 연산자
- 결과는 true(1) 또는 false(0) 반환
| 연산자 | 의미 | 예시 | 설명 |
|---|
| == | 같다 | a == b | a와 b가 같으면 true |
| != | 다르다 | a != b | a와 b가 다르면 true |
| > | 크다 | a > b | a가 b보다 크면 true |
| < | 작다 | a < b | a가 b보다 작으면 true |
| >= | 크거나 같다 | a >= b | a가 b보다 크거나 같으면 true |
| <= | 작거나 같다 | a <= b | a가 b보다 작거나 같으면 true |
✔️ 비교 연산자 예제 코드
bool isSame = (a == b);
bool isDifferent = (a != b);
bool isGreater = (a > b);
bool isSmaller = (a < b);
✔️ 비교 연산자 디어셈블리 매핑 분석
(a == b)
mov eax, dword ptr [b] ; b의 값을 eax로 로드
cmp dword ptr [a], eax ; a와 b를 비교
jne not_equal ; 다르면 점프
mov isSame, 1 ; 같으면 true(1)
jmp end_cmp
not_equal:
mov isSame, 0 ; 다르면 false(0)
(a != b)
mov eax, dword ptr [b]
cmp dword ptr [a], eax
je equal ; 같으면 점프
mov isDifferent, 1 ; 다르면 true(1)
jmp end_cmp
equal:
mov isDifferent, 0 ; 같으면 false(0)
(a > b)
mov eax, dword ptr [b]
cmp dword ptr [a], eax
jle not_greater
mov isGreater, 1
jmp end_cmp
not_greater:
mov isGreater, 0
(a < b)
mov eax, dword ptr [b]
cmp dword ptr [a], eax
jge not_smaller
mov isSmaller, 1
jmp end_cmp
not_smaller:
mov isSmaller, 0
2️⃣ 논리 연산자 (Logical Operators)
✔️ 논리 연산자란?
- 여러 조건을 조합하거나 부정할 때 사용하는 연산자
- 비교 연산자 결과(0, 1)를 조합
| 연산자 | 의미 | 예시 | 설명 |
|---|
| ! | NOT | !a | a가 true면 false |
| && | AND | a && b | a와 b 모두 true일 때만 true |
| || | OR | a || b | a 또는 b가 true면 true |
✔️ 논리 연산자 예제 코드
bool test;
test = !isSame;
test = (hp <= 0 && isInvincible == false);
test = (hp > 0 || isInvincible == true);
✔️ 논리 연산자 디어셈블리 매핑 분석
! (NOT)
movzx eax, byte ptr [isSame]
test eax, eax
jne not_false
mov test, 1 ; isSame이 0이면 true
jmp end_not
not_false:
mov test, 0 ; isSame이 1이면 false
&& (AND)
test = (hp <= 0 && isInvincible == false);
cmp dword ptr [hp], 0
jg not_dead ; hp > 0이면 false
movzx eax, byte ptr [isInvincible]
test eax, eax
jne not_dead ; isInvincible이 true면 false
mov test, 1
jmp end_and
not_dead:
mov test, 0
|| (OR)
test = (hp > 0 || isInvincible == true);
cmp dword ptr [hp], 0
jg is_alive ; hp > 0이면 true
movzx eax, byte ptr [isInvincible]
test eax, eax
jne is_alive ; isInvincible이 true면 true
mov test, 0
jmp end_or
is_alive:
mov test, 1
📌 핵심 정리
| 구분 | 의미 | 디어셈블리 핵심 명령 |
|---|
| == | 같다 | cmp + je/jne |
| != | 다르다 | cmp + jne/je |
| > | 크다 | cmp + jle |
| < | 작다 | cmp + jge |
| ! | 부정 | test + jne/je |
| && | 논리곱 | 첫 조건 false면 바로 종료 |
| || | 논리합 | 첫 조건 true면 바로 종료 |
📌 디버깅/디스어셈블리 팁
| 작업 | 단축키 |
|---|
| 디버그 실행 | F5 |
| 디스어셈블리 보기 | Ctrl+Alt+D |
| 레지스터 확인 | 디버그 중 레지스터 창 |
| 메모리 확인 | Ctrl+Alt+M |
💡 추가 학습 포인트
✅ 비교 연산과 논리 연산은 조건문과 필수 연계
✅ 디어셈블리 분석하며 실제 흐름 꼭 체크
✅ 논리 연산의 단축 평가(short-circuit) 원리도 기억
✅ 논리식 복잡해지면 괄호로 명확히 구분
📥 필요하시면 PDF로 변환 가능
📚 다음 강의 정리도 이런 방식으로 계속 도와드릴까요?
🔥 추가 궁금한 점 있으면 바로 질문 주세요!
학습 효율 극대화 자료로 꾸준히 제공해드리겠습니다 💪😊