Skip to main content

Short note: stack memory

Short answer

Stack memory is a LIFO RAM area addressed by the stack pointer (SP) that grows downward. PUSH decrements SP twice and stores a register pair; POP does the reverse. It handles CALL/RET, interrupts, and temporary register saving.

Write a short note on stack memory.

A stack is a block of read/write memory used as a last-in first-out (LIFO) store: the last item pushed is the first one popped. In the 8085 the stack lies in RAM and is addressed by the 16-bit stack pointer (SP), which always holds the address of the top of stack.

Operation

  • The programmer loads SP at the start, e.g. LXI SP,0FFFFH.
  • The stack grows downward (towards lower addresses).
  • PUSH rp: SP ← SP−1, store high byte of the register pair; SP ← SP−1, store low byte.
  • POP rp: low byte ← [SP], SP ← SP+1; high byte ← [SP], SP ← SP+1.
 PUSH B  (B=12H, C=34H, SP=FFFFH)
 Address   Before   After
 FFFEH      --       12H   (B)
 FFFDH      --       34H   (C)  <- SP = FFFDH

Uses

  1. Saving register contents temporarily (PUSH/POP) when a subroutine needs the registers.
  2. CALL saves the return address on the stack; RET pops it into the PC.
  3. Interrupts and RST instructions store the PC on the stack automatically.
  4. Passing parameters to subroutines.

Points to remember: PUSH and POP work on register pairs (B, D, H, PSW) only; PUSH/POP must be balanced, and the stack must not overlap program or data area. Nested subroutines are possible because the stack stores return addresses in order. Stack depth is limited only by available memory.

✓ Answer checked by Claude Opus 5.5 (high effort)

All Microprocessor chapter 2 questions →