CBL_SignMagToTwosComp : A combinational logic converting a sign-magnitude to a two’s complement representation
This model describes a combinational logic converting a sign-magnitude to a two’s complement representation. For an N-bit binary number in[N-1:0]
, the sign-magnitude representation uses the MSB in[N-1]
as the sign bit and the rest in[N-2:0]
as the magnitude.
module CBL_SignMagToTwosComp #( parameter width = 4 // bit width )( input [width-1:0] in, // input bits output [width-1:0] out // output bits ); assign out = (in[width-1]) ? ~{1'b0, in[width-2:0]} + 1 : in; endmodule
Input/Output Terminals
Name | I/O | Type | Description |
in [width-1:0] | input | wire | input bits |
out [width-1:0] | output | wire | output bits |
Parameters
Name | Type | Default | Description |
width | integer | 4 | bit width |
List of Testbenches
tb_check : A testbench for checking the basic functionality of a combinational logic |
tb_check : A testbench for checking the basic functionality of a combinational logic
This testbench checks the basic functionality of a combinational logic by enumerating all the possible input values and listing the corresponding outputs of the combinational logic.
module tb_check (); parameter in_width = 4; parameter out_width = in_width; reg [in_width-1:0] in; wire [out_width-1:0] out; CBL_SignMagToTwosComp #(.width(in_width)) DUT (.in, .out); initial begin in = 0; repeat ((1 << in_width) - 1) begin #(1ns); in = in + 1; end end always @(out) begin $display("IN: %b --> OUT: %b", in, out); end endmodule