Altera_Forum
Honored Contributor
9 years agoUnsigned to signed conversion and its simulation in Modelsim
Hello dear friends,
I am having an unsigned number of the input and need to sign extend it and negate (2s representation) if in the specific condition occurs (say if sign=1, to simplify) Here is my code in SystemVerilog: module signed_unsigned ( sign, clk, data_in, data_out); input logic sign; input logic clk; input unsigned [7:0] data_in; output signed [8:0] data_out; always_ff @ (posedge clk) begin if (sign) data_out <= -data_in; else data_out <= data_in; end endmodule It looks like it analyzed properly in Quartus (see RTL representation in the attachment). However, when I simulate in Modelsim it doesn't show the correct result. In the testbench I have a clock generator and just assignments to the data_in. I expect to see 101 value for 0xFF, 156 for 0xAA, etc but nothing happens. the numbers are same What can be wrong? I am very confused. Cheers,