Lesson 4.1: Jumps, Loops, and Conditionals
Learning Objectives
- Identify unconditional and conditional jump instructions (
jmp,je,jne, etc.). - Analyze how loops and if-else statements are represented in assembly.
Prerequisites
- Familiarity with CPU flags.
- Understanding of instruction flow and basic control structures in high-level languages.
Key Concepts
- Unconditional Jump:
jmp label - Conditional Jumps:
je,jne,jg,jge,jl,jle, etc. - Flags: Condition codes set by
cmp,test, or arithmetic instructions
Detailed Explanation
Conditional Execution
cmp rax, rbx sets flags. Then je label jumps if zero flag (ZF) is set.
A for or while loop typically compiles into a combination of cmp/test and jmp instructions.
start_loop:
cmp rax, 10
jge end_loop ; if rax >= 10, jump out
add rax, 1
jmp start_loop
end_loop:
; ...
Additional detailed content would continue here with comprehensive examples, exercises, and explanations...
Recommended Resources
- Intel Developer Manual, Vol. 2: Instruction Set Reference
- Reverse Engineering Loops in x86-64 (Tutorial)