Adder.vhd
75 lines
| 2.3 KiB
| text/x-vhdl
|
VhdlLexer
Alexis
|
r1 | ------------------------------------------------------------------------------ | ||
-- This file is a part of the LPP VHDL IP LIBRARY | ||||
-- Copyright (C) 2009 - 2010, Laboratory of Plasmas Physic - CNRS | ||||
-- | ||||
-- This program is free software; you can redistribute it and/or modify | ||||
-- it under the terms of the GNU General Public License as published by | ||||
Alexis
|
r19 | -- the Free Software Foundation; either version 3 of the License, or | ||
Alexis
|
r1 | -- (at your option) any later version. | ||
-- | ||||
-- This program is distributed in the hope that it will be useful, | ||||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of | ||||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||||
-- GNU General Public License for more details. | ||||
-- | ||||
-- You should have received a copy of the GNU General Public License | ||||
-- along with this program; if not, write to the Free Software | ||||
-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||||
------------------------------------------------------------------------------- | ||||
Alexis
|
r38 | -- Author : Alexis Jeandet | ||
-- Mail : alexis.jeandet@lpp.polytechnique.fr | ||||
---------------------------------------------------------------------------- | ||||
pellion
|
r111 | LIBRARY IEEE; | ||
USE IEEE.numeric_std.ALL; | ||||
USE IEEE.std_logic_1164.ALL; | ||||
LIBRARY lpp; | ||||
USE lpp.general_purpose.ALL; | ||||
Alexis
|
r1 | |||
pellion
|
r111 | ENTITY Adder IS | ||
GENERIC( | ||||
Input_SZ_A : INTEGER := 16; | ||||
Input_SZ_B : INTEGER := 16 | ||||
Alexis
|
r1 | |||
pellion
|
r111 | ); | ||
PORT( | ||||
clk : IN STD_LOGIC; | ||||
reset : IN STD_LOGIC; | ||||
clr : IN STD_LOGIC; | ||||
load : IN STD_LOGIC; | ||||
add : IN STD_LOGIC; | ||||
OP1 : IN STD_LOGIC_VECTOR(Input_SZ_A-1 DOWNTO 0); | ||||
OP2 : IN STD_LOGIC_VECTOR(Input_SZ_B-1 DOWNTO 0); | ||||
RES : OUT STD_LOGIC_VECTOR(Input_SZ_A-1 DOWNTO 0) | ||||
); | ||||
END ENTITY; | ||||
Alexis
|
r1 | |||
pellion
|
r111 | ARCHITECTURE ar_Adder OF Adder IS | ||
Alexis
|
r1 | |||
pellion
|
r111 | SIGNAL REG : STD_LOGIC_VECTOR(Input_SZ_A-1 DOWNTO 0); | ||
SIGNAL RESADD : STD_LOGIC_VECTOR(Input_SZ_A-1 DOWNTO 0); | ||||
Alexis
|
r1 | |||
pellion
|
r111 | BEGIN | ||
Alexis
|
r1 | |||
pellion
|
r111 | RES <= REG; | ||
RESADD <= STD_LOGIC_VECTOR(resize(SIGNED(OP1)+SIGNED(OP2), Input_SZ_A)); | ||||
Alexis
|
r1 | |||
pellion
|
r111 | PROCESS(clk, reset) | ||
BEGIN | ||||
IF reset = '0' THEN | ||||
REG <= (OTHERS => '0'); | ||||
ELSIF clk'EVENT AND clk = '1' then | ||||
IF clr = '1' THEN | ||||
REG <= (OTHERS => '0'); | ||||
ELSIF add = '1' THEN | ||||
REG <= RESADD; | ||||
ELSIF load = '1' THEN | ||||
REG <= OP2; | ||||
END IF; | ||||
END IF; | ||||
END PROCESS; | ||||
END ar_Adder; | ||||