CodiodeCodiode
Home
Problem Solving
Skill Tracks
My Assignments
Contests
Leaderboard
Community
Settings
Codiode/Problems/Sequential Logic

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.

Sign in to solveSee what Pro unlocks

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.

Related problems

  • 3-bit Ripple Counter from Toggle Flip-FlopsEasy
  • D Latch from a 2:1 MUXEasy
  • 2-bit Ring CounterEasy
  • T Flip-Flop from a D Flip-FlopEasy
  • Handshake Deadlock Due to Early ResetHard
  • Reconvergence of Individually Synchronized BitsHard
  • Debug: Asynchronous Clear GlitchHard
  • Clock Gate Enable Crossing DomainsHard

Browse all problems · Learning tracks