Verilog RTL I – Combinational
Combinational, arithmetic, sequential, counters, timers
What you will learn and practise
Complete the stages in order and retain the requested evidence.
always blocks and blocking assignment
if/else, case/casez/casex
Complete assignments and latch avoidance
Combinational coding guidelines
1. 2:1 MUX with assign
2. 2:1 MUX with if
3. 2:1 MUX with case
4. 4:1/8:1 MUX
5. Decoder/DEMUX
6. Encoder/priority encoder
7. Binary↔one-hot
8. Min/max selector
9. Leading-one/zero detector
10. Population counter
11. Parameterized MUX
Debug missing default, incomplete assignment, bad slicing
Explain why each faulty block infers wrong hardware
Combinational RTL library
Implement complete combinational RTL with assign, if/else and case while preventing unintended latches.
- Create project_workspace/week2_verilog_rtl1/day7.
- Reuse the Day 6 simulation flow.
- Enable compiler/lint warnings and retain the log.
- Implement 2:1 MUX using assign, if/else and case.
- Implement 4:1 and 8:1 MUX blocks.
- Implement decoder and demultiplexer.
- Implement encoder and priority encoder.
- Implement binary-to-one-hot and one-hot-to-binary conversion.
- Implement min/max selector, leading-one/zero detector and population counter.
- Create a parameterized MUX and verify representative select/input combinations.
- Compare continuous assignment with a combinational always block.
- Why are blocking assignments normally used in combinational procedural RTL?
- Explain how an incomplete if/case assignment can infer a latch.
- State the purpose of a default case and when it is required for clear intent.
- Explain priority behavior in a priority encoder and how it differs from an ordinary encoder.
Correct missing defaults, incomplete output assignments and bad vector slicing in faulty combinational blocks; state what hardware the faulty version could infer.
- combinational RTL library
- testbench/results
- warning-clean compile log
- debug-before/after notes
- written answers
- No unintended latch behavior
- Outputs are assigned for all intended input conditions
- Parameterized MUX verifies correctly
- Debug explanation connects source defect to hardware behavior
Build, run and retain evidence
project_workspace/week2_verilog_rtl1/day7_combinational/
rtl/mux2_assign.vrtl/mux2_if.vrtl/mux2_case.vrtl/mux_n.vrtl/decoder.vrtl/demux.vrtl/priority_encoder.vrtl/onehot.vrtl/popcount.vtb/tb_day7.v
- Every MUX select value
- Decoder/DEMUX legal selections
- Priority encoder multiple-active-input cases
- Binary/one-hot conversion cases
- Population count 0, all-ones and mixed patterns
- Parameterized MUX at two configurations
iverilog -g2012 -Wall -o sim/day7.vvp rtl/*.v tb/tb_day7.vRunvvp sim/day7.vvp | tee logs/day7.logWaveformgtkwave sim/day7.vcd- All combinational checks PASS
- No unintended latch behavior in reviewed RTL
- No compile errors
- Log and VCD retained
Review before completing Day 7
- MCQ
What coding defect commonly causes unintended latch inference?
Review answer
An output is not assigned on every combinational path.
- Code reading
In an always @(*) MUX, why are blocking assignments normally used?
Review answer
They model ordered combinational calculation without clocked-state semantics.
- Debug
A case statement assigns y in three branches but not the fourth and has no default. What is the risk?
Review answer
y may retain its old value, implying a latch.
- Short answer
Differentiate an ordinary encoder from a priority encoder.
Review answer
A priority encoder defines which asserted input wins when multiple inputs are active.
Combinational RTL
- always combinational
- if/case
- complete assignment
- MUX/decoder/encoder
- latch avoidance
Assessment: Q2