module barrel_shift(A, S, LorR, Q);

	input [15:0] A;
	input [15:0] S;
	input LorR;
	output [15:0] Q;

	reg [15:0] Q;

	always @(A or S[3:0] or LorR) begin
		if(LorR) begin
			Q <= (A >> S[3:0]) | (A << (16 - S[3:0]));
		end
		else begin
			Q <= (A << S[3:0]) | (A >> (16 - S[3:0]));
		end
	end
endmodule