CMX
CMX firmware code in-line documentation
 All Classes Namespaces Files Functions Variables
add3x4.vhd
Go to the documentation of this file.
1 
11 
12 
13 LIBRARY ieee ;
14 USE ieee.std_logic_1164.all;
15 USE ieee.numeric_std.all;
16 Library work;
17 --use work.CMXpackage.all;
18 --use work.CMX_CP_package.all;
19 
20 
21 ENTITY add3x4 IS
22  PORT(
23  a : IN std_logic_vector (2 DOWNTO 0);
24  b : IN std_logic_vector (2 DOWNTO 0);
25  c : IN std_logic_vector (2 DOWNTO 0);
26  d : IN std_logic_vector (2 DOWNTO 0);
27  sum : OUT std_logic_vector (2 DOWNTO 0);
28  clk : IN std_logic
29  );
30 
31 -- Declarations
32 
33 END add3x4 ;
34 
35 -- hds interface_end
36 --------------------------------------------------------------------------------
37 ARCHITECTURE rtl_abx OF add3x4 IS
38 --------------------------------------------------------------------------------
39 -- 3-bit by 2-value adder, saturates at 7
40 --
41  ----------
42  function add4 (
43  a: std_logic_vector (2 downto 0);
44  b: std_logic_vector (2 downto 0);
45  c: std_logic_vector (2 downto 0);
46  d: std_logic_vector (2 downto 0)
47  )
48  return std_logic_vector is
49  ----------
50  -- add two 3-bit numbers, return 3-bit result that saturates at 7.
51  --
52  variable isum: integer range 0 to 28;
53  variable vsum: std_logic_vector(4 downto 0);
54  ----------
55  begin
56  isum := to_integer(unsigned(a))
57  + to_integer(unsigned(b))
58  + to_integer(unsigned(c))
59  + to_integer(unsigned(d));
60  vsum := std_logic_vector(to_unsigned(isum, 5));
61  if (vsum(3) = '1' or vsum(4) = '1') then
62  return "111";
63  else
64  return vsum(2 downto 0);
65  end if;
66  end add4;
67 
68 
69 --------------------------------------------------------------------------------
70 BEGIN
71 
72  clokprok: process (clk, a, b, c, d)
73  --
74  variable vsum: std_logic_vector(3 downto 0);
75  --
76  begin
77  if (clk'event and clk = '1') then
78  --
79  sum <= add4(a, b, c, d);
80  end if;
81  end process;
82 
83 END rtl_abx;
in clkstd_logic
Definition: add3x4.vhd:28
in astd_logic_vector (2 downto 0)
Definition: add3x4.vhd:23
out sumstd_logic_vector (2 downto 0)
Definition: add3x4.vhd:27
clokprokclk,a,b,c,d
Definition: add3x4.vhd:72
in cstd_logic_vector (2 downto 0)
Definition: add3x4.vhd:25
in dstd_logic_vector (2 downto 0)
Definition: add3x4.vhd:26
in bstd_logic_vector (2 downto 0)
Definition: add3x4.vhd:24
std_logic_vector add4a,b,c,d,
Definition: add3x4.vhd:42