Prev Problem
Next Problem

71. Arithmetic Logic Unit

Back To All Submissions
Previous Submission
Next Submission

Solving Approach

How do you plan to solve it?

 

Code

/*Write your code here*/
module alu4(
    input [3:0] a, b,
    input [2:0] op,
    output [3:0] y,
    output cf
);
    assign {cf, y} = op == 3'b000 ? {1'b0, a} + {1'b0, b} :
                     op == 3'b001 ? {1'b0, a} - {1'b0, b} :
                     op == 3'b010 ? {1'b0, a} & {1'b0, b} :
                     op == 3'b011 ? {1'b0, a} | {1'b0, b} :
                     op == 3'b100 ? {1'b0, a} ^ {1'b0, b} : 5'b00000;
endmodule

 

Was this helpful?
Upvote
Downvote