0% found this document useful (0 votes)
31 views

Computer Architecture Assignment

The document describes code for a 32-bit barrel shifter. It contains a b_shift module that uses 32 multiplexers (mux) to shift the input (a) by the number of positions indicated by the input (b). It also contains a multiplexer module that selects the appropriate bit from the input (a) based on the value of the input (b).

Uploaded by

Sheryar Mahar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views

Computer Architecture Assignment

The document describes code for a 32-bit barrel shifter. It contains a b_shift module that uses 32 multiplexers (mux) to shift the input (a) by the number of positions indicated by the input (b). It also contains a multiplexer module that selects the appropriate bit from the input (a) based on the value of the input (b).

Uploaded by

Sheryar Mahar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

32- BIT BARREL SHIFTER CODE

Coding for Model Sim:


mux m24(y[23],{ a[22:0], a[31:23]}, b);
module b_shift(a , b, x, y);

mux m25(y[24],{ a[23:0], a[31:24]}, b);

input [31:0] a;

mux m26(y[25],{ a[24:0], a[31:25]}, b);

input[4:0] b;

mux m27(y[26],{ a[25:0], a[31:26]}, b);

output [31:0] x;

mux m28(y[27],{ a[26:0], a[31:27]}, b);

output [31:0] y;

mux m29(y[28],{ a[27:0], a[31:28]}, b);

mux m1(y[0], a, b);

mux m30(y[29],{ a[28:0], a[31:29]}, b);

mux m2(y[1],{ a[0], a[31:1]}, b);

mux m31(y[30],{ a[29:0], a[31:30]}, b);

mux m3(y[2],{ a[1:0], a[31:2]}, b);

mux m32(y[31],{ a[30:0], a[31:31]}, b);

mux m4(y[3],{ a[2:0], a[31:3]}, b);


mux m5(y[4],{ a[3:0], a[31:4]}, b);

assign x=y;
endmodule

mux m6(y[5],{ a[4:0], a[31:5]}, b);


mux m7(y[6],{ a[5:0], a[31:6]}, b);

module multiplexer( ans, a, b);

mux m8(y[7],{ a[6:0], a[31:7]}, b);

input[31:0] a;

mux m9(y[8],{ a[7:0], a[31:8]}, b);

output ans;

mux m10(y[9],{ a[8:0], a[31:9]}, b);

reg ans;

mux m11(y[10],{ a[9:0], a[31:10]}, b);

input [4:0] b;

mux m12(y[11],{ a[10:0], a[31:11]}, b);

alw ays @( b)

mux m13(y[12],{ a[11:0], a[31:12]}, b);

begin

mux m14(y[13],{ a[12:0], a[31:13]}, b);


mux m15(y[14],{ a[13:0], a[31:14]}, b);
mux m16(y[15],{ a[14:0], a[31:15]}, b);
mux m17(y[16],{ a[15:0], a[31:16]}, b);
mux m18(y[17],{ a[16:0], a[31:17]}, b);
mux m19(y[18],{ a[17:0], a[31:18]}, b);
mux m20(y[19],{ a[18:0], a[31:19]}, b);
mux m21(y[20],{ a[19:0], a[31:20]}, b);
mux m22(y[21],{ a[20:0], a[31:21]}, b);

if ( b==5' b00000)
ans = a[0];
else if ( b==5' b00001)
ans = a[1];
else if ( b==5' b00010)
ans = a[2];
else if ( b==5' b00011)
ans = a[3];
else if ( b==5' b00100)

mux m23(y[22],{ a[21:0], a[31:22]}, b);

Page | 1

ans = a[4];

else if ( b==5' b10011)

else if ( b==5' b00101)


ans = a[5];

ans = a[19];
else if ( b==5' b10100)

else if ( b==5' b00110)


ans = a[6];

ans = a[20];
else if ( b==5' b10101)

else if ( b==5' b00111)


ans = a[7];

ans = a[21];
else if ( b==5' b10110)

else if ( b==5' b01000)


ans = a[8];

ans = a[22];
else if ( b==5' b10111)

else if ( b==5' b01001)


ans = a[9];

ans = a[23];
else if ( b==5' b11000)

else if ( b==5' b01010)


ans = a[10];

ans = a[24];
else if ( b==5' b11001)

else if ( b==5' b01011)


ans = a[11];

ans = a[25];
else if ( b==5' b11010)

else if ( b==5' b01100)


ans = a[12];

ans = a[26];
else if ( b==5' b11011)

else if ( b==5' b01101)


ans = a[13];

ans = a[27];
else if ( b==5' b11100)

else if ( b==5' b01110)


ans = a[14];

ans = a[28];
else if ( b==5' b11101)

else if ( b==5' b01111)


ans = a[15];

ans = a[29];
else if ( b==5' b11110)

else if ( b==5' b10000)


ans = a[16];

ans = a[30];
else if ( b==5' b11111)

else if ( b==5' b10001)


ans = a[17];
else if ( b==5' b10010)

ans = a[31];
end
endmodule

ans = a[18];

Page | 2

SCREENSHOT OUTPUT:
Input 1

Output 1

Input 2

Output 2

You might also like