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

Pre-Defaulting Strategy

HardVerilog / SystemVerilogBuild

Complex control logic blocks often require decoding multiple fields of an instruction or transaction to drive numerous downstream signals. When relying on deeply nested conditional statements, missing an assignment in just one branch causes synthesis tools to infer unwanted transparent latches. Setting default values at the top of a combinational block is the industry standard practice to guarantee pure combinational logic while keeping code concise and readable.

The operation_decoder module evaluates an incoming transaction and configures the datapath. It receives a valid signal, an override flag, a 2-bit mode, and a 4-bit opcode. It drives five outputs: alu_en, mem_en, write_en, error_flag, and a 3-bit next_state.

By default, or if valid is 0, all outputs must be 0. If valid is 1, the decoder follows these rules: If override is 1, error_flag becomes 1 and next_state becomes 3'b111. All other outputs remain 0. If override is 0, behavior depends on the mode: • mode 2'b00 (ALU): alu_en becomes 1. next_state takes the value of {1'b0, opcode[1:0]} + 3'b001. If the upper two bits of opcode (opcode[3:2]) are not 2'b00, error_flag becomes 1. • mode 2'b01 (MEM): mem_en becomes 1. If opcode[3] is 1, write_en becomes 1 and next_state is 3'b101. If opcode[3] is 0, write_en remains 0 and next_state is 3'b110. • mode 2'b10 or 2'b11 (Reserved): error_flag becomes 1 and next_state is 3'b000.

| Signal | Direction | Width | Description | |--------------|-----------|-------|-------------| | valid | input | 1 | Transaction valid flag | | override | input | 1 | High priority override flag | | mode | input | 2 | Operation mode (00=ALU, 01=MEM, 10/11=Reserved) | | opcode | input | 4 | Operation specific code | | alu_en | output | 1 | ALU enable flag | | mem_en | output | 1 | Memory enable flag | | write_en | output | 1 | Memory write enable flag | | error_flag | output | 1 | Error detected flag | | next_state | output | 3 | Next state vector |

Constraints

  • The design must be purely combinational.
  • No latches may be inferred by the synthesis tool.
  • All outputs must default to 0 when unassigned by a specific rule.
  • The override signal takes priority over all mode decoding when valid is 1.

Topics

CombinationalDecoderBest Practices

Solve this problem

Write the module in Verilog, SystemVerilog or VHDL. Your submission is compiled and simulated against a real testbench — you get the waveform back, not a stored answer.

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

  • Single Continuous AssignmentEasy
  • Basic Vector ConcatenationEasy
  • Ternary Operator MuxEasy
  • Underscores for ReadabilityEasy
  • Left Hand Side ConcatenationEasy
  • Inout Port MechanicsEasy
  • Explicit Binary LiteralsEasy
  • Vector Port EndiannessEasy

Browse all problems · Learning tracks