Here is a tiny bit of code that I would expect to produce two 126s. This is because -3 is 253 as an 8-bit unsigned number, then 253/2 = 126.5, and division rounds toward zero. The reason I expect both divisions to be unsigned is that they are "context-determined" in standard speak (as opposed to "self-determined"), with the context being unsigned. Many thanks.
module trivial; reg we; reg [7:0] c; initial begin c = 8'd3; we = 1'b1; $display ("res(we) = %d", (we ? (-$signed(c)) / 8'sd2 : 8'd1)); $display ("res(1) = %d", (1'b1 ? (-$signed(c)) / 8'sd2 : 8'd1)); end endmodule $ iverilog icarus.v && vvp.exe a.out res(we) = 126 res(1) = -1
Log in to post a comment.