Professional Documents
Culture Documents
Carlo B. Baja - Expt2 - LogicalShifters
Carlo B. Baja - Expt2 - LogicalShifters
Logical Shifter
Course Code: CPE 504 Program: BSCPE
Course Title: Computer Systems Architecture Date Performed: September 13, 2019
Section: CPE52FC1 Date Submitted: September 14, 2019
Members: Carlo B. Baja Instructor: Cris Paulo Hate
1. Objective(s):
The activity aims the students to create the simulation of logical shifter using VHDL code.
3. Discussion:
Logical shifter is the shifting of the bits from selected digit values. It is used in some arithmetic operations
such as multiplication and division. The block diagram in Figure 2-1 includes the combinational circuit with 2
inputs (DI and SEL) and 1 output (SO). The first input, DI, serves as a data input that is being shifted; the
second input, SEL, is a selector to what particular binary value of the shift process while the output is the
result of the shift operation.
14
In VHDL coding, the “with SEL select” syntax should be used for bits shifting operation. Sample code
using with SEL select syntax is shown below:
(output omitted)
with SEL select
SO <= DI when "00",
DI sll 1 when "01",
DI sll 2 when "10",
DI sll 3 when others;
Sample Output
Input Output
SEL DI SO
01 0000 0011 0000 0110
00 0000 0000 0000 0000
11 0000 1111 0111 1000
10 0001 0011 0100 1100
In writing the logical shifter codes, there are certain rules that should be considered:
• For VHDL, you can only use predefined shift (SLL, SRL, ROL, etc.) or concatenation operations.
• Use only one type of shift operation.
• The n value in the shift operation must be incremented or decremented only by 1 for each consequent
binary value of the selector.
• The n value can be only positive.
• All values of the selector must be presented.
1. Computer Unit
2. Xilinx Software
5. Procedure:
1. Using Xilinx Software make a project with a named logicalshifters. (Please refer to topic A and
follow steps 1-7)
2. Create an HDL Source (Please refer to topic B and follow steps 1 to 5).
3. Enter the following parameters in the “Define Module” dialog box
15
4. Click next, then Finish
5. In the architectural behavioral body of the VHDL Module codes enter the following:
begin
with SEL select
SO <= DI when "00",
DI sll 1 when "01",
DI sll 2 when "10",
DI sll 3 when others;
end behavioral;
6. Compare the given codes below to the VHDL Module codes created.
--
-- Following is the VHDL code for a logical shifter.
--
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity logicalshifters is
port(DI : in unsigned(7 downto 0);
SEL : in unsigned(1 downto 0);
SO : out unsigned(7 downto 0));
end logicalshifters;
architecture behavioral of logicalshifters is
begin
with SEL select
SO <= DI when "00",
DI sll 1 when "01",
DI sll 2 when "10",
DI sll 3 when others;
end behavioral;
If it is not equal, what should be added to the edited VHDL Module code?
Nothing.
7. Edit the VHDL module based on the given codes above.
What do you think is the importance of the missing codes that just added?
To ensure that the logical shifter works as designed.
8. Uncheck the Manual Compile if it is checked. (Please refer to topic B and follow steps includes in
Figure 7)
9. Right click on the logicalshifters under the Hierarchy panel of the Design View. (Upper left portion
of the Xilinx window) and choose Implement Top Module.
Note: Make sure that the Implementation under the Hierarchy panel of the Design View radio
button is selected.
Table 2-2
Input Output
SEL DI SO
1.) 00 0111 0000 0111 0000
2.) 01 0101 1001 1011 0010
3.) 10 0110 0010 1000 1000
4.) 11 0011 1011 1101 1000
5.) 00 0101 0101 0101 0101
6.) 01 0011 1111 0111 1110
7.) 10 0011 1010 1110 1000
8.) 11 0010 1001 0100 1000
9.) 01 0101 1110 1011 1100
10.) 10 0110 1111 1100 1011
7. Data Analysis
The shift operators are described with the components of type BIT or BOOLEAN for the one-dimensional
array. The left operand L is an array for the shift operator and the right operand R is integer. The right
operand is the number of positions that should be shifted to the left operand. The value of the same type as
the left operand is returned as a result of the shift.
The sll, srl, and rol have been used in the operation. The operator sll returns the left operand's value after
the number of times R has been shifted. The operator srl returns the left operand L value after shifting it to
right R times. The operator rol returns the left operand's value after it is rotated to the left R times.
8. Supplemental Activity::
18
Create a VHDL code with test bench of the following:
a. Logical Shifters using SRL
19
Testbench
20
Waveform
Module
8. Assessment Rubric:
21