N-bit adder 代码

上一篇 / 下一篇  2007-12-06 01:40:32 / 个人分类:示例代码


-- 在quartus 6.0 下通过编译,说明一个文件中并非只能有一个实体 2007.12.5
------------------------------------------------------------------------
-- Single-bit adder
------------------------------------------------------------------------
library IEEE;
use IEEE.std_logic_1164.all;
entity adder is
    port (a    : in std_logic;
          b    : in std_logic;
          cin  : in std_logic;
          sum  : out std_logic;
          cout : out std_logic);
end adder;

-- description of adder using concurrent signal assignments
architecture rtl of adder is
begin
    sum <= (a xor b) xor cin;
    cout <= (a and b) or (cin and a) or (cin and b);
end rtl;
------------------------------------------------------------------------
-- N-bit adder
-- The width of the adder is determined by generic N
------------------------------------------------------------------------
library IEEE;
use IEEE.std_logic_1164.all;
entity adderN is
    generic(N : integer := 16);
    port (a    : in std_logic_vector(N downto 1);
          b    : in std_logic_vector(N downto 1);
          cin  : in std_logic;
          sum  : out std_logic_vector(N downto 1);
          cout : out std_logic);
end adderN;

-- structural implementation of the N-bit adder
architecture structural of adderN is
    component adder
        port (a    : in std_logic;
              b    : in std_logic;
              cin  : in std_logic;
              sum  : out std_logic;
              cout : out std_logic);
    end component;

    signal carry : std_logic_vector(0 to N);
begin
    carry(0) <= cin;
    cout <= carry(N);

    -- instantiate a single-bit adder N times
    gen: for I in 1 to N generate
    add: adder port map(
        a => a(I),
        b => b(I),
        cin => carry(I - 1),
        sum => sum(I),
        cout => carry(I));
   end generate;
end structural;


FPGA/CPLD器件价格查询

TAG: 示例 Quartus quartus n-bit adder

 

评分:0

我来说两句

显示全部

:loveliness: :handshake :victory: :funk: :time: :kiss: :call: :hug: :lol :'( :Q :L ;P :$ :P :o :@ :D :( :)

日历

« 2008-12-04  
 123456
78910111213
14151617181920
21222324252627
28293031   

数据统计

  • 访问量: 838
  • 日志数: 7
  • 文件数: 1
  • 建立时间: 2007-03-16
  • 更新时间: 2007-12-16

RSS订阅

Open Toolbar