SystemVerilog #63 · 2026-11-25 · Non-blocking assignments in a loop · Easy · about 15 min
Sum the lanes of a word, every clock
Write lane_sum in lane_sum.sv: a clocked module that adds up the byte lanes of a word. word has N lanes of 8 bits (N is a parameter, default 4), and lane i is word[i]. Use unsigned arithmetic.
- On a rising edge with
vld= 1,wsumbecomes the sum of allNlanes ofword(a value from 0 toN * 255), andtotalbecomes the oldtotalplus that same sum, modulo 2^16. - On an edge with
vld= 0, both outputs hold. rst_nis a synchronous active-low reset: both outputs go to 0.
Both outputs are 16-bit registers, so they show the result of the previous edge.
Example (N = 4): after reset, a word 32'h01_02_03_04 accepted on one edge gives wsum = 10, total = 10. A second accepted word 32'h10_00_00_01 gives wsum = 17, total = 27. A word on the bus with vld = 0 changes nothing.
Fill in lane_sum.sv. Run accepts one word with a single non-zero lane, then a word with vld = 0.
Write and run your answer in the browser. The hidden tests check it, and it’s free.