// tb_seg7.sv // Checks seg7_decoder against a table written as segment letters and draws // each digit as ASCII art so you can inspect the shapes. // Run: iverilog -g2012 -o sim tb_seg7.sv seg7_decoder.sv && vvp sim module tb_seg7; logic [3:0] hex; logic [6:0] seg_n; int errors = 0; seg7_decoder dut (.hex(hex), .seg_n(seg_n)); // Lit segments for 0..F, written as letters (independent of the RTL table). string lit [16] = '{"abcdef", "bc", "abdeg", "abcdg", "bcfg", "acdfg", "acdefg", "abc", "abcdefg", "abcdfg", "abcefg", "cdefg", "adef", "bcdeg", "adefg", "aefg"}; function automatic logic [6:0] mask_of(input string s); logic [6:0] m = '0; for (int i = 0; i < s.len(); i++) m[s[i] - "a"] = 1'b1; // bit 0 = a ... bit 6 = g return m; endfunction initial begin for (int h = 0; h < 16; h++) begin logic [6:0] on; hex = 4'(h); #1; on = ~seg_n; if (on !== mask_of(lit[h])) begin $display("FAIL hex %h: seg_n = %b", hex, seg_n); errors++; end $display("%h: %s ", hex, on[0] ? "_" : " "); $display(" %s%s%s", on[5] ? "|" : " ", on[6] ? "_" : " ", on[1] ? "|" : " "); $display(" %s%s%s", on[4] ? "|" : " ", on[3] ? "_" : " ", on[2] ? "|" : " "); end if (errors == 0) $display("PASS"); else $display("FAILED with %0d errors", errors); $finish; end endmodule