Week 2 · Day 6 · 7 hours

Verilog RTL I – Fundamentals

Combinational, arithmetic, sequential, counters, timers

Daily plan

What you will learn and practise

Complete the stages in order and retain the requested evidence.

Theory · 2h

Verilog module/ports/nets/variables
Operators and continuous assignment
Parameters; hierarchy and instantiation
Compilation and basic simulation flow

Guided lab · 2h

1. AND/OR/XOR/XNOR
2. NAND/NOR
3. Multi-gate module
4. Half adder
5. Full adder
6. Full adder using half adders

Independent lab · 2h

7. Half/full subtractor
8. 4-bit ripple adder
9. Parameterized N-bit adder
10. Comparator
11. Parity generator/checker

Debug and assignment · 1h

Fix syntax, width, port and undeclared-signal bugs
Write one parameterized arithmetic block

Expected deliverable

Working RTL + basic TB for arithmetic blocks

Practical work

Build and simulate synthesizable Verilog fundamentals using correct modules, ports, signals, operators, hierarchy and parameters.

Setup
  1. Create project_workspace/week2_verilog_rtl1/day6 with rtl, tb, sim and logs directories.
  2. Use Icarus Verilog for compile/simulation and GTKWave for waveform inspection.
  3. Keep one compile/run log for the final evidence.
Execution steps
  1. Implement AND, OR, XOR, XNOR, NAND and NOR modules.
  2. Implement half adder and full adder, then build a full adder hierarchically from half adders.
  3. Implement half/full subtractor and a 4-bit ripple-carry adder.
  4. Convert the adder into a parameterized N-bit module.
  5. Implement comparator and parity generator/checker blocks.
  6. Write a basic testbench that exercises nominal and boundary input combinations.
Written assignment
  1. Explain the difference between a net and a procedural variable in Verilog.
  2. Explain continuous assignment and when assign is appropriate.
  3. Explain why explicit vector widths matter in arithmetic RTL.
  4. Describe parameter elaboration and one benefit of parameterized RTL.
  5. Draw the hierarchy of a full adder built from two half adders and identify all interconnect signals.
Debug challenge

Repair instructor-provided syntax, port-map, undeclared-signal and width-mismatch defects, then explain each correction.

Evidence to retain
  • RTL source files
  • basic testbench
  • compile/simulation log
  • waveform or terminal result
  • written answers
Completion criteria
  • All required modules compile without errors
  • Testbench demonstrates correct arithmetic behavior
  • Parameterized block works for at least two widths
  • Learner can explain module/port/net/parameter choices
Executable lab

Build, run and retain evidence

project_workspace/week2_verilog_rtl1/day6_fundamentals/

Required files
  • rtl/gates.v
  • rtl/half_adder.v
  • rtl/full_adder.v
  • rtl/ripple_adder.v
  • rtl/adder_n.v
  • rtl/comparator.v
  • rtl/parity.v
  • tb/tb_day6.v
Mandatory tests
  • All basic gate truth-table combinations
  • Half/full adder carry cases
  • 4-bit ripple adder 0+0, 1+1, 15+1 and representative vectors
  • Parameterized adder at two widths
  • Comparator equal/less/greater cases
  • Parity even/odd cases
Compile
iverilog -g2012 -Wall -o sim/day6.vvp rtl/*.v tb/tb_day6.v
Run
vvp sim/day6.vvp | tee logs/day6.log
Waveform
gtkwave sim/day6.vcd
PASS criteria
  • Testbench terminates with PASS
  • No $fatal/$error
  • Compile has no errors
  • Required VCD and log exist
Knowledge check

Review before completing Day 6

  1. MCQ

    Which Verilog object represents a continuously driven connection?

    Review answer

    wire

  2. Code reading

    For output [W:0] sum = {1'b0,a}+{1'b0,b}, explain why the output is W+1 bits.

    Review answer

    The extra bit preserves carry-out.

  3. Debug

    A 4-bit adder declares a 4-bit result but must preserve carry. Identify the defect.

    Review answer

    The result width is insufficient; use W+1 bits or a separate carry.

  4. Short answer

    Why is named port mapping safer for larger hierarchical RTL?

    Review answer

    It makes signal-to-port intent explicit and reduces ordering mistakes.

Skills and assessment traceability

Fundamentals

  • modules/ports
  • nets/variables
  • operators/assign
  • parameters/hierarchy
  • basic simulation

Assessment: Q1