Saturday, January 28, 2023

 

2I/P- 5BIT WIDE SUBTRACTOR 

module sub_5b (bor,diff,A,B);
input [4:0] A,B;
output [4:0]diff;
output bor;
wire[4:0]b1,b2;

not n1 (b1[0],B[0]);//(1scomp)
not n2 (b1[1],B[1]);//(1scomp)
not n3 (b1[2],B[2]);//(1scomp)
not n4 (b1[3],B[3]);//(1scomp)
not n5 (b1[4],B[4]);//(1scomp)

add2_5b ad1 (unused,b2,5'b00001,b1);  //(1scomp+1)

add2_5b ad2 (bor,diff,A,b2); //((2scomp of B) + A)
endmodule 


logic:- 1st do 1s comp and perform 2s comp for B and add with A. 
sub modules :- 5 i/p adder module

TEST BENCH:-

module sub2_5b_tb();
reg [4:0]A,B;
wire [4:0]diff;
wire bor;
sub_5b dut (bor,diff,A,B);
initial
begin
repeat(20)
begin
A=$random;
B=$urandom_range(A,0);
#1;
$display({A}," ",{B},":",{diff});
end
end
endmodule









No comments:

Post a Comment

VERILOG CODES :-

 VERILOG CODES :- (by NUTAN.K) COMBINATIONAL :-  1.MUX:- (one bit wide)  1a) 2:1 MUX and its Testbench   1b) 4:1 MUX using 2:1 and its testb...