SAF-C164SM Infineon Technologies, SAF-C164SM Datasheet - Page 431

no-image

SAF-C164SM

Manufacturer Part Number
SAF-C164SM
Description
16-Bit CMOS Microcontroller
Manufacturer
Infineon Technologies
Datasheet
C164CM/C164SM
Derivatives
System Programming
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 the 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 two words of the stack
are still used to store both the IP and CSP.
Providing Local Registers for Subroutines
The following methods are provided for subroutines which require local storage:
• Alternate Banks of Registers
• Saving and Restoring Registers
• Use of the System Stack for Local Registers
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 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 can 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 cycle 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.
This operation is supported through the SCXT (switch context) instruction with the
addressing mode ‘reg, mem’. Using this instruction saves the old contents of the CP on
the system stack and moves the value of the SP into CP (see the example below). Each
local register is then accessed as if it were a normal register. Upon exit from the
subroutine, first the old CP must be restored by popping it from the stack and then the
number of used local registers must be added to the SP to restore the allocated local
space back to the system stack.
Note: The system stack grows downward, while the register bank grows upward.
User’s Manual
22-10
V1.0, 2002-02

Related parts for SAF-C164SM