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,mode, output reg[7:0]y);
always @* begin
    y=x;
    case(mode)
        3'b001: y=y<<sh;
        3'b010: y=y>>sh;
        3'b011: for(integer i=0;i<sh;i++) begin
                    y=y>>1; y[7]=x[7];end
        3'b100: for(integer i=0;i<sh;i++) begin
                    y={y[6:0],y[7]};end
        3'b101: for(integer i=0;i<sh;i++) begin
                    y={y[0],y[7:1]};end
    endcase
end
endmodule

 

Was this helpful?
Upvote
Downvote