Lecture 6 (A)
Lecture 6 (A)
If result of preceding instruction is not Zero Then the JNZ transfers the control to the
instruction at label PRINT_LOOP.
If the preceding instruction contains zero (i.e. CX=0) then the program goes to execute
DOS return instructions.
JXXX destination_label
if the condition for the jump is true, the next instruction to be executed is
at destination_label
If the jump condition is false, then IP is not altered and naturally the
next instruction is performed.
Example(cont’d…)
It computes by…
JB or • Jump if Below CF = 1
JNAE • Jump if not Above or Equal
JC • Jump if Carry CF = 1
CF = 0
JNC • Jump if no Carry CF=0
JO • Jump if Overflow CF=1 or ZF = 1
JNO • Jump if No Overflow OF=1
JS Jump if Sign Negative SF = 1
JNS Jump if Non-Negative Sign SF =0
JP/JPE Jump if Parity Even PF=1
JNP/JPO Jump if parity Odd PF=1
Conditional Jumps
Interpretation
Signed JUMPs correspond to an analogous unsigned JUMPs (i.e. JG is equivalent to JA)
Using wrong kind of JUMP can lead to wrong results. For example: for AX= 7FFFh and BX= 8000h
CMP AX,BX
JA BELOW
Even though 7FFFh>8000h in a signed sense, the program does not jump to label BELOW. Because
JMP destination
JMP TOP
MOV AX,BX EXIT:
MOV AX,BX
High-Level Language
Structures
1. 1. IF-THEN
2. 2. IF-THEN-ELSE
3. 3. CASE
IF-THEN
IF condition is true.
THEN
execute true-branch
statements
END_IF
A Pseudo Code , Algorithm
and Code for IF-THEN
• The condition is an expression that is either true or false.
• lf It is true, the true-branch statements are executed.
• lf It is false, nothing is done, and the program goes on to whatever
follows.
• Example: to Replace a number in AX by its absolute value…
IF condition is true
THEN
execute true-branch
statements
ELSE
execute false-branch
statements
END_IF
A Pseudo Code and algorithm and Code for
IF-THEN-ELSE
• The condition is an expression that is either true or false.
• If It is true, the true-branch statements are executed.
• If It is false then False-branch statements are executed.
• Example: Suppose AL and BL contain extended ASCII characters. Display the one
that comes first in the character sequence…
MOV AH,2
CMP AL,BL ;AL<=BL ?
IF AL <= BL JNBE ELSE_
THEN MOV DL,AL
Display the character in AL JMP DISPLAY
ELSE ELSE_:
Display the character in BL MOV DL,BL
END IF DISPLAY:
INT 2lh
CASE
A CASE is a multi-way branch structure that tests a register, variable, or expression for
particular values or a range of values.
CASE Expression
Values_1:
Statement_1
Values_2:
Statement_2
… Values_n:
Statement_n
END_CASE
CASE
• Example: If AX contains a negative number, put -1 in BX; if AX contains 0,
put 0 in BX; and if AX contains a positive number, put 1 in BX.
CMP AX,O
JL NEGATIVE
JE ZERO
CASE AX JG POSITIVE
<0 : put -1 in BX NEGATIVE:
=0 : put 0 in BX MOV BX,-1
>0 : put +l in BX JMP END_CASE
ZERO:
END_CASE
MOV BX,0
JMP END_CASE
POSITIVE:
MOV BX, l
END_CASE:
Solve the Following
END_CASE
References
• https://www.slideshare.net/prodipghoshjoy/flow-control-instructions-6060
2372
Books