Understanding IF-ELSE in
Assembly Language
Conditional Statements in Low-Level
Programming
Introduction to Conditional Statements
Assembly language uses conditional jumps for decision-
making.
IF-ELSE logic is implemented using:
- CMP (Compare): Compares two values.
- JUMP instructions: Directs program flow based on
comparison.
Key Jump Instructions:
- JE (Jump if Equal), JNE (Jump if Not Equal)
- JG (Jump if Greater), JL (Jump if Less), etc.
Syntax of IF-ELSE in Assembly
General IF-ELSE structure:
CMP operand1, operand2 ; Compare values
JE label_if_equal ; Jump if equal
; ELSE part
MOV AX, 0 ; Code for ELSE
JMP end_if
label_if_equal:
MOV AX, 1 ; Code for IF condition
end_if:
Example Code
Task: Check if two numbers are equal.
MOV AX, 5 ; Load 5 into AX
MOV BX, 5 ; Load 5 into BX
CMP AX, BX ; Compare AX and BX
JE Equal ; Jump if equal
MOV CX, 0 ; ELSE: Set CX = 0
JMP End
Equal:
MOV CX, 1 ; IF: Set CX = 1
End:
Explanation:
- If AX = BX, CX becomes 1.
- Else, CX remains 0.
Key Points & Summary
CMP: Compares values, does not modify operands.
JUMP Instructions control flow after comparison.
IF-ELSE logic enables decision-making in Assembly.
Efficient and direct implementation using minimal
instructions.

if_else_assembly_language ( hhhhh1).pptx

  • 1.
    Understanding IF-ELSE in AssemblyLanguage Conditional Statements in Low-Level Programming
  • 2.
    Introduction to ConditionalStatements Assembly language uses conditional jumps for decision- making. IF-ELSE logic is implemented using: - CMP (Compare): Compares two values. - JUMP instructions: Directs program flow based on comparison. Key Jump Instructions: - JE (Jump if Equal), JNE (Jump if Not Equal) - JG (Jump if Greater), JL (Jump if Less), etc.
  • 3.
    Syntax of IF-ELSEin Assembly General IF-ELSE structure: CMP operand1, operand2 ; Compare values JE label_if_equal ; Jump if equal ; ELSE part MOV AX, 0 ; Code for ELSE JMP end_if label_if_equal: MOV AX, 1 ; Code for IF condition end_if:
  • 4.
    Example Code Task: Checkif two numbers are equal. MOV AX, 5 ; Load 5 into AX MOV BX, 5 ; Load 5 into BX CMP AX, BX ; Compare AX and BX JE Equal ; Jump if equal MOV CX, 0 ; ELSE: Set CX = 0 JMP End Equal: MOV CX, 1 ; IF: Set CX = 1 End: Explanation: - If AX = BX, CX becomes 1. - Else, CX remains 0.
  • 5.
    Key Points &Summary CMP: Compares values, does not modify operands. JUMP Instructions control flow after comparison. IF-ELSE logic enables decision-making in Assembly. Efficient and direct implementation using minimal instructions.