Lab 7: VHDL 16-Bit Shifter
Lab 7: VHDL 16-Bit Shifter
Objectives :
Design a 16-bit shifter which need implement eight shift operations: logic shift right, logic shift
left, arithmetic shift right, arithmetic shift left, rotate right, rotate left rotate left with carry, rotate left with
carry.
4 A
S
To C
C
H
16
Figure 1. Symbol
1
S1 S0 Shift Operation
0 0 Logic Shift
0 1 Arithmetic shift
1 0 Rotate
1 1 Rotate with carry
S3 S2 Shift direction
0 0 Parallel Load
0 1 Shift Right with IL
1 0 Shift Left with IR
1 1 No Change
In the above logic diagram, for the unit “16-bit basic shifter” design you may refer to the
available code for the Universal Shift Register with parallel load(three different style
codes are given).
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
USE IEEE.STD_LOGIC_UNSIGNED.ALL;
USE IEEE.NUMERIC_BIT.ALL;
2
ENTITY univ_shiftreg1 IS
PORT(clk, il, ir : IN BIT;
s: IN BIT_VECTOR(1 DOWNTO 0);
i : IN BIT_VECTOR(3 DOWNTO 0);
q : OUT BIT_VECTOR(3 DOWNTO 0));
END univ_shiftreg1;
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_bit.all;
entity univ_shiftreg2 is
end univ_shiftreg2;
begin
process(clk)
begin
if (clk = '1' and clk'event) then
case s is
when "00" =>
qtmp <= qtmp;
3
when "01" =>
qtmp <=il&i&ir;
when "10" =>
qtmp <= (il&qtmp(4 downto 1)&ir) sll 1;
end beh2;
Write a vhdl code to model (entity and architecture) a four to one multiplexer called “MUX41”.
4
s: IN BIT_VECTOR(1 DOWNTO 0);
o: OUT BIT);
END MUX41;
ARCHITECTURE arch_mux41 OF MUX41 IS
BEGIN
PROCESS(i3, i2, i1, i0, s)
BEGIN
CASE s IS
WHEN "00" => o <= i0;
WHEN "01" => o <= i1;
WHEN "10" => o <= i2;
WHEN "11" => o <= i3;
WHEN OTHERS => NULL;
END CASE;
END PROCESS;
END arch_mux41
Write a vhdl code to model (entity and architecture) d flip-flop called “DFF”.
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
ENTITY DFF IS
PORT(d, clk : IN BIT;
q, qb : OUT BIT);
END DFF;
ARCHITECTURE arch_dff OF DFF IS
BEGIN
PROCESS(clk)
VARIABLE q_temp : BIT;
BEGIN
IF(clk'EVENT AND clk='1')THEN
q_temp := d;
END IF;
q <= q_temp;
qb <= NOT q_temp;
END PROCESS;
END arch_dff;
Using DFF and MUX41 components, generates the structural model of the “univ_shiftreg”. That is,
show the port map for each of the components shown in Fig 2.
LIBRARY IEEE;
USE IEEE.STD_LOGIC_1164.ALL;
ENTITY univ_shiftreg3 IS
PORT(clk, il, ir : IN BIT;
s: IN BIT_VECTOR(1 DOWNTO 0);
i : IN BIT_VECTOR(3 DOWNTO 0);
q : OUT BIT_VECTOR(3 DOWNTO 0));
END univ_shiftreg3;
ARCHITECTURE struct OF univ_shiftreg3 IS
COMPONENT MUX41
PORT (i3, i2, i1, i0 : IN BIT;
s: IN BIT_VECTOR(1 DOWNTO 0);
o: OUT BIT);
END COMPONENT;
COMPONENT DFF
PORT(d, clk : IN BIT;
5
q, qb : OUT BIT);
END COMPONENT;
FOR U1, U2, U3, U4: MUX41 USE ENTITY WORK.MUX41(arch_mux41);
FOR U5, U6, U7, U8: DFF USE ENTITY WORK.DFF(arch_dff);