2023 24 3b

Computer Organization and Architecture2023-247 marksProcessor organization, general registers organization, stac

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

PointRegister stackMemory stack
LocationRegisters inside the CPUA reserved area of main memory
SpeedVery fast, no memory accessSlower, each push or pop is a memory access
SizeSmall and fixed by hardwareLarge and can be changed by software
CostCostly, as registers are expensiveCheap, memory is cheap
Overflow checkFULL and EMPTY flip-flopsSP compared with limit addresses
Direction of growthUsually towards higher addressesUsually towards lower addresses
Typical useExpression evaluation in a small processorSubroutine 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.