User Stacks - Motorola CPU32 Reference Manual

Hide thumbs Also See for CPU32:
Table of Contents

Advertisement

stack fills from high memory to low memory. The address mode –(SP) creates a new
item on the active system stack, and the address mode (SP)+ deletes an item from the
active system stack.
The program counter is saved on the active system stack on subroutine calls and is
restored from the active system stack on returns. On the other hand, both the program
counter and the status register are saved on the supervisor stack during the process-
ing of traps and interrupts. Thus, the correct execution of the supervisor state code is
not dependent on the behavior of user code, and user programs may use the USP ar-
bitrarily.
To keep data on the system stack aligned properly, data entry on the stack is restricted
so that data is always put in the stack on a word boundary. Thus, byte data is pushed
on or pulled from the system stack in the high-order half of the word; the low-order half
is unchanged.

3.7.2 User Stacks

The user can implement stacks with the address register indirect with postincrement
and predecrement addressing modes. With address register An (n = 0 to 6), the user
can implement a stack that is filled either from high to low memory or from low to high
memory. Important considerations are as follows:
• Use the predecrement mode to decrement the register before its contents are
used as the pointer to the stack.
• Use the postincrement mode to increment the register after its contents are used
as the pointer to the stack.
• Maintain the SP correctly when byte, word, and long-word items are mixed in
these stacks.
To implement stack growth from high to low memory, use –(An) to push data on the
stack, (An)+ to pull data from the stack.
For this type of stack, after either a push or a pull operation, register An points to the
top item on the stack. This scheme is illustrated as follows:
To implement stack growth from low to high memory, use (An) + to push data on the
stack, –(An) to pull data from the stack.
In this case, after either a push or pull operation, register An points to the next available
space on the stack. This scheme is illustrated as follows:
MOTOROLA
DATA ORGANIZATION AND ADDRESSING CAPABILITIES
3-16
LOW MEMORY
(FREE)
An
TOP OF STACK
BOTTOM OF STACK
HIGH MEMORY
CPU32
REFERENCE MANUAL

Advertisement

Table of Contents
loading

Table of Contents