久久久久久久999_99精品久久精品一区二区爱城_成人欧美一区二区三区在线播放_国产精品日本一区二区不卡视频_国产午夜视频_欧美精品在线观看免费

標題: VHDL之加法器系列(四位 八位 半加器 全加器) [打印本頁]

作者: xiaoliu    時間: 2014-11-10 15:28
標題: VHDL之加法器系列(四位 八位 半加器 全加器)
一、半加器
Library ieee;
Use ieee.std_logic_1164.all;
Entity halfadd is
Port(a,b:in std_logic;
     S,c:out std_logic);
end halfadd;
Architecture add of halfadd is
begin
S<=a xor b;
c<=a and b;
end;


二、全加器
Library ieee;
Use ieee.std_logic_1164.all;
Entity fulladd is
Port(a,b,cin:in std_logic;
     S,c:out std_logic);
end fulladd;
Architecture add of fulladd is
signal m,n,k:std_logic;
component halfadd is
Port(a,b:in std_logic;
     S,c:out std_logic);
end component;
begin
U0:halfadd port map(a,b,m,n);
U1:halfadd port map(m,cin,S,k);
c<=n or k;
end;


三、四位加法器
一)元件化全加器實現
Library ieee;
Use ieee.std_logic_1164.all;
Entity adder4 is
Port(a,b:in std_logic_vector(3 downto 0);
      cin:in std_logic;
      S:out std_logic_vector(3 downto 0);
      co:out std_logic);
end adder4;
Architecture add of adder4 is
signal c:std_logic_vector(3 downto 0);
component fulladd is
Port(a,b,cin:in std_logic;
     S,c:out std_logic);
end component;
begin
U0:fulladd port map(a(0),b(0),cin,S(0),c(0));
U1:fulladd port map(a(1),b(1),c(0),S(1),c(1));
U2:fulladd port map(a(2),b(2),c(1),S(2),c(2));
U3:fulladd port map(a(3),b(3),c(2),S(3),co);
end;

二)循環語句實現
Library ieee;
Use ieee.std_logic_1164.all;
Entity adder4 is
Port(a,b:in std_logic_vector(3 downto 0);
      cin:in std_logic;
      S:out std_logic_vector(3 downto 0);
      co:out std_logic);
end adder4;
Architecture add of adder4 is
begin
Process(a,b,cin)
variable c:std_logic_vector(4 downto 0);
begin
c(0):=cin;
for i in 0 to 3 loop
  s(i)<=a(i) xor b(i) xor c(i);
  c(i+1):=((a(i) xor b(i))and c(i))or (a(i) and b(i));
end loop;
co<=c(4);
end process;
end;
三)子程序實現
Library ieee;
Use ieee.std_logic_1164.all;
Entity adder4 is
Port(a,b:in std_logic_vector(3 downto 0);
      cin:in std_logic;
      S:out std_logic_vector(3 downto 0);
      co:out std_logic);
end adder4;
Architecture add of adder4 is
Procedure sam(ai,bi,ci:in std_logic;
               so,co: out std_logic) is  
   begin
   so:=ai xor bi xor ci;
   co:=((ai xor bi)and ci)or(ai and bi);
   end sam;
begin
Process(a,b,cin)
variable c:std_logic_vector(4 downto 0);
variable sum:std_logic_vector(3 downto 0);
begin
c(0):=cin;
for i in 0 to 3 loop
  sam(a(i),b(i),c(i),Sum(i),c(i+1));
end loop;
co<=c(4);
S<=sum;
end process;
end;
-------n-1位加法器,修改n的值,可以改變運算位數--------
Library ieee;
Use ieee.std_logic_1164.all;
entity adder_n is
generic(n:integer:=4);----改變w的值可以改變運算寬度
port(a,b:in std_logic_vector(n-1 downto 0);
     cin:in std_logic;
     Sum:out std_logic_vector(n-1 downto 0);
     co:out std_logic);
end;
Architecture add of adder_n is
  ---------------以下子程序---------------------
procedure fulladder(ai,bi,ci:in std_logic;
                     s,cc:out std_logic)is
       begin
        s:=ai xor bi xor ci;
        cc:=((ai xor bi)and ci)or(ai and bi);
  end fulladder;
  ------------------------------------------
begin
  process(a,b,cin)
   ---loop循環語句必須在process中使用,切子程序要求使用變量,所以在此不使用信號------
   variable ss:std_logic_vector(n-1 downto 0);
   variable c:std_logic_vector(n downto 0);
   -----------------------------------------------------------------------
   begin
  c(0):=cin;
  for i in 0 to n-1 loop
    fulladder(a(i),b(i),c(i),ss(i),c(i+1));
    end loop;
    co<=c(n);
    sum<=ss;
   end process;
  end;

四、八位二進制數相加
一)元件化實現
Library ieee;
Use ieee.std_logic_1164.all;
Entity adder8 is
Port(a,b:in std_logic_vector(7 downto 0);
      cin:in std_logic;
      S:out std_logic_vector(7 downto 0);
      co:out std_logic);
end adder8;
Architecture add of adder8 is
signal a1,a2,b1,b2,s1,s2:std_logic_vector(3 downto 0);
signal cc:std_logic;
component adder4 is
Port(a,b:in std_logic_vector(3 downto 0);
     cin:in std_logic;
     S:out std_logic_vector(3 downto 0);
     co:out std_logic);
end component;
begin
a1<=a(3 downto 0);a2<=a(7 downto 4);
b1<=b(3 downto 0);b2<=b(7 downto 4);
U0:adder4 port map(a1,b1,cin,S1,cc);
U1:adder4 port map(a2,b2,cc,S2,co);
S(7 downto 4)<=S2;S(3 downto 0)<=S1;
end;

二)循環語句實現
Library ieee;
Use ieee.std_logic_1164.all;
Entity adder4 is
Port(a,b:in std_logic_vector(3 downto 0);
      cin:in std_logic;
      S:out std_logic_vector(3 downto 0);
      co:out std_logic);
end adder4;
Architecture add of adder4 is
variable c:std_logic_vector(8 downto 0);
begin
Process(a,b,cin)
begin
c(0)<=cin;
for i in 0 to 7 loop
  s(i)<=a(i) xor b(i) xor c(i);
  c(i+1)<=((a(i) xor b(i))and c(i))or (a(i) and b(i));
end loop;
co<=c(8);
end process;
end;
三)子程序實現
Library ieee;
Use ieee.std_logic_1164.all;
Entity adder8 is
Port(a,b:in std_logic_vector(7 downto 0);
      cin:in std_logic;
      S:out std_logic_vector(7 downto 0);
      co:out std_logic);
end adder8;
Architecture add of adder4 is
Procedure sam(ai,bi,ci:in std_logic;
               so,co: out std_logic) is  
   begin
   so:=ai xor bi xor ci;
   co:=((ai xor bi)and ci)or(ai and bi);
   end sam;
begin
Process(a,b,cin)
variable c:std_logic_vector(8 downto 0);
variable sum:std_logic_vector(7 downto 0);
begin
c(0):=cin;
for i in 0 to 7 loop
  sam(a(i),b(i),c(i),Sum(i),c(i+1));
end loop;
co<=c(8);
S<=sum;
end process;
end;


減法器接下篇:http://www.zg4o1577.cn/bbs/dpj-28501-1.html





歡迎光臨 (http://www.zg4o1577.cn/bbs/) Powered by Discuz! X3.1
主站蜘蛛池模板: 国产黄色大片 | 精品91av| 亚洲欧美综合 | 一区二区在线免费观看视频 | 久久久久久久国产精品 | www.黄色网| 亚洲综合色视频在线观看 | 精品视频在线一区 | 九九九国产 | a视频在线 | 久久新 | 国产成人精品网站 | 欧美日韩电影一区二区 | 色视频在线观看 | 亚洲日本一区二区三区四区 | 欧美一区精品 | 伦理二区 | 欧美专区在线视频 | 拍拍无遮挡人做人爱视频免费观看 | 亚洲精品国产精品国自产在线 | 国产精品亚洲欧美日韩一区在线 | 精品一区二区久久久久久久网站 | 国产精品欧美精品 | 婷婷一级片| 成人h视频在线观看 | 午夜精品一区二区三区在线视频 | 成人免费视频播放 | 欧美精品一区在线发布 | 欧美日韩在线精品 | 自拍第1页 | 伊人色综合久久天天五月婷 | 精品国产区 | 国产精品自产拍在线观看蜜 | 91精品综合久久久久久五月天 | 日韩有码一区 | 精品一区二区av | 在线色网| 99草免费视频 | 国产欧美一区二区久久性色99 | 欧美日韩国产一区二区三区 | 国产欧美在线观看 |