Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
SlideShare a Scribd company logo
Program Flow Control
Instructions
Unconditional Jumps
• Unconditional Jumps
• The basic instruction that transfers control to another
point in the program is JMP. The basic syntax of JMP
instruction
General Form (Syntax):
• JMP label
• JMP is able to transfer control both forward and
backward.
• Here the CS and IP are unconditionally modified with
new CS and IP values.
• No flags are checked or affected by this instruction
Unconditional Jumps
• Intra-segment Jump or NEAR jump :
• If the target of JMP is in the same code segment,
it requires only the IP to be changed to transfer
control to the target location. This is called intra-
segment jump or NEAR jump
• Inter-segment or FAR jump :
• If the target for the instruction JMP is in different
code segment from that containing the JMP, then
IP and CS will be changed to transfer control to
the target location. Such a jump is called FAR or
Inter- Segment jump.
Unconditional Jumps
• Unlike JMP instruction that does an
unconditional jump, there are instructions
that do a conditional jumps (jump only when
some conditions are in act).
• The different types of conditional instruction
are as given in the next slide…
Jump instructions based on Flags
Instruction Description Condition Similar
Instructions
JC Jump if carry Carry = 1 JB, JNAE
JNC Jump if no carry Carry = 0 JNB, JAE
JZ Jump if zero Zero = 1 JE
JNZ Jump if not zero Zero = 0 JNE
JS Jump if sign Sign = 1 -
JNS Jump if no sign Sign = 0 -
JO Jump if overflow Ovrflw=1 -
JNO Jump if no Ovrflw Ovrflw=0 -
JP Jump if parity Parity = 1 JPE
JPE Jump if parity even Parity = 1 JP
JNP Jump if no parity Parity = 0 JPO
JPO Jump if parity odd Parity = 0 JNP
Jump Instructions based on Unsigned
numbers
Instruction Description Condition
Similar
Instructions
JA Jump if above (>) Carry=0, Zero=0 JNBE
JNBE Jump if not below or equal (not <=) Carry=0, Zero=0 JA
JAE Jump if above or equal (>=) Carry = 0 JNC, JNB
JNB Jump if not below (not <) Carry = 0 JNC, JAE
JB Jump if below (<) Carry = 1 JC, JNAE
JNAE Jump if not above or equal (not >=) Carry = 1 JC, JB
JBE Jump if below or equal (<=)
Carry = 1 or Zero
= 1
JNA
JNA Jump if not above (not >)
Carry = 1 or Zero
= 1
JBE
JE Jump if equal (=) Zero = 1 JZ
JNE Jump if not equal () Zero = 0 JNZ
Jump Instructions for signed numbers
Instruction Description Condition
Similar
Instructions
JG Jump if greater (>)
Sign = Ovrflw
or Zero=0
JNLE
JNLE
Jump if not less than or equal (not
<=)
Sign = Ovrflw
or Zero=0
JG
JGE Jump if greater than or equal (>=) Sign = Ovrflw JNL
JNL Jump if not less than (not <) Sign = Ovrflw JGE
JL Jump if less than (<) Sign Ovrflw JNGE
JNGE Jump if not greater or equal (not >=) Sign Ovrflw JL
JLE Jump if less than or equal (<=)
Sign Ovrflw or
Zero = 1
JNG
JNG Jump if not greater than (not >)
Sign Ovrflw or
Zero = 1
JLE
JE Jump if equal (=) Zero = 1 JZ
JNE Jump if not equal () Zero = 0 JNZ
Jump Instructions for signed numbers
Instruction Description Condition
Similar
Instructions
JG Jump if greater (>)
Sign = Ovrflw
or Zero=0
JNLE
JNLE
Jump if not less than or equal (not
<=)
Sign = Ovrflw
or Zero=0
JG
JGE Jump if greater than or equal (>=) Sign = Ovrflw JNL
JNL Jump if not less than (not <) Sign = Ovrflw JGE
JL Jump if less than (<) Sign Ovrflw JNGE
JNGE Jump if not greater or equal (not >=) Sign Ovrflw JL
JLE Jump if less than or equal (<=)
Sign Ovrflw or
Zero = 1
JNG
JNG Jump if not greater than (not >)
Sign Ovrflw or
Zero = 1
JLE
JE Jump if equal (=) Zero = 1 JZ
JNE Jump if not equal () Zero = 0 JNZ
Machine Control Instructions
• HLT : (Halt)
• This instruction causes the processor to enter to halt state.
• CPU stops fetching and executing instructions
• CPU is brought out of the halt state when reset signal is
given to it, or NMI is given or INTR pin goes high.
• NOP: (No Operation)
• This instruction is used to add wait states of 3 clock cycles.
• During these three clock cycles, CPU does not perform
anything.
• This instruction is useful in delay programs to add delay
loops
Machine Control Instructions
• WAIT
• This instruction causes the processor to enter into an idle state or a
wait state.
• Processor continues to remain in the wait state till a valid INTR or
NMI or a TEST pin goes high.
• It is used to synchronise with other external hardware such as Math
co-processor 8087.
• LOCK
• This instruction causes the processor to take control of the shared
resources.
• This is used as an instruction prefix to some critical instructions
which has to be executed.
• While LOCKED, it prevents the resources to be shared by other
processors.
• Example : LOCK IN AL,80H
Flag manipulation instructions
These instructions are used to change the status of flags in the
flag register such as Carry, Direction and Interrupt.
• CLC
• This instruction clears the Carry Flag
• CF  0
• CMC
• This instruction complements the Carry Flag
• CF  Complement of CF
• STC
• This instruction sets the Carry Flag
• CF  1
Flag manipulation instructions
• CLD
• This instruction clears the Direction Flag
• DF  0
• STD
• This instruction sets the Direction Flag
• DF  1
• CLI
• This instruction clears the Interrupt Flag
• IF  0
• STI
• This instruction sets the Interrupt Flag
• IF  1

More Related Content

Chapter3 program flow control instructions

  • 2. Unconditional Jumps • Unconditional Jumps • The basic instruction that transfers control to another point in the program is JMP. The basic syntax of JMP instruction General Form (Syntax): • JMP label • JMP is able to transfer control both forward and backward. • Here the CS and IP are unconditionally modified with new CS and IP values. • No flags are checked or affected by this instruction
  • 3. Unconditional Jumps • Intra-segment Jump or NEAR jump : • If the target of JMP is in the same code segment, it requires only the IP to be changed to transfer control to the target location. This is called intra- segment jump or NEAR jump • Inter-segment or FAR jump : • If the target for the instruction JMP is in different code segment from that containing the JMP, then IP and CS will be changed to transfer control to the target location. Such a jump is called FAR or Inter- Segment jump.
  • 4. Unconditional Jumps • Unlike JMP instruction that does an unconditional jump, there are instructions that do a conditional jumps (jump only when some conditions are in act). • The different types of conditional instruction are as given in the next slide…
  • 5. Jump instructions based on Flags Instruction Description Condition Similar Instructions JC Jump if carry Carry = 1 JB, JNAE JNC Jump if no carry Carry = 0 JNB, JAE JZ Jump if zero Zero = 1 JE JNZ Jump if not zero Zero = 0 JNE JS Jump if sign Sign = 1 - JNS Jump if no sign Sign = 0 - JO Jump if overflow Ovrflw=1 - JNO Jump if no Ovrflw Ovrflw=0 - JP Jump if parity Parity = 1 JPE JPE Jump if parity even Parity = 1 JP JNP Jump if no parity Parity = 0 JPO JPO Jump if parity odd Parity = 0 JNP
  • 6. Jump Instructions based on Unsigned numbers Instruction Description Condition Similar Instructions JA Jump if above (>) Carry=0, Zero=0 JNBE JNBE Jump if not below or equal (not <=) Carry=0, Zero=0 JA JAE Jump if above or equal (>=) Carry = 0 JNC, JNB JNB Jump if not below (not <) Carry = 0 JNC, JAE JB Jump if below (<) Carry = 1 JC, JNAE JNAE Jump if not above or equal (not >=) Carry = 1 JC, JB JBE Jump if below or equal (<=) Carry = 1 or Zero = 1 JNA JNA Jump if not above (not >) Carry = 1 or Zero = 1 JBE JE Jump if equal (=) Zero = 1 JZ JNE Jump if not equal () Zero = 0 JNZ
  • 7. Jump Instructions for signed numbers Instruction Description Condition Similar Instructions JG Jump if greater (>) Sign = Ovrflw or Zero=0 JNLE JNLE Jump if not less than or equal (not <=) Sign = Ovrflw or Zero=0 JG JGE Jump if greater than or equal (>=) Sign = Ovrflw JNL JNL Jump if not less than (not <) Sign = Ovrflw JGE JL Jump if less than (<) Sign Ovrflw JNGE JNGE Jump if not greater or equal (not >=) Sign Ovrflw JL JLE Jump if less than or equal (<=) Sign Ovrflw or Zero = 1 JNG JNG Jump if not greater than (not >) Sign Ovrflw or Zero = 1 JLE JE Jump if equal (=) Zero = 1 JZ JNE Jump if not equal () Zero = 0 JNZ
  • 8. Jump Instructions for signed numbers Instruction Description Condition Similar Instructions JG Jump if greater (>) Sign = Ovrflw or Zero=0 JNLE JNLE Jump if not less than or equal (not <=) Sign = Ovrflw or Zero=0 JG JGE Jump if greater than or equal (>=) Sign = Ovrflw JNL JNL Jump if not less than (not <) Sign = Ovrflw JGE JL Jump if less than (<) Sign Ovrflw JNGE JNGE Jump if not greater or equal (not >=) Sign Ovrflw JL JLE Jump if less than or equal (<=) Sign Ovrflw or Zero = 1 JNG JNG Jump if not greater than (not >) Sign Ovrflw or Zero = 1 JLE JE Jump if equal (=) Zero = 1 JZ JNE Jump if not equal () Zero = 0 JNZ
  • 9. Machine Control Instructions • HLT : (Halt) • This instruction causes the processor to enter to halt state. • CPU stops fetching and executing instructions • CPU is brought out of the halt state when reset signal is given to it, or NMI is given or INTR pin goes high. • NOP: (No Operation) • This instruction is used to add wait states of 3 clock cycles. • During these three clock cycles, CPU does not perform anything. • This instruction is useful in delay programs to add delay loops
  • 10. Machine Control Instructions • WAIT • This instruction causes the processor to enter into an idle state or a wait state. • Processor continues to remain in the wait state till a valid INTR or NMI or a TEST pin goes high. • It is used to synchronise with other external hardware such as Math co-processor 8087. • LOCK • This instruction causes the processor to take control of the shared resources. • This is used as an instruction prefix to some critical instructions which has to be executed. • While LOCKED, it prevents the resources to be shared by other processors. • Example : LOCK IN AL,80H
  • 11. Flag manipulation instructions These instructions are used to change the status of flags in the flag register such as Carry, Direction and Interrupt. • CLC • This instruction clears the Carry Flag • CF  0 • CMC • This instruction complements the Carry Flag • CF  Complement of CF • STC • This instruction sets the Carry Flag • CF  1
  • 12. Flag manipulation instructions • CLD • This instruction clears the Direction Flag • DF  0 • STD • This instruction sets the Direction Flag • DF  1 • CLI • This instruction clears the Interrupt Flag • IF  0 • STI • This instruction sets the Interrupt Flag • IF  1