You are on page 1of 33

Control Transfer

Instructions

Unconditional Jump
Instruction - JMP
This

instruction unconditionally
transfers control to the target
location. The target location contains
the next instruction to be executed
by the microprocessor.

Unconditional Jump
Instruction - JMP

Unconditional Jump
Instruction - JMP

Unconditional Jump
Instruction - JMP
INTRASEGMENT JUMP

INTERSEGMENT JUMP

the jump is limited to


within the code
segment only.

the jump is allowed to


any other code
segment. Both the
code segment and
the IP are modified.

Unconditional Jump
Instruction - JMP
RELATIVE OPERAND

A relative operand is
a signed
displacement from
the JMP instruction to
the target location.
The address of the
target location can be
obtained by adding
the displacement
from the JMP
instruction.

INDIRECT OPERAND

An indirect operand can


be a 16-bit register that
contains the offset
address of the next
instruction to be executed
by the microprocessor. An
indirect operand can be a
16-bit register that
indirectly points a
memory location where
the offset address can be
found.

Unconditional Jump
Instruction - JMP
SHORT-LABEL

A short jump
displacement is a
distance represented by
a one-byte signed
number whose value
ranges between +127
and -128. A negative
displacement (80 to FF)
means jump backward
and A positive
displacement (01 to 7F)
means jump upward.

NEAR-LABEL

A near jump allows a


branch or jump within
+32K bytes or
anywhere in the
current code segment
from the instruction in
the current code
segment.

Unconditional Jump
Instruction - JMP
REGPTR16

MEMPTR16

A 16-bit register that


contains the offset
address to be loaded
to IP.

the physical address


of the next instruction
is located in the
memory pointed to by
Memptr16. IP =
[mem] & [mem+1].

Unconditional Jump
Instruction - JMP
FAR-LABEL

MEMPTR32

it signifies an
intersegment jump.

the physical address


of the next instruction
is located in the
memory pointed to by
Memptr32. IP =
[mem] & [mem+1];
CS = [mem+ 2] &
[mem+3].

Examples:
Intrasegment

Jump
(Relative, short-label, jump forward)

Examples:
Intrasegment

Jump
(Relative, short-label, jump forward)

Examples:
Intrasegment

Jump
(Relative, near-label)

Examples:
Intrasegment

Jump
(Indirect, Regptr16)

Examples:
Intrasegment

Jump
(Indirect, Memptr16)

Examples:
Intrasegment

Jump
(Indirect, Memptr32)

Examples:
Intrasegment

Jump
(Relative, short-label, jump
backward)

Conditional Jump Instructions


- Jcc
Conditional

transfer instructions are


jumps that may or may not transfer
control depending on the state of the
status flags at the time the
instruction is executed.

Conditional Jump Instructions


- Jcc
Important

Facts:

1. Only the short-label operand is

supported by conditional jump


instructions.
2. Conditional jump should be placed
immediately after an instruction that
will modify the status flags such as
CMP, INC, DEC, etc.

Conditional Jump Instructions


- Jcc
Comparing

Unsigned Numbers

Conditional Jump Instructions


- Jcc
Comparing

Signed Numbers

Conditional Jump Instructions


- Jcc
Test

Flags

Conditional Jump Instructions


- Jcc
Test

Flags

Example:

Iteration Controls
LOOP
It is a combination of decrement CX and JNZ.
It transfers control to the target location while
CX <> 0. If CX becomes 0, the next
sequential instruction is executed.

Iteration Controls
LOOPE/LOOPZ
It decrements CX by 1 and transfers control to
the target location while CX <> 0 and ZF = 1.
If CX = 0 or ZF = 0, the loop is terminated
and the instruction following loop is executed.

Iteration Controls
LOOPNE/LOOPNZ
It decrements CX by 1 and transfers control to
the target location while CX <> 0 and ZF = 0.
If CX = 0 or ZF = 1, the loop is terminated
and the instruction following loop is executed.

Iteration Controls
LOOPNE/LOOPNZ
It decrements CX by 1 and transfers control to
the target location while CX <> 0 and ZF = 0.
If CX = 0 or ZF = 1, the loop is terminated
and the instruction following loop is executed.

Iteration Controls
JCXZ
It transfers control to the target operand if CX
is 0.

Subroutine and Subroutine


Handling Instructions
CALL
It transfers control to a subroutine. After
executing the subroutine, control is
transferred back to the instruction following
the CALL instruction. . In order to do this, the
contents of either both registers CS and IP, or
register IP only (if Intrasegment call), are
pushed into the stack before the control is
relinquished to the subroutine.

Subroutine and Subroutine


Handling Instructions

Subroutine and Subroutine


Handling Instructions
RET
It transfers control from a subroutine back to
the instruction following the CALL instruction.

Subroutine and Subroutine


Handling Instructions
RET
Important Facts:
1. For intrasegment CALL, RET pops out the contents
of the register IP at the top of the stack. For
intersegment CALL, RET pops out both the contents
of the register IP and CS at the top of the stack.
2. The optional Disp16 operand is an offset value
added to register SP after restoring the return
address into register CS and IP, or register IP only.
This is provided to discard the parameters that are
pushed into the stack before the CALL instruction is
initiated.

Examples:

Examples:

You might also like