4. Flow Control Instructions
īļ Program using the different instruction :-
ī Conditional and Unconditional Jump Instructions
īCompare Instruction
īLoop Instruction
5. Conditional Jump
īļSyntax:
īJxxx destination_label
īWhere xxx represents the condition
īļIf condition is true, the next instruction to be executed is the one at
destination_label.
īļIf condition is false, the instruction immediately following the jump is
done next.
6. Conditional Jump
īļThe destination_label must precede the jump instruction by no more
than 126 bytes.
īļTo implement a conditional jump, the CPU looks at the FLAG
register (set by last instruction executed by the processor).
īļJMP instructions themselves do not affect flags.
8. Categories of Conditional Jump
īļSigned Jumps: This is used when a signed interpretation is being
given to result.
Symbol Description Condition for Jumps
JG/JNLE Jump if greater than
Jump if not less than or equal to
ZF = 0 and SF = OF
JGE/JNL Jump if greater than or equal to
Jump if not less than
SF = OF
JL/JNGE Jump if less than
Jump if not greater than or equal to
SF <> OF
JLE/JNG Jump if less than or equal to
Jump if not greater than
ZF = 1 and SF <> OF
9. Categories of Conditional Jump
īļUnsigned Jumps: This is used for an unsigned interpretation of result
Symbol Description Condition for Jumps
JA/JNBE Jump if above than
Jump if not below than or equal to
ZF = 0 and CF = 0
JAE/JNB Jump if above than or equal to
Jump if not below than
CF = 0
JB/JNAE Jump if below than
Jump if not above than or equal to
CF = 1
JBE/JNA Jump if below than or equal to
Jump if not above than
ZF = 1 and CF = 1
17. CASE
īļA case is a multiway branch structure that tests a register,
variable, or expression for particular values or range of
values. The general form is as follows:
īļCase Expression
īvalues_1: statements_1
īvalues_2: statements_2
âĻâĻâĻâĻ..
īvalues_n: statements_n
īEND_CASE
19. High Level Language Structures
īļBranching with Compound Conditions
ī AND CONDITIONS
ī OR CONDITIONS
20. AND CONDITION
ī An AND condition is true if and only if condition_1 and
condition_2 are both true.
ī If any condition is false, then the whole thing is false.
22. OR CONDITION
ī If condition_1 OR condition_2 is true then an OR conditions is true.
ī If both conditions are false, then the whole thing is false.
24. High Level Language Structures
īļLooping Structures
īFOR LOOP
īWHILE LOOP
īREPEAT LOOP
25. LOOPING STRUCTURES
īļFOR LOOP
īExecuted at least once.
ī If CX contains 0, the loop instruction decrements CX (CX =
FFFFh)
ī To prevent this, use instruction JCXZ before the loop.
;initialize CX
JCXZ SKIP
TOP:
;body of the loop
LOOP TOP
SKIP:
27. LOOPING STRUCTURES
īļWHILE LOOP
ī WHILE condition DO
ī ;statements
ī END_WHILE
ī WHILE LOOP checks the terminating condition at the top of the
loop, so donât forget to initialize variables.
29. LOOPING STRUCTURES
īļREPEAT LOOP
ī REPEAT
ī ;statements
ī UNTIL condition
īļFirst statements are executed, then the condition is checked.
īļIf true, the loop terminates; if false, control branches to the top of the
loop