fpga

2

Click here to load reader

Upload: faizan

Post on 16-Jul-2015

189 views

Category:

Education


0 download

TRANSCRIPT

Page 1: Fpga

----------------------------------------------------- Simple ALU Module (ESD book Figure 2.5)-- by Weijun Zhang, 04/2001---- ALU stands for arithmatic logic unit.-- It perform multiple operations according to -- the control bits.-- we use 2's complement subraction in this example-- two 2-bit inputs & carry-bit ignored---------------------------------------------------

library ieee;use ieee.std_logic_1164.all;use ieee.std_logic_unsigned.all;use ieee.std_logic_arith.all;

---------------------------------------------------

entity ALU is

port( A: in std_logic_vector(1 downto 0);B: in std_logic_vector(1 downto 0);Sel: in std_logic_vector(1 downto 0);Res: out std_logic_vector(1 downto 0)

);

end ALU;

---------------------------------------------------

architecture behv of ALU isbegin

process(A,B,Sel) begin

-- use case statement to achieve -- different operations of ALU

case Sel is when "00" =>

Res <= A + B; when "01" => Res <= A + (not B) + 1;

when "10" =>Res <= A and B;

when "11" => Res <= A or B;

when others => Res <= "XX";

end case;

end process;

end behv;

----------------------------------------------------

Page 2: Fpga

----------------------------------------------------- 3-bit Shift-Register/Shifter-- (ESD book figure 2.6)-- by Weijun Zhang, 04/2001---- reset is ignored according to the figure---------------------------------------------------

library ieee ;use ieee.std_logic_1164.all;

---------------------------------------------------

entity shift_reg isport( I: in std_logic;

clock: in std_logic;shift: in std_logic;Q: out std_logic

);end shift_reg;

---------------------------------------------------

architecture behv of shift_reg is

-- initialize the declared signal signal S: std_logic_vector(2 downto 0):="111";

begin process(I, clock, shift, S) begin

-- everything happens upon the clock changingif clock'event and clock='1' then if shift = '1' then

S <= I & S(2 downto 1); end if;end if;

end process;

-- concurrent assignment Q <= S(0);

end behv;

----------------------------------------------------