Question: My ALU isn't working right and the opcode and enable should be grab by the FSM that i have already made can you fix it
My ALU isn't working right and the opcode and enable should be grab by the FSM that i have already made can you fix it and make a testbench so it works?
module alu
input : a Operand A
input : b Operand B
input : opcode, Operation opcode from FSM
input enable, Enable signal for ALU operation
output reg : result, ALU result
output reg divbyzero Flag to indicate division by zero
;
ALU Operations based on opcode
always @ begin
if enable begin
divbyzero ; Default to no division by zero error
case opcode
b: result a b; Addition
b: result a b; Subtraction
b: result a b; Multiplication
b: begin
if b begin
result b; Division by zero case
divbyzero ; Set division by zero flag
end else begin
result a b; Division
divbyzero ; No error
end
end
b: result a & b; AND
b: result a b; OR
b: result a ; Shift Left
b: result a ; Shift Right
default: result b; Default to error case
endcase
end else begin
result b; If ALU is not enabled, output
divbyzero ; No division by zero error if ALU is disabled
end
end
endmodule
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
