Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please answer both parts. OPCODE has no signifigance, ALU is adder. e) make this

ID: 2267719 • Letter: P

Question

Please answer both parts. OPCODE has no signifigance, ALU is adder.

e) make this ALU module work to do alu Atalu _Btalu_cin, you will have to add declaration statements to define the types of variables, and you will have to add code in the case statement for OPCODE 0000 (the only OPCODE shown) //ALU module module ALU (input [3:0] alu A, alu B, OPCODE, input alu Cin, output reg [3:01 alu_out, output reg alu_Cout, alu_OF) put your declarations here // A and B are 4 bit wide inputs, Cin is a 1 bit wide carry in, Sum // is a 4 bit wide array containing the Sum of A+BtCin, Cout is the 1 carry out from the ripple adder FA4 and OF is a lbit variable // indicating overflow, this is an instance of FA4 FA4 fa4a (A, B, Cin, Sum, Cout, OF); always e ()begin case (OPCODE) /1 add alu_Atalu_B with alu Cin using FA4 'b0000 begin put your code here to make this work end endcase end endmodule

Explanation / Answer

module ALU (
input [3:0] alu_A, alu_B, OPCODE,
input alu_Cin,
output reg [3:0] alu_out,
output reg alu_Cout, alu_OF
);

// Internal variable decalarations
reg [3:0] A;
reg [3:0] B;
reg Cin;
wire [3:0] Sum;
wire Cout;
wire OF;

// Full Adder 4bit instantiation
FA4 fa4a (A, B, Cin, Sum, Cout, OF);

always @ (*)
  begin
   case(OPCODE) // only going for the 4'b0000 OPCODE
   4'b0000 : begin
   A = alu_A;
   B = alu_B;
   Cin = alu_Cin;
   alu_out = Sum;
   alu_Cout = Cout;
   alu_OF = OF;
   end
   endcase
  end
endmodule

//module Definition for the 4bit Full Adder
module FA4 (
input [3:0] A,B,
input Cin,
output [3:0] Sum,
output Cout,OF
);

// Generating the Carry_out and Sum
assign {Cout,Sum} = A + B + Cin;
// Generating the Overflow flag
assign OF = (A[3] ^ B[3] ^ Sum[3]) ^ Cout;

endmodule