
CHAPTER 2: ARCHITECTURE
•Return instructions (RET, RETS, RETD, RETI)
A return instruction is used to return from a subroutine called by the call instruction to the routine that called the subroutine. Return operation is done by loading the PC value (address next to the call instruction) that was stored in the stack when the subroutine was called into the PC.
The RET instruction operates only to return the PC value in the stack, and the processing is continued from the address next to the call instruction.
The RETS instruction returns the PC value then adds "1" to the PC. It skips executing an instruction next to the call instruction.
Figure 2.2.3.3 shows return operations from a subroutine.
| Mainroutine | Subroutine |
| ||
| : |
| : |
|
|
Address | : |
| ADD | A,B |
|
xxxxH | CALR sign8 | : |
|
| |
xxxxH+1 | JR | sign8 | JR | NC,1 |
|
xxxxH+2 | LD | %A,[%X] | RET (RETD) | Return to | |
|
|
|
|
| xxxxH+1 |
| : |
| RETS |
| Return to |
|
|
|
|
| xxxxH+2 |
Fig. 2.2.3.3 Return from subroutine
The RETD instruction performs the same operation as the RET instruction, then stores the
The RETI instruction is for the exclusive use of hardware and software interrupt service routines. When an interrupt is generated, the content of the F register is saved into the stack with the current PC value. The RETI instruction returns them.
•Software interrupt instruction (INT)
The software interrupt instruction "INT imm6" specifies a vector address within the addresses from 0111H to 013FH to execute its interrupt service routine. It can also call a hardware interrupt service routine because it can specify an address from 0100H. It performs the same operation with the call instruction, but the F register is also saved into the stack before branching. Consequently, the RETI instruction must be used for returning from interrupt service routines. See Section 3.5, "Interrupts" for details of the interrupt.
2.2.4 Table look-up instruction
The RETD instruction, one of the return instructions, has an
By using the RETD instruction combined with the "JR %BA" or "JR %A" instructions, an
Example: The following is an example of a table for converting a BCD data (0 to 9) in the A register into an ASCII code (30H to 39H). The conversion result is stored in the addresses 0040H
LD | %A,3 | ;Sets data to | be converted | ||
CALR | TOASCII | ;Calls | converting routine |
| |
LDB | %BA,[%X]+ | ;Loads | result | from memory | to BA register |
: |
|
|
|
|
|
: |
|
|
|
|
|
16 | EPSON | S1C63000 CORE CPU MANUAL |