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?

use shift operators, for rotate instructions simply write an example and see how it works

Code

/*Write your code here*/
module univ_barrel8(
    input [7:0] x,
    input [2:0] sh, mode,
    output reg [7:0] y
);
    always @(*) begin
        case (mode)
            3'd0 : y = x;
            3'd1 : y = x << sh;
            3'd2 : y = x >> sh;
            3'd3 : y = $signed(x) >>> sh;
            3'd4 : y = (x << sh)|(x >> (8-sh));
            3'd5 : y = (x << (8-sh))|(x >> sh);
            default : y = x;
        endcase
    end
endmodule
           

 

Was this helpful?
Upvote
Downvote