Codiode

Simultaneous Push and Pop Resolution

HardLogic CircuitBuild

Pipelined processors often encounter structural hazards when a return instruction and a new function call attempt to access the call stack in the same clock cycle. To prevent pipeline stalls, the stack controller must resolve simultaneous push and pop operations gracefully without corrupting the stack pointer.

Design the pointer and write-enable logic for a synchronous stack controller. The circuit maintains a 4-bit stack pointer ptr that tracks the current top of the stack. When a simultaneous push and pop occurs, the pointer must not change, but the new push_data must immediately overwrite the data being popped at the current pointer address.

push pop ptr (next cycle) we waddr wdata
0 0 ptr 0 0 0
1 0 ptr + 1 1 ptr + 1 push_data
0 1 ptr - 1 0 0 0
1 1 ptr 1 ptr push_data

Constraints

  • Implement ptr as a 4-bit register initialized to 0 on a synchronous active-high rst.
  • Output 0 for both 4-bit waddr and 8-bit wdata whenever we is 0.
  • Generate control signals for an external RAM rather than instantiating internal memory blocks.

Topics

DatapathRegistersControl Logic

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 13 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.