Computer Hardware User's Guide

Calls, Traps, and Returns
7-11
Program Flow Control
7.3 Calls, Traps, and Returns
Calls and traps provide a means of executing a subroutine or function while
providing a return to the calling routine.
The CALL, CALL
cond,
and TRAP
cond
instructions store the value of the PC
on the stack before changing the PC’s contents. The RETS
cond
or RETI
cond
instructions use the value on the stack to return execution from traps and calls.
CALL is a 4-cycle instruction, while CALL
cond
and TRAP
cond
are 5-cycle
instruction.
The CALL instruction places the next PC value on the stack and places
the
src
(source) operand into the PC. The
src
is a 24-bit immediate value.
Figure 7–1 shows CALL response timing.
The CALL
cond
instruction is similar to the CALL instruction except for two
differences:
It executes only if a specific condition is true (the 20 conditions—
including unconditional—are listed in Table 13–12 on page 13-30).
The
src
is either a PC-relative displacement or is in register-addres-
sing mode.
The condition flags are set by a previous instruction only when the destination
register is one of the extended-precision registers (R0–R7) or when one of
the compare instructions (CMPF, CMPF3, CMPI, CMPI3, TSTB, or TSTB3)
is executed.
The TRAP
cond
instruction also executes only if a specific condition is true
(same conditions as for the CALL
cond
instruction). When executing, the
following actions occur:
1) Interrupts are disabled with 0 written to bit GIE of the ST.
2) The next PC value is stored on the stack.
3) The specified vector is retrieved from the trap-vector table and is loaded
into the PC. The vector address corresponds to the trap number in the
instruction.
Using the RETI
cond
to return reenables interrupts by setting the bit field of
the status register.
RETS
cond
returns execution from any of the above three instructions by
popping the top of the stack to the PC. For RETS
cond
to execute, the
specified condition must be true. The conditions are the same as for the
CALL
cond
instruction.