Page 173 - DCAP210_INTRODUCTION__TO_MICROPROCESSORS
P. 173
Unit 12: The Stacks
12.1 Stack Notes
The stack is an area of memory identified by the programmer for temporary storage of information.
The stack is a LIFO structure (Last In First Out). The stack normally grows backwards into memory.
In other words, the programmer defines the bottom of the stack and the stack grows up into
reducing address range.
Given that the stack grows backwards into memory, it is customary to place the bottom of
the stack at the end of memory to keep it as far away from user programs as possible.
In the 8085, the stack is defined by setting the SP (Stack Pointer) register.
LXI SP, FFFFH
This sets the Stack Pointer to location FFFFH (end of memory for the 8085). The Size of the stack
is limited only by the available memory
The stack was first proposed in 1955, and then patented in 1957, by the German
Friedrich L. Bauer. The same concept was developed independently, at around
the same time, by the Australian Charles Leonard Hamblin.
12.1.1 Stack in main memory
Most CPUs have registers that can be used as stack pointers. Processor families like the x86, Z80,
6502, and many others have special instructions that implicitly use a dedicated (hardware) stack
pointer to conserve opcode space. Some processors, like the PDP-11 and the 68000, also have
special addressing modes for implementation of stacks, typically with a semi-dedicated stack
pointer as well (such as A7 in the 68000). However, in most processors, several different registers
may be used as additional stack pointers as needed (whether updated via addressing modes or
via add/sub instructions).
12.1.2 Stack in registers or dedicated memory
The x87 floating point architecture is an example of a set of registers organized as a stack where
direct access to individual registers (relative the current top) is also possible. As with stack-based
machines in general, having the top-of-stack as an implicit argument allows for a small machine
code footprint with a good usage of bus bandwidth and code caches, but it also prevents some
types of optimizations possible on processors permitting random access to the register file for all
(two or three) operands. A stack structure also makes superscalar implementations with register
renaming (for speculative execution) somewhat more complex to implement, although it is still
feasible, as exemplified by modern x87 implementations.
Sun SPARC, AMD Am29000, and Intel i960 are all examples of architectures using register
windows within a register-stack as another strategy to avoid the use of slow main memory for
function arguments and return values.
LOVELY PROFESSIONAL UNIVERSITY 167