0% found this document useful (0 votes)
9 views15 pages

Lect 3 FNL

The document explains the use of IF-ELSE conditions and loops in Assembly Language, specifically using the 8086 emulator. It details how to implement IF-ELSE structures using CMP and conditional jumps, as well as methods for creating loops. The importance of practice and visualization in mastering these concepts is emphasized.

Uploaded by

akkhanyar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views15 pages

Lect 3 FNL

The document explains the use of IF-ELSE conditions and loops in Assembly Language, specifically using the 8086 emulator. It details how to implement IF-ELSE structures using CMP and conditional jumps, as well as methods for creating loops. The importance of practice and visualization in mastering these concepts is emphasized.

Uploaded by

akkhanyar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 15

Title

• IF-ELSE Conditions and LOOPS in Assembly


Language
Introduction
• Assembly Language: Low-level programming.
• Today’s Focus:
• - IF-ELSE Structures
• - Conditions (Comparisons)
• - LOOPS
• Emulator: 8086 (EMU8086)
Conditions in Assembly
• Assembly does NOT have direct IF-ELSE.
• We use:
• - CMP Instruction (Compare)
• - Conditional Jumps (JE, JNE, JG, JL, JGE, JLE)
• Example:
• CMP AX, BX
• JE EqualLabel
CMP Instruction
• CMP destination, source
• Operation: destination - source
• Sets Flags (Zero Flag, Sign Flag, etc.)
• Next instruction checks those flags.
Conditional Jump Instructions
• JE: Jump if Equal
• JNE: Jump if Not Equal
• JG: Jump if Greater
• JL: Jump if Less
• JGE: Jump if Greater or Equal
• JLE: Jump if Less or Equal
How IF-ELSE works
• Step-by-Step:
• 1. Compare two values with CMP
• 2. Use conditional jump to 'IF' part
• 3. Use JMP to skip 'ELSE'
• Example:
• CMP AX, BX
• JE IF_Block
• ; ELSE Block
• JMP End_If
• IF_Block:
• ; IF Code
• End_If:
Simple IF Example
• MOV AX, 5
• MOV BX, 5
• CMP AX, BX
• JNE Lahore ; IF Block

• MOV CX, 1
• JMP EndIf
• Lahore:
• MOV CX, 0
• EndIf:
Simple IF-ELSE Example
• MOV AL, 10
• MOV BL, 5
• CMP AL, BL
• JG Greater
• MOV CL, 0
• JMP EndIf
• Greater:
• MOV CL, 1
• EndIf:
Introduction to Loops
• Repeat a block of code multiple times.
• Methods:
• - Using LOOP instruction
• - Using Counter and Conditional Jumps
LOOP Instruction
• Syntax:
• MOV CX, count
• Label:
• ; Code
• LOOP Label
• Each LOOP:
• - Decrements CX
• - Jumps to Label if CX != 0
Simple LOOP Example
• MOV CX, 5
• PrintStar:
• ; Print '*'
• LOOP PrintStar
Loop Using Jumps Example
• MOV CX, 3
• Label:
• ; Do Something
• DEC CX
• JNZ Label
Summary
• Assembly uses CMP and Jumps instead of
direct IF-ELSE.
• Loops use LOOP or manual decrement + jump.
• Practice is key to mastering flow control.
Tips for 8086 Emulator
• - Step-by-step run (Trace)
• - Watch Registers and Flags
• - Set Breakpoints to debug
Thank You!
• Practice small examples.
• Visualize with Flowcharts.
• Questions?

You might also like