Professional Documents
Culture Documents
Digital System Design: Implementation of Barrel Shifter
Digital System Design: Implementation of Barrel Shifter
Digital System Design: Implementation of Barrel Shifter
OBJECTIVES
INTRODUCTION
A barrel shifter is a combinational logic circuit with n data inputs, n data outputs, and a set
of control inputs that specify how to shift the data between input and output. A barrel
shifter that is part of a microprocessor CPU can typically specify the direction of shift (left or
right), the type of shift (circular, arithmetic, or logical), and the amount of shift (typically 0
to n–1 bits, but sometimes 1 to n bits).
A typical barrel shifter has n data inputs, n data outputs and control inputs. Control inputs
specify ,direction, type (arithmetic, logical, circular) , number of positions to rotate or shift
data inputs for example: n = 16 , DIN[15:0], DOUT[15:0], S[3:0] (shift amount) then to
this problem there are many possible solutions, all based on multiplexers.
Data ; Input 4
type Input 2
amount Input 2
out Output 4
1. Module barrel_shifter
Module barrel_shifter(data, type, amount, out);
Page | 61
Digital System Design LAB 3
Input [3:0] data;
endmodule
Page | 62
Digital System Design LAB 3
2. module mux16x1
module mux16x1(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, s0, s1, s2, s3, out);
output out;
endmodule
3. module mux8x1
module mux8x1(a, b, c, d, e, f, g, h, s0, s1, s2, out);
output out;
endmodule
Page | 63
Digital System Design LAB 3
4. module mux4x1
module mux4x1(a, b, c, d, s0, s1, out);
output out;
endmodule
5. module mux2x1
module mux2x1(a, b, s, out);
input a, b, s;
output out;
endmodule
Page | 64
Digital System Design LAB 3
Draw a figure which is representative of the hierarchy of Verilog codes provided?
Task1
Create a project in Xilinx ISE .Add all of the modules written above to the project. Now
simulate this file using ISE Simulator. Next synthesize this file using XST.
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
Draw results from Test bench for barrel shifter? Indicate Input & Output signals?
Page | 65
Digital System Design LAB 3
Barrel Shifter at behavioral level Verilog HDL
A Verilog module for barrel shifter at behavioral level is written below.
begin
case({type, amount})
Page | 66
Digital System Design LAB 3
4'b1100: out = data;
endcase
end
endmodule
Task2
Create a project in Xilinx ISE .Add this file to the project .Now simulate this file using ISE
Simulator. Now Answer following Questions
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
How you are shifting data in barrel shifter at behavioral level as compared to
module written at gate level?
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
Draw results from Test bench for barrel shifter at behavioral level?
Page | 67
Digital System Design LAB 3
Arithmetic Operations
Adders, Subtractors, Adders/Subtractors
Task3
Create a project in Xilinx ISE .Add this file to the project .For each file create test bench and
generate output waveforms. Then answer Questions given at the end of modules.
input [7:0] A;
input [7:0] B;
assign SUM = A + B;
endmodule
assign SUM = A + B;
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
Draw wave form results from Test bench for Unsigned 8-bit Adder?
Page | 68
Digital System Design LAB 3
Unsigned 8-Bit Adder with Carry In
The following module describes Unsigned 8-bit Adder with Carry.
input [7:0] A;
input [7:0] B;
input CI;
endmodule
Draw wave form results from Test bench for Unsigned 8-bit Adder with Carry In?
input [7:0] A;
input [7:0] B;
output CO;
assign tmp = A + B;
endmodule
Draw wave form results from Test bench for Unsigned 8-bit Adder with Carry In?
Page | 69
Digital System Design LAB 3
Unsigned 8-Bit Adder with Carry In and Carry Out
The following module describes Unsigned 8-bit Adder with Carry In and Carry Out.
input CI;
input [7:0] A;
input [7:0] B;
output CO;
endmodule
Draw wave form results from Test bench for Unsigned 8-bit Adder with Carry In
and carry out?
input [7:0] A;
input [7:0] B;
assign RES = A - B;
endmodule
Draw wave form results from Test bench for Unsigned 8-bit Subtractor ?
Page | 70
Digital System Design LAB 3
Unsigned 8-Bit Adder/Subtractor
module v_adders_7(A, B, OPER, RES);
input OPER;
input [7:0] A;
input [7:0] B;
begin
if (OPER==1'b0) RES = A + B;
else RES = A - B;
end
end module
if (OPER==1'b0) RES = A + B;
else RES = A - B;
_________________________________________________________________________
______________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
_________________________________________________________________________
Draw wave form results from Test bench for unsigned 8-bit Adder/Subtractor?
Page | 71
Observations/Comments/Explanation of Results