SlideShare a Scribd company logo
1 of 33
Flag Control
Objective:
• Identify the different flag control instruction
• Apply the different flag control instructions
Flag Control Instructions
The 8086/8088 provides a group of instructions
that directly affects the state of the flags.
• LAHF Instruction
• SAHF Instruction
• CLC Instruction
• STC Instruction
• CMC Instruction
• PUSHF Instruction
• POPF Instruction
The LAHF Instruction

The LAHF (Load AH from flags)
instruction copies the SF, ZF, AF, PF, and
CF into bits b7, b6, b4, b2, and b0
respectively of register AH.
Format:
Action:
AH
LAHF
SF x ZF x AF x PF x CF
The SAHF Instruction
The SAHF (Store AH into flags)
instruction transfers bits b7, b6, b4, b2,
and b0 from register AH into SF, ZF, AF,
PF, and CF, respectively.
SAHFFormat:
Action:
SF ZF x AF x PF x CF AH
Example:
MOV AH, 25H
SAHF
The CLC Instruction
 The CLC (Clear Carry Flag) instruction
clears the carry flag.
 Format: CLC
 Action: CF 0
The STC Instruction
The STC (Set Carry Flag) instruction sets
the carry flag to 1.
Format: STC
Action: CF 1
The CMC Instruction
 The CMC (Complement Carry Flag)
instruction complements the carry flag.
 Format: CMC
 Action: CF CF’
Status & Flags Register
• Carry flag (CF): CF=1 if there is
– a carry out from most significant bit (msb) on addition
– a borrow into msb on subtraction
– CF also affected differently by shift and rotate instructions
• Parity flag (PF): PF=1 if
– low byte of result has an even number of one bits (even
parity)
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
CFPFAFZFSFOF IFDF
Status & Flags Register - Cont.
• Auxiliary carry flag (AF): AF=1 if there is
– a carry out from bit 3 on addition
– a borrow into bit 3 on subtraction
• Zero flag (ZF): ZF=1
– if the result is zero
• Sign flag (SF): SF=1 if
– msb of result is 1 indicating that the result is negative
for signed number interpretation
• Overflow flag (OF): OF=1
– if signed overflow occurs
The PUSHF Instruction
 The PUSHF (Push Status Register onto Stack)
instruction pushes the flag register onto the stack.
PUSHF decrements SP by 2 and then moves the
flag register to the top of the stack.
 Format: PUSHF
 Action: SP SP - 2
SP [flag register]
The POPF Instruction
 The POPF (Pop Flags off the Stack)
instruction transfers the word pointed to by
SP to the status register, thereby altering
the value of the flags.
POPF

Format:
Action:
status register
SP
[SP]
SP + 2
Stack Instructions
• SP points at the the top of the stack
• .STACK 100H
– SP is initialized to 100H
• PUSH operand
– SP  SP - 2
– [SP+1:SP]  operand
• POP operand
– Operand  [SP+1:SP]
– SP  SP + 2
• PUSHF
– SP  SP - 2
– [SP+1:SP]  flags register
• POPF
– Flags register  [SP+1:SP]
– SP  SP + 2
The CLI Instruction
 The CLI (Clear Interrupt Flag) instruction
clears the interrupt flag, thereby disabling
interrupt request. The 8086/8088 will
therefore not recognize any external
interrupt request with the exception of the
non-maskable interrupt.
 Format: CLI
 Action: IF 0
The STI Instruction
 The STI (Set Interrupt Flag) instruction
sets the interrupt flag to 1, thereby enabling
the 8086/8088 to recognize any interrupt
request.
 Format: STI
 Action: IF 1
The CLD Instruction
 The CLD (Clear Direction Flag) instruction
clears the direction flag, thereby causing
the string instruction to auto-increment the
index registers (SI or DI).
 Format: CLD
 Action: DF 0
The STD Instruction
 The STD (Set Direction Flag) instruction
sets the direction flag to 1, thereby causing
the string instruction to auto-decrement the
index registers (SI or DI).
 Format: STD
 Action: DF 1
Flow Control Instruction
Flow Control Instructions
• Unconditional jump
– JMP label ; IP  label
• Conditional jump
– Signed jumps
– Unsigned jumps
– Common jumps
• Signed jumps
– JG/JNLE jump if greater than, or jump if not less than or equal
– JGE/JNL jump if greater than or equal, or jump if not less than
– JL/JNGE jump if less than, or jump if not greater than or equal
– JLE/JNG jump if less than or equal, or jump if not greater than
Flow Control Instructions
Flow Control Instructions
Flow Control Instructions
• Single-flag jumps
– JS jump if sign negative
– JNS jump if nonnegative sign
– JP/JPE jump if parity even
– JNP/JPO jump if parity odd
• Jump based on CX
– JCXZ if CX = 0, then jump to the address specified by
the operand
• Loop Instructions
– Loop short-label -loop decrement CX
– Loopnz/Loopne -loop while not zero/loop while not equal
– Loopz/Loope -loop while zero/loop while equal
• All jump instructions have no effect on the flags.
Flow Control Instructions
Branching Structures: IF-Then
• Example:
If AX < 0 Then
Replace AX by –AX
ENDIF
; if AX < 0
CMP AX, 0
JNL END_IF
;then
NEG AX
END_IF:
IF-Then-Else
• Example:
If AL <= BL Then
Display character in AL
Else
Display character in BL
ENDIF
MOV AH, 2
; if AL<=BL
CMP AL, BL
JNBE ELSE_
;then
MOV DL, AL
JMP DISPLAY
ELSE_:
MOV DL, BL
DISPLAY:
INT 21H
END_IF:
CASE
• Example:
CASE AX
<0: put –1 in BX
=0: put 0 in BX
>0: put 1 in BX
END_CASE
; case AX
CMP AX, 0
JL NEGATIVE
JE ZERO
JG POSITIVE
NEGATIVE: MOV BX, -1
JMP END_CASE
ZERO: MOV BX, 0
JMP END_CASE
POSITIVE: MOV BX, 1
END_CASE:
CASE – Cont.
• Example:
CASE AL
1,3: display ‘o’
2,4: display ‘e’
END_CASE
; case AL
CMP AL, 1 ; 1, 3:
JE ODD
CMP AL, 3
JE ODD
CMP AL, 2 ; 2, 4:
JE EVEN
CMP AL, 4
JE EVEN
JMP END_CASE
ODD: MOV DL, ‘o’
JMP DISPLAY
EVEN: MOV DL, ‘e’
DISPLAY: MOV AH, 2
INT 21H
END_CASE:
Branches with Compound
Conditions
• Example:
If (‘A’ <= character) and (character <= ‘Z’) Then
Display character
END_IF
; read a character
MOV AH, 1
INT 21H
; If (‘A’ <= character) and (character <= ‘Z’) Then
CMP AL, ‘A’
JNGE END_IF
CMP AL, ‘Z’
JNLE END_IF
; display character
MOV DL, AL
MOV AH, 2
INT 21H
END_IF:
Branches with Compound Conditions
• Example:
If (character=‘y’) OR (character <= ‘Y’) Then
Display character
Else terminate program
END_IF
; read a character
MOV AH, 1
INT 21H
; If (character=‘y’) OR (character = ‘Y’) Then
CMP AL, ‘y’
JE Then
CMP AL, ‘Y’
JE Then
JMP ELSE_
Then: MOV AH, 2
MOV DL, AL
INT 21H
JMP END_IF
ELSE:MOV AH, 4CH
INT 21H
END_IF:
Loop Instructions
• Loop Next
– Dec Cx
– If CX<>0 JMP Next
• Loopz/loope Next
– Dec Cx
– If (CX<>0) AND (ZF=1) JMP Next
• Loopnz/loopne Next
– Dec Cx
– If (CX<>0) AND (ZF=0) JMP Next
FOR LOOP
• Example:
For 80 times DO
Display ‘*’
END_IF
MOV CX, 80
MOV AH, 2
MOV DL, ‘*’
Next: INT 21H
Loop Next
While Loop
• Example:
Initialize count to 0
Read a character
While character <> Carriage Return DO
Count = Count + 1
Read a character
END_While
MOV DX, 0
MOV AH, 1
INT 21H
While_: CMP AL, 0DH
JE End_While
INC DX
INT 21H
JMP While_
End_While:
Repeat Loop
• Example:
Repeat
Read a character
Until character is blank
MOV AH, 1
Repeat:
INT 21H
; until
CMP AL, ‘ ‘
JNE Repeat
Application of Loope
• Example: Search for a number in a Table
Table DB 1,2,3,4,5,6,7,8,9
XOR SI, SI
MOV CX, 9
Next: INC SI
CMP Table[SI-1], 7
Loopne Next

More Related Content

What's hot

Addressing mode Computer Architecture
Addressing mode  Computer ArchitectureAddressing mode  Computer Architecture
Addressing mode Computer ArchitectureHaris456
 
3.programmable interrupt controller 8259
3.programmable interrupt controller 82593.programmable interrupt controller 8259
3.programmable interrupt controller 8259MdFazleRabbi18
 
8259 programmable interrupt controller
8259 programmable interrupt controller8259 programmable interrupt controller
8259 programmable interrupt controllerSrikrishna Thota
 
Instruction set of 8086
Instruction set of 8086Instruction set of 8086
Instruction set of 80869840596838
 
Programming 8051 Timers
Programming 8051 Timers Programming 8051 Timers
Programming 8051 Timers ViVek Patel
 
4.4 diversity combining techniques
4.4   diversity combining techniques4.4   diversity combining techniques
4.4 diversity combining techniquesJAIGANESH SEKAR
 
Double SideBand Suppressed Carrier (DSB-SC)
Double SideBand Suppressed Carrier (DSB-SC)Double SideBand Suppressed Carrier (DSB-SC)
Double SideBand Suppressed Carrier (DSB-SC)Ridwanul Hoque
 
IMPLEMENTING ARITHMETIC INSTRUCTIONS IN EMU 8086
IMPLEMENTING ARITHMETIC INSTRUCTIONS IN EMU 8086IMPLEMENTING ARITHMETIC INSTRUCTIONS IN EMU 8086
IMPLEMENTING ARITHMETIC INSTRUCTIONS IN EMU 8086COMSATS Abbottabad
 
The 8051 microcontroller
The 8051 microcontrollerThe 8051 microcontroller
The 8051 microcontrollerPallaviHailkar
 
Types of line coding
Types of line codingTypes of line coding
Types of line codingramalakshmi54
 
8086 instruction set with types
8086 instruction set with types8086 instruction set with types
8086 instruction set with typesRavinder Rautela
 
Addressing modes 8085
Addressing modes 8085Addressing modes 8085
Addressing modes 8085ShivamSood22
 
Addressing modes of 8085
Addressing modes of 8085Addressing modes of 8085
Addressing modes of 8085Gaurav Solanki
 
Module 4 registers and counters
Module 4 registers and counters Module 4 registers and counters
Module 4 registers and counters Deepak John
 
8255 Programmble Peripheral Interface
8255 Programmble Peripheral Interface8255 Programmble Peripheral Interface
8255 Programmble Peripheral InterfaceAmit Kumer Podder
 

What's hot (20)

Addressing mode Computer Architecture
Addressing mode  Computer ArchitectureAddressing mode  Computer Architecture
Addressing mode Computer Architecture
 
Windowing ofdm
Windowing ofdmWindowing ofdm
Windowing ofdm
 
3.programmable interrupt controller 8259
3.programmable interrupt controller 82593.programmable interrupt controller 8259
3.programmable interrupt controller 8259
 
8259 programmable interrupt controller
8259 programmable interrupt controller8259 programmable interrupt controller
8259 programmable interrupt controller
 
8251 USART
8251 USART8251 USART
8251 USART
 
Instruction set of 8086
Instruction set of 8086Instruction set of 8086
Instruction set of 8086
 
Adc interfacing
Adc interfacingAdc interfacing
Adc interfacing
 
8051 interrupts
8051 interrupts8051 interrupts
8051 interrupts
 
Programming 8051 Timers
Programming 8051 Timers Programming 8051 Timers
Programming 8051 Timers
 
4.4 diversity combining techniques
4.4   diversity combining techniques4.4   diversity combining techniques
4.4 diversity combining techniques
 
I/O Ports
I/O Ports I/O Ports
I/O Ports
 
Double SideBand Suppressed Carrier (DSB-SC)
Double SideBand Suppressed Carrier (DSB-SC)Double SideBand Suppressed Carrier (DSB-SC)
Double SideBand Suppressed Carrier (DSB-SC)
 
IMPLEMENTING ARITHMETIC INSTRUCTIONS IN EMU 8086
IMPLEMENTING ARITHMETIC INSTRUCTIONS IN EMU 8086IMPLEMENTING ARITHMETIC INSTRUCTIONS IN EMU 8086
IMPLEMENTING ARITHMETIC INSTRUCTIONS IN EMU 8086
 
The 8051 microcontroller
The 8051 microcontrollerThe 8051 microcontroller
The 8051 microcontroller
 
Types of line coding
Types of line codingTypes of line coding
Types of line coding
 
8086 instruction set with types
8086 instruction set with types8086 instruction set with types
8086 instruction set with types
 
Addressing modes 8085
Addressing modes 8085Addressing modes 8085
Addressing modes 8085
 
Addressing modes of 8085
Addressing modes of 8085Addressing modes of 8085
Addressing modes of 8085
 
Module 4 registers and counters
Module 4 registers and counters Module 4 registers and counters
Module 4 registers and counters
 
8255 Programmble Peripheral Interface
8255 Programmble Peripheral Interface8255 Programmble Peripheral Interface
8255 Programmble Peripheral Interface
 

Viewers also liked

Logic, shift and rotate instruction
Logic, shift and rotate instructionLogic, shift and rotate instruction
Logic, shift and rotate instructionkashif Shafqat
 
Flow control instructions
Flow control instructionsFlow control instructions
Flow control instructionsProdip Ghosh
 
Flow control in computer
Flow control in computerFlow control in computer
Flow control in computerrud_d_rcks
 
Computer system architecture
Computer system architectureComputer system architecture
Computer system architectureKumar
 
Flags registor of 8086 processor
Flags registor of 8086 processorFlags registor of 8086 processor
Flags registor of 8086 processorFazle Akash
 
8086 instructions
8086 instructions8086 instructions
8086 instructionsRavi Anand
 

Viewers also liked (6)

Logic, shift and rotate instruction
Logic, shift and rotate instructionLogic, shift and rotate instruction
Logic, shift and rotate instruction
 
Flow control instructions
Flow control instructionsFlow control instructions
Flow control instructions
 
Flow control in computer
Flow control in computerFlow control in computer
Flow control in computer
 
Computer system architecture
Computer system architectureComputer system architecture
Computer system architecture
 
Flags registor of 8086 processor
Flags registor of 8086 processorFlags registor of 8086 processor
Flags registor of 8086 processor
 
8086 instructions
8086 instructions8086 instructions
8086 instructions
 

Similar to Flag control

Assembly Language Programming By Ytha Yu, Charles Marut Chap 6 (Flow Control ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 6 (Flow Control ...Assembly Language Programming By Ytha Yu, Charles Marut Chap 6 (Flow Control ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 6 (Flow Control ...Bilal Amjad
 
Instructionsetof8086 by Alwani
Instructionsetof8086 by AlwaniInstructionsetof8086 by Alwani
Instructionsetof8086 by AlwaniHimanshu Alwani
 
Jumps in Assembly Language.
Jumps in Assembly Language.Jumps in Assembly Language.
Jumps in Assembly Language.NA000000
 
Loop instruction, controlling the flow of progam
Loop instruction, controlling the flow of progamLoop instruction, controlling the flow of progam
Loop instruction, controlling the flow of progamDr. Girish GS
 
Arithmetic and logical instructions set
Arithmetic and logical instructions setArithmetic and logical instructions set
Arithmetic and logical instructions setRobert Almazan
 
instruction-set-of-8086-mr-binu-joy3.ppt
instruction-set-of-8086-mr-binu-joy3.pptinstruction-set-of-8086-mr-binu-joy3.ppt
instruction-set-of-8086-mr-binu-joy3.pptssuser2b759d
 
Microprocessor:stack,shifting,looping
Microprocessor:stack,shifting,loopingMicroprocessor:stack,shifting,looping
Microprocessor:stack,shifting,loopingSamiul Ehsan
 
Intel codetable
Intel codetableIntel codetable
Intel codetableJ R7
 
Flags
FlagsFlags
FlagsCME
 
unit1.pdf
unit1.pdfunit1.pdf
unit1.pdfSaruM1
 
Microprocessor.pptx
Microprocessor.pptxMicroprocessor.pptx
Microprocessor.pptxNishatNishu5
 
Chap3 program flow control instructions
Chap3 program flow control instructionsChap3 program flow control instructions
Chap3 program flow control instructionsHarshitParkar6677
 
Chapter3 program flow control instructions
Chapter3 program flow control instructionsChapter3 program flow control instructions
Chapter3 program flow control instructionsHarshitParkar6677
 

Similar to Flag control (20)

Assignment on alp
Assignment on alpAssignment on alp
Assignment on alp
 
Assignment on alp
Assignment on alpAssignment on alp
Assignment on alp
 
Assembly Language Programming By Ytha Yu, Charles Marut Chap 6 (Flow Control ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 6 (Flow Control ...Assembly Language Programming By Ytha Yu, Charles Marut Chap 6 (Flow Control ...
Assembly Language Programming By Ytha Yu, Charles Marut Chap 6 (Flow Control ...
 
Al2ed chapter8
Al2ed chapter8Al2ed chapter8
Al2ed chapter8
 
Instructionsetof8086 by Alwani
Instructionsetof8086 by AlwaniInstructionsetof8086 by Alwani
Instructionsetof8086 by Alwani
 
Jumps in Assembly Language.
Jumps in Assembly Language.Jumps in Assembly Language.
Jumps in Assembly Language.
 
Loop instruction, controlling the flow of progam
Loop instruction, controlling the flow of progamLoop instruction, controlling the flow of progam
Loop instruction, controlling the flow of progam
 
Arithmetic and logical instructions set
Arithmetic and logical instructions setArithmetic and logical instructions set
Arithmetic and logical instructions set
 
instruction-set-of-8086-mr-binu-joy3.ppt
instruction-set-of-8086-mr-binu-joy3.pptinstruction-set-of-8086-mr-binu-joy3.ppt
instruction-set-of-8086-mr-binu-joy3.ppt
 
assembly flag resister
assembly flag resisterassembly flag resister
assembly flag resister
 
Expt 5 matrix.docx
Expt 5 matrix.docxExpt 5 matrix.docx
Expt 5 matrix.docx
 
Microprocessor:stack,shifting,looping
Microprocessor:stack,shifting,loopingMicroprocessor:stack,shifting,looping
Microprocessor:stack,shifting,looping
 
Intel codetable
Intel codetableIntel codetable
Intel codetable
 
Flags
FlagsFlags
Flags
 
Intel 8086
Intel 8086Intel 8086
Intel 8086
 
unit1.pdf
unit1.pdfunit1.pdf
unit1.pdf
 
Microprocessor.pptx
Microprocessor.pptxMicroprocessor.pptx
Microprocessor.pptx
 
Chapter2c
Chapter2cChapter2c
Chapter2c
 
Chap3 program flow control instructions
Chap3 program flow control instructionsChap3 program flow control instructions
Chap3 program flow control instructions
 
Chapter3 program flow control instructions
Chapter3 program flow control instructionsChapter3 program flow control instructions
Chapter3 program flow control instructions
 

More from Robert Almazan

Distruct week 15 graphs theory (updated)
Distruct week 15 graphs theory (updated)Distruct week 15 graphs theory (updated)
Distruct week 15 graphs theory (updated)Robert Almazan
 
Arithmetic instructions
Arithmetic instructionsArithmetic instructions
Arithmetic instructionsRobert Almazan
 
Week 5 lan topology part 2
Week 5 lan topology part 2Week 5 lan topology part 2
Week 5 lan topology part 2Robert Almazan
 
Week 4 introducing network standards
Week 4 introducing network standardsWeek 4 introducing network standards
Week 4 introducing network standardsRobert Almazan
 
Week 3 basic network media
Week 3 basic network mediaWeek 3 basic network media
Week 3 basic network mediaRobert Almazan
 
Week 2 network configurartion
Week 2 network configurartionWeek 2 network configurartion
Week 2 network configurartionRobert Almazan
 
introduction to networking
introduction to networkingintroduction to networking
introduction to networkingRobert Almazan
 

More from Robert Almazan (8)

Distruct week 15 graphs theory (updated)
Distruct week 15 graphs theory (updated)Distruct week 15 graphs theory (updated)
Distruct week 15 graphs theory (updated)
 
Arithmetic instructions
Arithmetic instructionsArithmetic instructions
Arithmetic instructions
 
Week 5 lan topology
Week 5 lan topologyWeek 5 lan topology
Week 5 lan topology
 
Week 5 lan topology part 2
Week 5 lan topology part 2Week 5 lan topology part 2
Week 5 lan topology part 2
 
Week 4 introducing network standards
Week 4 introducing network standardsWeek 4 introducing network standards
Week 4 introducing network standards
 
Week 3 basic network media
Week 3 basic network mediaWeek 3 basic network media
Week 3 basic network media
 
Week 2 network configurartion
Week 2 network configurartionWeek 2 network configurartion
Week 2 network configurartion
 
introduction to networking
introduction to networkingintroduction to networking
introduction to networking
 

Recently uploaded

Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptxSherlyMaeNeri
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfTechSoup
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designMIPLM
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxHumphrey A Beña
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYKayeClaireEstoconing
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfSpandanaRallapalli
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...Postal Advocate Inc.
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Celine George
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Celine George
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxChelloAnnAsuncion2
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Mark Reed
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Celine George
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4MiaBumagat1
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSJoshuaGantuangco2
 

Recently uploaded (20)

Judging the Relevance and worth of ideas part 2.pptx
Judging the Relevance  and worth of ideas part 2.pptxJudging the Relevance  and worth of ideas part 2.pptx
Judging the Relevance and worth of ideas part 2.pptx
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdfInclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
Inclusivity Essentials_ Creating Accessible Websites for Nonprofits .pdf
 
Keynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-designKeynote by Prof. Wurzer at Nordex about IP-design
Keynote by Prof. Wurzer at Nordex about IP-design
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptxINTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
INTRODUCTION TO CATHOLIC CHRISTOLOGY.pptx
 
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITYISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
ISYU TUNGKOL SA SEKSWLADIDA (ISSUE ABOUT SEXUALITY
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdf
 
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
USPS® Forced Meter Migration - How to Know if Your Postage Meter Will Soon be...
 
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
Incoming and Outgoing Shipments in 3 STEPS Using Odoo 17
 
Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17Difference Between Search & Browse Methods in Odoo 17
Difference Between Search & Browse Methods in Odoo 17
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
 
Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)Influencing policy (training slides from Fast Track Impact)
Influencing policy (training slides from Fast Track Impact)
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17Computed Fields and api Depends in the Odoo 17
Computed Fields and api Depends in the Odoo 17
 
Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4ANG SEKTOR NG agrikultura.pptx QUARTER 4
ANG SEKTOR NG agrikultura.pptx QUARTER 4
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
 

Flag control

  • 1. Flag Control Objective: • Identify the different flag control instruction • Apply the different flag control instructions
  • 2. Flag Control Instructions The 8086/8088 provides a group of instructions that directly affects the state of the flags. • LAHF Instruction • SAHF Instruction • CLC Instruction • STC Instruction • CMC Instruction • PUSHF Instruction • POPF Instruction
  • 3. The LAHF Instruction  The LAHF (Load AH from flags) instruction copies the SF, ZF, AF, PF, and CF into bits b7, b6, b4, b2, and b0 respectively of register AH. Format: Action: AH LAHF SF x ZF x AF x PF x CF
  • 4. The SAHF Instruction The SAHF (Store AH into flags) instruction transfers bits b7, b6, b4, b2, and b0 from register AH into SF, ZF, AF, PF, and CF, respectively. SAHFFormat: Action: SF ZF x AF x PF x CF AH Example: MOV AH, 25H SAHF
  • 5. The CLC Instruction  The CLC (Clear Carry Flag) instruction clears the carry flag.  Format: CLC  Action: CF 0
  • 6. The STC Instruction The STC (Set Carry Flag) instruction sets the carry flag to 1. Format: STC Action: CF 1
  • 7. The CMC Instruction  The CMC (Complement Carry Flag) instruction complements the carry flag.  Format: CMC  Action: CF CF’
  • 8. Status & Flags Register • Carry flag (CF): CF=1 if there is – a carry out from most significant bit (msb) on addition – a borrow into msb on subtraction – CF also affected differently by shift and rotate instructions • Parity flag (PF): PF=1 if – low byte of result has an even number of one bits (even parity) 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0 CFPFAFZFSFOF IFDF
  • 9. Status & Flags Register - Cont. • Auxiliary carry flag (AF): AF=1 if there is – a carry out from bit 3 on addition – a borrow into bit 3 on subtraction • Zero flag (ZF): ZF=1 – if the result is zero • Sign flag (SF): SF=1 if – msb of result is 1 indicating that the result is negative for signed number interpretation • Overflow flag (OF): OF=1 – if signed overflow occurs
  • 10. The PUSHF Instruction  The PUSHF (Push Status Register onto Stack) instruction pushes the flag register onto the stack. PUSHF decrements SP by 2 and then moves the flag register to the top of the stack.  Format: PUSHF  Action: SP SP - 2 SP [flag register]
  • 11. The POPF Instruction  The POPF (Pop Flags off the Stack) instruction transfers the word pointed to by SP to the status register, thereby altering the value of the flags. POPF  Format: Action: status register SP [SP] SP + 2
  • 12. Stack Instructions • SP points at the the top of the stack • .STACK 100H – SP is initialized to 100H • PUSH operand – SP  SP - 2 – [SP+1:SP]  operand • POP operand – Operand  [SP+1:SP] – SP  SP + 2 • PUSHF – SP  SP - 2 – [SP+1:SP]  flags register • POPF – Flags register  [SP+1:SP] – SP  SP + 2
  • 13. The CLI Instruction  The CLI (Clear Interrupt Flag) instruction clears the interrupt flag, thereby disabling interrupt request. The 8086/8088 will therefore not recognize any external interrupt request with the exception of the non-maskable interrupt.  Format: CLI  Action: IF 0
  • 14. The STI Instruction  The STI (Set Interrupt Flag) instruction sets the interrupt flag to 1, thereby enabling the 8086/8088 to recognize any interrupt request.  Format: STI  Action: IF 1
  • 15. The CLD Instruction  The CLD (Clear Direction Flag) instruction clears the direction flag, thereby causing the string instruction to auto-increment the index registers (SI or DI).  Format: CLD  Action: DF 0
  • 16. The STD Instruction  The STD (Set Direction Flag) instruction sets the direction flag to 1, thereby causing the string instruction to auto-decrement the index registers (SI or DI).  Format: STD  Action: DF 1
  • 18. Flow Control Instructions • Unconditional jump – JMP label ; IP  label • Conditional jump – Signed jumps – Unsigned jumps – Common jumps • Signed jumps – JG/JNLE jump if greater than, or jump if not less than or equal – JGE/JNL jump if greater than or equal, or jump if not less than – JL/JNGE jump if less than, or jump if not greater than or equal – JLE/JNG jump if less than or equal, or jump if not greater than
  • 21. Flow Control Instructions • Single-flag jumps – JS jump if sign negative – JNS jump if nonnegative sign – JP/JPE jump if parity even – JNP/JPO jump if parity odd • Jump based on CX – JCXZ if CX = 0, then jump to the address specified by the operand • Loop Instructions – Loop short-label -loop decrement CX – Loopnz/Loopne -loop while not zero/loop while not equal – Loopz/Loope -loop while zero/loop while equal • All jump instructions have no effect on the flags.
  • 23. Branching Structures: IF-Then • Example: If AX < 0 Then Replace AX by –AX ENDIF ; if AX < 0 CMP AX, 0 JNL END_IF ;then NEG AX END_IF:
  • 24. IF-Then-Else • Example: If AL <= BL Then Display character in AL Else Display character in BL ENDIF MOV AH, 2 ; if AL<=BL CMP AL, BL JNBE ELSE_ ;then MOV DL, AL JMP DISPLAY ELSE_: MOV DL, BL DISPLAY: INT 21H END_IF:
  • 25. CASE • Example: CASE AX <0: put –1 in BX =0: put 0 in BX >0: put 1 in BX END_CASE ; case AX CMP AX, 0 JL NEGATIVE JE ZERO JG POSITIVE NEGATIVE: MOV BX, -1 JMP END_CASE ZERO: MOV BX, 0 JMP END_CASE POSITIVE: MOV BX, 1 END_CASE:
  • 26. CASE – Cont. • Example: CASE AL 1,3: display ‘o’ 2,4: display ‘e’ END_CASE ; case AL CMP AL, 1 ; 1, 3: JE ODD CMP AL, 3 JE ODD CMP AL, 2 ; 2, 4: JE EVEN CMP AL, 4 JE EVEN JMP END_CASE ODD: MOV DL, ‘o’ JMP DISPLAY EVEN: MOV DL, ‘e’ DISPLAY: MOV AH, 2 INT 21H END_CASE:
  • 27. Branches with Compound Conditions • Example: If (‘A’ <= character) and (character <= ‘Z’) Then Display character END_IF ; read a character MOV AH, 1 INT 21H ; If (‘A’ <= character) and (character <= ‘Z’) Then CMP AL, ‘A’ JNGE END_IF CMP AL, ‘Z’ JNLE END_IF ; display character MOV DL, AL MOV AH, 2 INT 21H END_IF:
  • 28. Branches with Compound Conditions • Example: If (character=‘y’) OR (character <= ‘Y’) Then Display character Else terminate program END_IF ; read a character MOV AH, 1 INT 21H ; If (character=‘y’) OR (character = ‘Y’) Then CMP AL, ‘y’ JE Then CMP AL, ‘Y’ JE Then JMP ELSE_ Then: MOV AH, 2 MOV DL, AL INT 21H JMP END_IF ELSE:MOV AH, 4CH INT 21H END_IF:
  • 29. Loop Instructions • Loop Next – Dec Cx – If CX<>0 JMP Next • Loopz/loope Next – Dec Cx – If (CX<>0) AND (ZF=1) JMP Next • Loopnz/loopne Next – Dec Cx – If (CX<>0) AND (ZF=0) JMP Next
  • 30. FOR LOOP • Example: For 80 times DO Display ‘*’ END_IF MOV CX, 80 MOV AH, 2 MOV DL, ‘*’ Next: INT 21H Loop Next
  • 31. While Loop • Example: Initialize count to 0 Read a character While character <> Carriage Return DO Count = Count + 1 Read a character END_While MOV DX, 0 MOV AH, 1 INT 21H While_: CMP AL, 0DH JE End_While INC DX INT 21H JMP While_ End_While:
  • 32. Repeat Loop • Example: Repeat Read a character Until character is blank MOV AH, 1 Repeat: INT 21H ; until CMP AL, ‘ ‘ JNE Repeat
  • 33. Application of Loope • Example: Search for a number in a Table Table DB 1,2,3,4,5,6,7,8,9 XOR SI, SI MOV CX, 9 Next: INC SI CMP Table[SI-1], 7 Loopne Next