Codiode

The Default Assignment Trick

EasyVerilog / SystemVerilogBuildFree2 solved

An output decoder with many signals and many branches will leave something unassigned somewhere, and that becomes a latch. Assigning every output a default value at the top of the always_comb block rules this out with one line per signal.

The solution module is a memory controller command decoder. It evaluates a 3-bit state and a 2-bit opcode to drive four combinational control signals: mem_read, mem_write, addr_update, and ready.

By default, all control signals must be 0. The outputs change from their default values only under the following specific conditions:

  • During the IDLE state (3'b000) and the HALT state (3'b100), the ready signal is asserted to 1.
  • During the FETCH state (3'b001), both mem_read and addr_update are asserted to 1.
  • During the EXECUTE state (3'b010), mem_write is asserted to 1 if the opcode is 2'b10.
  • During the EXECUTE state (3'b010), mem_read is asserted to 1 if the opcode is 2'b01.

All other unmapped states and opcode combinations must output the default values.

Signal Direction Width Description
state input 3 Current state of the controller
opcode input 2 Instruction opcode
mem_read output 1 Memory read enable
mem_write output 1 Memory write enable
addr_update output 1 Address register update enable
ready output 1 Controller ready flag

Constraints

  • The design must be purely combinational.
  • No latches may be inferred.
  • All unmapped states and opcodes must safely default to all zeros.
  • Do not use sequential logic (always @(posedge clk)); use always_comb or always @(*).

Topics

combinationalsynthesislatch-prevention

Solve this problem

Write the module in Verilog, SystemVerilog or VHDL. Your submission is compiled and simulated against the problem's testbench. You get the waveform back, not a stored answer.

Free to solve. A Codiode account keeps your progress.

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 FSM Coding

Problem 2 of 15 in the FSM Coding track.

Related problems

Browse all problems · Verilog practice problems · Learning tracks

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