Code of barrel shifter:
Type 00 for left Shift
Type 01 for right Shift
Type 10 for left Rotate
Type 11 for right Rotate
Code:
module barrel_shifter(data, type, amount, out);
input [3:0] data;
input [1:0] type;
input [1:0] amount;
output [3:0] out;
endmodule
module barrel(u, y, t, out);
input [3:0] u; %data
input [1:0] y; %type
input [1:0] t; %amount
output [3:0] out;
assign zero=(0);
MUX0 m1(u[0],zero,zero,zero,a[0],a[1],a[2],a[3],a[0],a[3],a[2],a[1],a[0],a[1],a[2],a[3],t[0],t[1], y[0],y[1],out[0]);
MUX1 m2(u[1],u[0],zero,zero,u[1],u[2],u[3],zero,u[1],u[0],u[3],u[2],u[1],u[2],u[3],u[0],u[0],u[1], y[0],y[1],out[1]);
MUX2 m3(u[2],u[1],u[0],zero,u[2],u[3],zero,zero,u[2],u[1],u[0],u[3],u[2],u[3],u[0],u[1],u[0],u[1], y[0],y[1],out[2]);
MUX3 m4(u[3],u[2],u[1],u[0],u[3],zero,zero,zero,u[3],u[2],u[1],u[0],u[3],u[0],u[1],u[2],t[0],t[1], y[0],y[1],out[3]);
endmodule