Flow Control Structures
Flow Control Structures
STRUCTURES
JMP target
unconditionally transfers control to the target location.
There are two major categories of JMP instructions:
Intrasegment jump: A jump to a statement in the same
code segment.
Intersegment or far jump: A jump to a statement in a
different code segment.
Intrasegment jumps simply change the value in the IP
register. Intersegment jumps change both CS and IP.
CONDITIONAL JUMP
INSTRUCTIONS
Conditional jumps are of the general form:
Jcondition StatementLabel
where
(i) condition is one, two, or three letters
(ii) the StatementLabel must in the current code
segment and should be within -128 to +127 bytes
from the conditional jump instruction.
Except for the JCXZ (Jump if the value in the CX register is zero) and
JECXZ (Jump if the value in ECX register is zero) instruction, every
conditional jump instruction must follow a status-flag modifying
instruction, either immediately or otherwise.
It is the settings of the flags by this status-flag modifying instruction to
which the conditional jump reacts:
When a conditional jump is executed, the CPU checks the flags register.
If the conditions for the jump (expressed as one or more status flag
settings) are true, the CPU adjusts the IP register to point to the
destination label, so that the instruction at this label will be executed
next.
If the jump condition is false, then the IP register is not altered; this
means that the next sequential instruction will be executed.
SUB AX , BX
JZ L2
zero
.
.
.
L2:
.
SUB AX , BX
JZ L2
.
.
.
Note:
The two operands must be of the same size, except in
a comparison of the form:
CMP Operand, Immediate
Immediate may be of a smaller size than Operand.
Both operands may not be memory locations at the
same time.
No operand may be a segment register.
Operand1 may not be an immediate value.
IMPLEMENTATION OF HIGH-LEVEL
LANGUAGE CONTROL STRUCTURES
Note: In what follows it is
assumed that OP, OP1
and OP2 are signed
operands such that in any
comparison there is no
assembly error, and
statement' is the
assembly language
translation of statement.