22
µ
PD17062
2.5 SUBROUTINE
If a subroutine is executed, the specialized subroutine call instruction (CALL) and subroutine return
instruction (RET, RETSK) are used.
Fig. 2-3 illustrates the operation of subroutine call.
Subroutine call instructions are divided into two types. The direct subroutine call instruction (CALL addr)
calls the program memory address (addr) specified in its operand. The indirect subroutine call instruction
(CALL @AR) calls the program memory address specified in an address register.
The RET or RETSK instruction is used to return control from a subroutine. The RET or RETSK instruction
returns control to a program memory address next to the address at which the subroutine call instruction
(CALL) was executed. Upon execution of the RETSK instruction, the first instruction after the return is executed
as a no-operation instruction (NOP).
See also Chapter 3.
2.5.1 Direct Subroutine Call
The direct subroutine call instruction uses 11 bits of its operand to specify the program memory address
to be called. If the direct subroutine call instruction is used, the destination, or the first address of the
subroutine to be called, must be page 0 (addresses 0000H to 07FFH). The instruction cannot call a subroutine
whose first address is in page 1 (addresses 0800H to 0F7FH).
The subroutine return instruction (RET, RETSK) can be in page 1. The CALL instruction can be in page 0
or page 1.
Examples 1. When the subroutine return instruction is in page 0
When the first address of the subroutine is in page 0, as shown in Fig. 2-4, the return address
and return instruction can be in page 0 or page 1. When only the first address of the subroutine
is in page 0, the CALL instruction can be used in either page. If the first address of the
subroutine cannot be placed in page 0 because of programming restrictions, the method
shown in example 2 can be used.
2. When the first address of the subroutine is in page 1
The branch instruction (BR) is placed in page 0, as shown in Fig. 2-4, and the desired
subroutine (SUB1) is called via the BR instruction.
2.5.2 Indirect Subroutine Call
The indirect subroutine call instruction (CALL @AR) uses the 8-bit data in an address register (AR) to specify
the address of a subroutine to be called. The instruction can call a subroutine from a program memory address
between 0000H and 00FFH.
See Section 8.1.