SX User’s Manual Rev. 3.1 74 © 2000 Scenix Semiconductor, Inc. All rights reserved. www.scenix.com Chapter 3 Instruction Set 3.6.7 CALL addr8 Call Subroutine Operation: top-of-stack = program counter + 1 PC(7:0) = addr8 program counter (8) = 0 program counter (11:9) = PA2:PA0 Bits affected: none Opcode: 1001 kkkk kkkk Description: This instruction calls a subroutine. The full 12-bit address of the next program in-
struction is saved on the stack and the program counter is loaded with a new ad-
dress, which causes a jump to that program address.
Bits 7:0 come from the 8-bit constant value in the instruction, bit 8 is always 0, and
bits  11:9  come  from  the  PA2:PA0  bits  in  the  STATUS  register.  Therefore,  the
subroutine must start in the bottom half of a 512-word page in the program memory
(000h to 0FFh, 200h to 2FFh, etc.).
The subroutine is terminated by any one of the “return” instructions, which restores
the saved address to the program counter. Execution proceeds from the instruction
following the “call” instruction.
Cycles: 2 in “compatible” mode (SX18/20/28AC and SX18/20/28AC75 only), or 3 in “tur-
bo” mode
Example: page $600 ;set page of subroutine in STATUS reg. call addxy ;call subroutine addxy mov $0C,W ;use addxy subroutine results ... ;more of program (not shown) addxy ;subroutine address label mov W,$0E ;subroutine instructions start here add W,$0F ... ret ;return from subroutine The “call” instruction in this example calls a subroutine called “addxy.” When the
“call” instruction is executed, the address of the following instruction (the “mov
$0C,W” instruction) is pushed onto the stack and the program jumps to the “addxy”
routine. When the “ret” instruction is executed, the 12-bit program address saved
on  the  stack  is  popped  and  restored  to  the  program  counter,  which  causes  the