// tb_signed.sv // Shows how mixing signed and unsigned operands changes a comparison. // Run: iverilog -g2012 -o sim tb_signed.sv && vvp sim module tb_signed; logic signed [7:0] a = -8'sd5; // bit pattern 8'hFB logic [7:0] b = 8'd2; // unsigned logic signed [7:0] c = 8'sd2; // signed int errors = 0; initial begin // One unsigned operand makes the whole comparison unsigned: 251 < 2. if (a < b) begin $display("FAIL: a < b was true"); errors++; end else $display("a < b is false (compared as 251 < 2)"); // Both operands signed: -5 < 2. if (!(a < c)) begin $display("FAIL: a < c was false"); errors++; end else $display("a < c is true (compared as -5 < 2)"); // Casting b to signed restores the intended comparison. if (!(a < $signed(b))) begin $display("FAIL: a < $signed(b) was false"); errors++; end else $display("a < $signed(b) is true"); if (errors == 0) $display("PASS"); $finish; end endmodule