Codiode

Stack Pointer Up Down Control

MediumLogic CircuitBuild

Memory-based stacks require precise pointer arithmetic to track the top of the stack dynamically. Off-by-one errors in pointer management cause complete system crashes.

The stack pointer sp tracks the next empty location in memory. This requires a post-increment operation for pushes and a pre-decrement operation for pops. The combinational output addr provides the correct memory address for the current operation, while the 4-bit register sp updates on the next rising clock edge.

rst push pop addr (Current Cycle) sp (Next Cycle)
1 X X 0 0
0 0 0 sp sp
0 1 0 sp sp + 1
0 0 1 sp - 1 sp - 1
0 1 1 sp - 1 sp

Constraints

  • Implement synchronous active-high reset logic.
  • The sp and addr outputs must be exactly 4 bits wide.
  • Use 4-bit wrap-around arithmetic for pointer updates. No overflow or underflow flags are required.

Topics

DatapathRegistersPointer Arithmetic

Solve this problem

Place the gates, wire them up and watch the signals settle. Every submission runs on the same simulation engine that grades it.

This problem is part of Codiode Pro. The statement above is free to read.

The circuit builder and code editor need a desktop screen. On a phone, read the problem here and open it on a laptop to solve.

Part of Datapath and Storage

Problem 11 of 29 in the Datapath and Storage track.

Related problems

Browse all problems · Digital logic design practice problems · Learning tracks

Solve this on a laptopSend yourself the link and continue there.