Hello, aspiring security professionals! ๐ฑ
When studying malware analysis or reverse engineering, you inevitably encounter a huge barrier: Assembly Language.
Seeing a black screen filled with unknown English acronyms like MOV, LEA, CMP, JE… naturally makes you wonder, “Who am I? Where am I?” ๐ตโ๐ซ
But don’t be intimidated! Assembly language is not alien. It’s simply C language (a high-level language) in different attire. Compilers translate C language into machine code according to predefined rules (Patterns), so if you know these ‘conversion rules (Mapping)’, you can read assembly language fluently.
Today, we will thoroughly explore the core of reverse engineering: the 1:1 mapping structure between C language and assembly language. Understanding this principle will allow you to see the flow of code even without a decompiler! ๐

1. Variable Assignment ๐ฅ
Assigning a value to a variable in C language is expressed as data movement (Move) in assembly.
๐ C Language
int a = 10;
int b = a;
โ๏ธ Assembly
MOV [RBP-4], 0xA ; 1. ๋ฉ๋ชจ๋ฆฌ(๋ณ์ a์ ์์น)์ 10(0xA)์ ๋ฃ๋๋ค.
MOV EAX, [RBP-4] ; 2. ๋ณ์ a์ ๊ฐ์ ๋ ์ง์คํฐ(EAX)๋ก ๊ฐ์ ธ์จ๋ค.
MOV [RBP-8], EAX ; 3. ๋ ์ง์คํฐ ๊ฐ์ ๋ฉ๋ชจ๋ฆฌ(๋ณ์ b์ ์์น)์ ๋ฃ๋๋ค.
- Explanation:
- The CPU cannot directly move data from memory to memory. Therefore, it moves data via a register (temporary storage) like EAX.
- Forms like [RBP-4] refer to a stack memory address (local variable).
- Key point: You can think of MOV A, B as A = B.
2. Arithmetic Operations ๐งฎ
Operations like addition and subtraction are very intuitive.
๐ C Language
a = a + 5;
a++;
โ๏ธ Assembly
ADD [RBP-4], 5 ; a = a + 5 (ADD: ๋ํ๊ธฐ)
INC [RBP-4] ; a++ (INC: 1 ์ฆ๊ฐ)
- Explanation:
- ADD: Addition
- SUB: Subtraction
- INC: Increment by 1
- DEC: Decrement by 1
- IMUL / IDIV: Multiplication / Division
3. Conditional Statements (If-Else) โ๏ธ
These are branching statements that change the flow of a program. In assembly, they consist of two steps: comparison (CMP) and jump (JUMP).
๐ C Language
if (a == 10) {
// True Block
b = 1;
} else {
// False Block
b = 0;
}
โ๏ธ Assembly
CMP [RBP-4], 0xA ; 1. a์ 10์ ๋น๊ตํ๋ค. (์ค์ ๋ก๋ a - 10์ ํด๋ด)
JNE 0x401050 ; 2. ๊ฒฐ๊ณผ๊ฐ ๊ฐ์ง ์๋ค๋ฉด(Not Equal), Else ๋ธ๋ก(0x401050)์ผ๋ก ์ ํ!
; --- True Block ---
MOV [RBP-8], 1 ; b = 1
JMP 0x401060 ; Else ๋ธ๋ก์ ๊ฑด๋๋ฐ๊ณ ํ์ถ!
; --- False Block (0x401050) ---
MOV [RBP-8], 0 ; b = 0
- Explanation:
- CMP A, B: Compares A and B. (Internally performs A – B and considers them equal if the result is 0)
- JE (Jump Equal): Jumps if equal
- JNE (Jump Not Equal): Jumps if not equal
- JG / JL: Jumps if greater / Jumps if less
- Remember that the { } block structure of high-level languages changes into a GOTO (jump) form in assembly!
4. Loops (For / While) ๐
Loops are a combination of conditional statements and jumps. They have a cyclic structure where the code goes down and then jumps back up.
๐ C Language
for (int i = 0; i < 10; i++) {
sum += i;
}
โ๏ธ Assembly
MOV [RBP-4], 0 ; i = 0 (์ด๊ธฐํ)
JMP Check_Condition ; ์กฐ๊ฑด ํ์ธํ๋ฌ ๊ฐ๊ธฐ
Loop_Start: ; ๋ฃจํ ์์ ์ง์
MOV EAX, [RBP-4] ; i ๊ฐ์ ๊ฐ์ ธ์ด
ADD [RBP-8], EAX ; sum += i
INC [RBP-4] ; i++ (์ฆ๊ฐ)
Check_Condition: ; ์กฐ๊ฑด ํ์ธ ์ง์
CMP [RBP-4], 0xA ; i์ 10 ๋น๊ต
JL Loop_Start ; i < 10 (์์ผ๋ฉด) Loop_Start๋ก ๋ค์ ์ ํ!
- Explanation:
- A C language for loop is broken down into the sequence: initialization -> condition check -> body -> increment/decrement -> condition check.
- If you see JMP or Jcc instructions with an upward arrow in assembly code, you can think, “Ah, this is a loop!”
5. Function Call ๐
This is the most important Calling Convention in reversing. Before calling a function, you prepare parameters (arguments), and after the function finishes, you receive the return value.
๐ C Language
int result = Add(10, 20);
โ๏ธ Assembly (x64 Standard)
MOV EDX, 20 ; 2๋ฒ์งธ ์ธ์(20)๋ฅผ EDX(๋๋ RSI) ๋ ์ง์คํฐ์ ๋ฃ์
MOV ECX, 10 ; 1๋ฒ์งธ ์ธ์(10)๋ฅผ ECX(๋๋ RDI) ๋ ์ง์คํฐ์ ๋ฃ์
CALL 0x401200 ; Add ํจ์ ํธ์ถ (์คํ์ ๋ณต๊ท ์ฃผ์ ์ ์ฅํ๊ณ ์ด๋)
MOV [RBP-4], EAX ; ๊ฒฐ๊ณผ๊ฐ(EAX)์ result ๋ณ์์ ์ ์ฅ
- Explanation:
- Parameter Passing: In an x64 environment, arguments are primarily passed in registers (RDI, RSI, RDX, RCX…). (x86 uses stack PUSH)
- CALL: Jumps to the address where the function is located. At this time, the return address after the function finishes is secretly saved on the stack.
- Return Value (RAX/EAX): The result of a function’s execution is always stored in the EAX (or RAX) register. Therefore, checking EAX immediately after a CALL will reveal the return value.
๐ก Tip: Study with AI
It’s okay if the patterns you learned today aren’t familiar yet. We have AI!
If you encounter unfamiliar assembly code during practice, ask it this:
“Decompile this assembly code into C language and explain its structure (if, for, etc.)!”
AI will interpret the code based on the mapping rules we just learned. But remember, knowing the theory and seeing the results is vastly different from seeing them without understanding the theory! ๐
Conclusion ๐
C language and assembly language are like ‘two sides of the same coin’.
If you gain the ability to imagine the other side (C language) just by looking at one side (assembly), you’ve already grasped the ticket to becoming an intermediate analyst.
Next time, based on this theory, we will conduct a magical practical session where we ask AI to “reimplement this assembly code in Python.”
Have a great time reversing today! Fighting! ๐ช
Leave a Reply