SX Users Manual Rev. 3.1
114
© 2000 Scenix Semiconductor, Inc. All rights reserved.
www.scenix.com
Chapter 3 Instruction Set
3.6.44 RETP
Return from Subroutine Across Page Boundary
Operation:
STATUS(PA2:PA0) = top-of-stack (11:9)
program counter = top-of-stack
Bits affected:
none
Opcode:
0000 0000 1101
Description:
Like the RET instruction, the RETP instruction causes a return from a subroutine.
It pops the 12-bit value previously stored on the stack and restores that value to the
program counter. This causes the program to jump to the instruction immediately
following the call instruction that called the subroutine.
Unlike the RET instruction, the RETP instruction also writes bit 11:9 of the return
address (the address of the instruction immediately following the call instruction)
into the PA2:PA0 bits of the STATUS register. This automatically configures the
PA2:PA0 bits to select the current page, allowing a subsequent same-page jump or
call to be executed without using another page instruction.
Cycles:
2 in compatible mode (SX18/20/28AC and SX18/20/28AC75 only), or 3 in tur-
bo mode
Example:
org
$050
;start of program in page 0
...
page
$200
;set PA2:PA0 bits to 001 (different page)
call
subxy
;call subroutine in different page
...
call
addxy
;call subroutine in same page
...
addxy
;subroutine in same page as call
...
ret
...
org
$200
;new memory segment at 200h
subxy
;subroutine address label at 200h
...
retp
;return from subroutine (different page)
The first call crosses a 512-word page boundary (PA2:PA0 = 001). Upon return
from that subroutine, the PA2:PA0 bits are automatically returned to their original
values (PA2:PA0 = 00), allowing a subsequent same-page call to be done without
using the page instruction again.