CBL_TwosComp : A combinational logic computing the two’s complement of a binary input
This model describes a combinational logic computing the two’s complement of an N-bit binary input by inverting its individual bits and adding 1.
module CBL_TwosComp #( parameter width = 4 // bit width )( input [width-1:0] in, // input bits output [width-1:0] out // output bits ); assign out = ~in + 1; 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 its corresponding outputs.
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_TwosComp #(.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