ST10R272L - SYSTEM PROGRAMMING
309/320
bank pointer is then assigned. Therefore, on entry into a new task, the appropriate bank
pointer is used as the operand for the SCXT (switch context) instruction. On exit from a task,
a simple POP instruction to the context pointer (CP) restores the previous task’s register
bank.
18.5
CALL procedure entry-and-exit
To support modular programming, a procedure mechanism is provided for coding of
frequently used portions of code into subroutines. The CALL and RET instructions store and
restore the value of the instruction pointer (IP) on the system stack, before and after a
subroutine is executed.
Note
Procedures may be called conditionally with instructions CALLA or CALLI, or be
called unconditionally using instructions CALLR or CALLS.
Any data pushed onto the system stack during execution of the subroutine, must be popped
before the RET instruction is executed.
18.5.1 Passing parameters on the system stack
Parameters may be passed through the system stack by PUSH instructions (before the
subroutine is called) and POP instructions (during execution of the subroutine).
Base-plus-offset indirect addressing, permits access to parameters without popping the
parameters from the stack during subroutine execution. Indirect addressing provides a
mechanism to access data referenced by data pointers.
In addition, two instructions have been implemented to allow one parameter to be passed on
the system stack without additional software overhead.
•
The PCALL (push and call) instruction first pushes the ’reg’ operand and the IP contents
onto the system stack and then passes control to the subroutine specified by the ’caddr’
operand.
•
When exiting from the subroutine, the RETP (return and pop) instruction first pops the IP
and then the ’reg’ operand from the system stack and returns to the calling program.
18.5.2 Cross segment subroutine calls
Calls to subroutines in different segments require the CALLS instruction (call inter-segment
subroutine). This instruction preserves both the CSP (code segment pointer) and IP on the
system stack.
On return from the subroutine, a RETS (return from inter-segment subroutine) instruction
must be used to restore both the CSP and IP. This ensures that the next instruction after the
CALLS instruction is fetched from the correct segment.