THE
80286
INSTRUCTION SET
RET
-Return
from Procedure
Opcode
CB
CB
C3
CA
dw
CA dw
C2 dw
Instruction
RET
RET
RET
RET dw
RET dw
RET dw
Clocks·
15,pm=25
55
11
15,pm=25
55
11
Description
Return to far caller, same privilege
Return, lesser privilege, switch stacks
Return
to
near caller, same privilege
RET (far), same privilege,
pop
dw bytes
RET (far), lesser privilege,
pop
dw bytes
RET (near),
same
privilege,
pop
dw
bytes
pushed before Call
• Add 1 clock for each byte
in
the next instruction executed.
FLAGS MODIFIED
None
FLAGS UNDEFINED
None
OPERATION
RET transfers control to a return address located
on
the stack. The address
is
usually placed
on
the
stack
by
a CALL instruction;
in
that case, the return
is
made to the instruction that
follows
the CALL.
There
is
an optional numeric parameter to RET.
It
gives the number of stack bytes
to
be released after
the return address
is
popped. These bytes are typically used
as
input parameters to the procedure
called.
For the intra-segment return, the address
on
the stack
is
a 2-byte quantity popped into IP. The CS
register
is
unchanged.
For the inter-segment return, the address
on
the stack
is
a 4-byte-long pointer. The offset
is
popped
first, followed by the selector. In real address mode,
CS and
IP
are directly loaded.
In protected mode, an inter-segment return causes the processor to consult the descriptor addressed by
the return selector. The
AR
byte of the descriptor must indicate a code segment of equal or less privi-
lege (of greater
or
equal numeric value) than the current privilege level. Returns
to
a lesser privilege
level cause the stack to be reloaded from the value saved beyond the parameter block.
The DS
u;;.d
ES
Geg:ne~t
registers !!!'!y
b~
8f:'t
to
7.~rn
hy the inter-segment RET instruction.
If
these
registers refer to segments which cannot be used by the
new
privilege level, they are set to zero to
prevent unauthorized access.
The following list of checks and actions describes the protected-mode inter-segment return
in
detail.
Inter-segment RET:
Second word on stack must be within stack limits else
#SS(O)
Return selector RPL must be 2:: CPL else
#GP
(return selector)
If return selector RPL = CPL then
B-94