English
Language : 

C161RI_1 Datasheet, PDF (285/317 Pages) Siemens Semiconductor Group – 16-Bit CMOS Single-Chip Microcontroller
System Programming
C161RI
Passing Parameters on the System Stack
Parameters may be passed via the system stack through PUSH instructions before the subroutine
is called, and POP instructions during execution of the subroutine. Base plus offset indirect
addressing also permits access to parameters without popping these parameters from the stack
during execution of the subroutine. Indirect addressing provides a mechanism of accessing data
referenced by data pointers, which are passed to the subroutine.
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.
Cross Segment Subroutine Calls
Calls to subroutines in different segments require the use of the CALLS (call inter-segment
subroutine) instruction. This instruction preserves both the CSP (code segment pointer) and IP on
the system stack.
Upon 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.
Note: It is possible to use CALLS within the same segment, but still two words of the stack are
used to store both the IP and CSP.
Providing Local Registers for Subroutines
For subroutines which require local storage, the following methods are provided:
Alternate Bank of Registers: Upon entry into a subroutine, it is possible to specify a new set of
local registers by executing the SCXT (switch context) instruction. This mechanism does not
provide a method to recursively call a subroutine.
Saving and Restoring of Registers: To provide local registers, the contents of the registers which
are required for use by the subroutine can be pushed onto the stack and the previous values be
popped before returning to the calling routine. This is the most common technique used today and
it does provide a mechanism to support recursive procedures. This method, however, requires two
machine cycles per register stored on the system stack (one cycle to PUSH the register, and one to
POP the register).
Use of the System Stack for Local Registers: It is possible to use the SP and CP to set up local
subroutine register frames. This enables subroutines to dynamically allocate local variables as
needed within two machine cycles. A local frame is allocated by simply subtracting the number of
required local registers from the SP, and then moving the value of the new SP to the CP.
Semiconductor Group
20-9
1998-05-01