Differentiate between Memory stack and register stack.
Differentiate between Memory stack and register stack.
Quick answer
A stack is a LIFO structure. It can be built in two ways: as a set of CPU registers (register stack), or in a portion of main memory (memory stack). In both, a stack pointer (SP) points to the top item.
Register stack
It is a small group of CPU registers, for example 64 words, organized as a stack. SP is a 6-bit register. Two flip-flops, FULL and EMPTY, signal the end conditions. The push and pop are
$$\text{PUSH: } SP \leftarrow SP + 1,\ M[SP] \leftarrow DR$$
$$\text{POP: } DR \leftarrow M[SP],\ SP \leftarrow SP - 1$$
The test for full or empty is done by checking whether SP has wrapped round to 0.
Memory stack
A part of the main memory is reserved for the stack. SP is a register holding a memory address. It usually starts at a high address and moves down as items are pushed. The push and pop are
$$\text{PUSH: } SP \leftarrow SP - 1,\ M[SP] \leftarrow DR$$
$$\text{POP: } DR \leftarrow M[SP],\ SP \leftarrow SP + 1$$
To find overflow and underflow, SP is compared with the upper and lower limit addresses of the stack area.
Differences
| Point | Register stack | Memory stack |
|---|---|---|
| Location | Registers inside the CPU | A reserved area of main memory |
| Speed | Very fast, no memory access | Slower, each push or pop is a memory access |
| Size | Small and fixed by hardware | Large and can be changed by software |
| Cost | Costly, as registers are expensive | Cheap, memory is cheap |
| Overflow check | FULL and EMPTY flip-flops | SP compared with limit addresses |
| Direction of growth | Usually towards higher addresses | Usually towards lower addresses |
| Typical use | Expression evaluation in a small processor | Subroutine calls, interrupts, local data |
Because main memory is cheap and big, general purpose computers use the memory stack. A register stack is used only where speed matters and a very small stack is enough, for example in a small embedded processor or for a stack of intermediate results.
Short on time? The 1, 5 and 10 mark versions of this answer, flashcards and practice sets come with a program pass.
Up nextExplain in detail the principle of carry look ahead adder and design 4-bit CLA adder.