Prev Problem
Next Problem

70. Universal Barrel Shifter

Back To All Submissions
Previous Submission
Next Submission

Solving Approach

How do you plan to solve it?

 

Code

/*Write your code here*/
module univ_barrel8(
    input[7:0]x,
    input[2:0]sh,
    input[2:0]mode,
    output reg [7:0]y
);
always@(*)begin
    case(mode)
    3'b000:begin
        y=x;
    end
    3'b001:begin
        y=x<<sh;
    end
    3'b010:begin
        y=x>>sh;
    end
    3'b011:begin
        y= $signed(x) >>> sh;
    end
    3'b100:begin
        y = (x << sh) | (x >> (8 - sh));
    end
    3'b101:begin
        y=(x >> sh) | (x << (8 - sh));
    end
    default:begin
        y=x;
    end
    endcase
end
endmodule


 

Was this helpful?
Upvote
Downvote