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 [7:0] y
);
reg [7:0] temp;

always @* begin
    temp = x;
    case(mode)
    3'd0    : temp = x ;
    3'd1    : temp = x<<sh;
    3'd2    : temp = x>>sh;
    3'd3    : temp = $signed(x)>>>sh;
    3'd4    : temp = (x<<sh)|(x>>(8-sh));
    3'd5    : temp = (x>>sh)|(x<<(8-sh));
    default : temp = x;
        endcase
end
assign y = temp;
endmodule

 

Was this helpful?
Upvote
Downvote