Create a full adder using the specified limits shown below. Must be done in mode
ID: 2250132 • Letter: C
Question
Create a full adder using the specified limits shown below. Must be done in modelsim
ALU_OP 1:0 [2:0] [5:0] Dout Cout 12:0] Fig. : 4-bit ALU. The design of ALU must has two 3-bits data input and 2-bits control signals, determining the type of operation. The output of the ALU is 6-bits signal, which depends on the control signals, and a carry out signal. For instance, a multiplication of two 3-bits unsigned signals results in a 6-bits output but an addition of two 3-bit signals leads to a 3-bits output with a -bit carry out. In this project, you areExplanation / Answer
/////////////// DESIGN FILE /////////////////////
module ALU_design (
input [2:0] A, B,
input [1:0] ALU_OP,
output reg [5:0] Dout,
output reg Cout
);
always @ (*)
begin
case(ALU_OP)
2'b00 : {Cout, Dout} = A * B ; // Multiplication of A and B
2'b01 : {Dout[5:3],Cout,Dout[2:0]} = A + B ; // Addition of A and B
2'b10 : {Dout[5:3],Cout,Dout[2:0]} = A - B ; // Subtract B from A
2'b11 : {Dout[5:3],Cout,Dout[2:0]} = B - A ; // Subtract A from B
endcase
end
endmodule
/////////////// TESTBENCH FILE /////////////////////
module top;
reg [2:0] A, B;
reg [1:0] ALU_OP;
wire [5:0] Dout;
wire Cout;
integer i;
// instantiation of the module
ALU_design c1 (.A(A), .B(B), .ALU_OP(ALU_OP), .Dout(Dout), .Cout(Cout));
initial begin
$monitor("A = %d B = %d ALU_OP = %d Dout = %d Cout = %d", A, B, ALU_OP, Dout, Cout);
A = 3'd7;
B = 3'd7;
for (i = 0; i < 3 ; i = i + 1) begin
ALU_OP = i;
#20;
end
A = 3'd7;
B = 3'd3;
for (i = 0; i < 3 ; i = i + 1) begin
ALU_OP = i;
#20;
end
A = 3'd3;
B = 3'd5;
for (i = 0; i < 4 ; i = i + 1) begin
if (i != 2)
ALU_OP = i;
#20;
end
A = 3'd3;
B = 3'd7;
for (i = 0; i < 4 ; i = i + 1) begin
if (i != 2)
ALU_OP = i;
#20;
end
end
endmodule
/****************** OUTPUT OF PROGRAM ******************
A = 7 B = 7 ALU_OP = 0 Dout = 49 Cout = 0
A = 7 B = 7 ALU_OP = 1 Dout = 6 Cout = 1
A = 7 B = 7 ALU_OP = 2 Dout = 0 Cout = 0
A = 7 B = 3 ALU_OP = 0 Dout = 21 Cout = 0
A = 7 B = 3 ALU_OP = 1 Dout = 2 Cout = 1
A = 7 B = 3 ALU_OP = 2 Dout = 4 Cout = 0
A = 3 B = 5 ALU_OP = 0 Dout = 15 Cout = 0
A = 3 B = 5 ALU_OP = 1 Dout = 0 Cout = 1
A = 3 B = 5 ALU_OP = 3 Dout = 2 Cout = 0
A = 3 B = 7 ALU_OP = 0 Dout = 21 Cout = 0
A = 3 B = 7 ALU_OP = 1 Dout = 2 Cout = 1
A = 3 B = 7 ALU_OP = 3 Dout = 4 Cout = 0
********************************************************/
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.