Prev Problem
Next Problem

51. Opcode Decoder

Back To All Submissions
Previous Submission
Next Submission

Solving Approach

How do you plan to solve it?

 

 

Code

//==================================================
// Module: alu_decoder
// Description: 2-bit opcode to 4-bit one-hot ALU operation decoder.
//==================================================
module alu_decoder (
    input  wire [1:0] opcode,
    output reg  [3:0] alu_op
);

    always @(*) begin
        case (opcode)
            2'b00: alu_op = 4'b0001;  // Operation 0
            2'b01: alu_op = 4'b0010;  // Operation 1
            2'b10: alu_op = 4'b0100;  // Operation 2
            2'b11: alu_op = 4'b1000;  // Operation 3
            default: alu_op = 4'b0000; // Safety default
        endcase
    end

endmodule

 

Was this helpful?
Upvote
Downvote