In: Electrical Engineering
Design a 4-bit multiplier by using 4 bit full adder and write a verilog code.
Answer)
Verilog Code for the 4 bit multiplier using 4 bit Full adder is shown below:-
module fulladder (
input a,
input b,
input cin,
output sum,
output cout
);
assign sum = a ^ b ^ cin;
assign cout = (a & b) | (b & cin) | (a & cin);
endmodule
module fulladder_4bit (
input [3:0] A,
input [3:0] B,
input Cin,
output [3:0] S,
output Cout
);
wire w1, w2, w3, w4;
fulladder m0 (.a(A[0]), .b(B[0]), .cin(Cin), .sum(S[0]),
.cout(w1));
fulladder m1 (.a(A[1]), .b(B[1]), .cin(w1), .sum(S[1]),
.cout(w2));
fulladder m2 (.a(A[2]), .b(B[2]), .cin(w2), .sum(S[2]),
.cout(w3));
fulladder m3 (.a(A[3]), .b(B[3]), .cin(w3), .sum(S[3]),
.cout(w4));
assign Cout = w4;
endmodule
module multiplier_4x4 (A, B, P);
input [3:0] A;
input [3:0] B;
output [7:0] P;
wire [3:0] AB0, AB1, AB2, AB3;
wire [3:0] w1, w2, w3;
wire c1, c2, c3;
assign AB0 = {4{B[0]}} & A;
assign AB1 = {4{B[1]}} & A;
assign AB2 = {4{B[2]}} & A;
assign AB3 = {4{B[3]}} & A;
fulladder_4bit DUT1 (.A(AB1), .B({1'b0, AB0[3:1]}), .Cin(1'b0),
.S(w1), .Cout(c1));
fulladder_4bit DUT2 (.A(AB2), .B({c1, w1[3:1]}), .Cin(1'b0),
.S(w2), .Cout(c2));
fulladder_4bit DUT3 (.A(AB3), .B({c2, w2[3:1]}), .Cin(1'b0),
.S(w3), .Cout(c3));
assign P[0] = AB0[0];
assign P[1] = w1[0];
assign P[2] = w2[0];
assign P[6:3] = w3;
assign P[7] = c3;
endmodule