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

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 22179|回復: 0
打印 上一主題 下一主題
收起左側(cè)

VHDL之加法器系列(四位 八位 半加器 全加器)

[復制鏈接]
跳轉(zhuǎn)到指定樓層
樓主
ID:51269 發(fā)表于 2014-11-10 15:28 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
一、半加器
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;


三、四位加法器
一)元件化全加器實現(xiàn)
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;

二)循環(huán)語句實現(xiàn)
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;
三)子程序?qū)崿F(xiàn)
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的值,可以改變運算位數(shù)--------
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循環(huán)語句必須在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;

四、八位二進制數(shù)相加
一)元件化實現(xiàn)
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;

二)循環(huán)語句實現(xiàn)
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;
三)子程序?qū)崿F(xiàn)
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
分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復

使用道具 舉報

您需要登錄后才可以回帖 登錄 | 立即注冊

本版積分規(guī)則

手機版|小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術(shù)交流QQ群281945664

Powered by 單片機教程網(wǎng)

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 欧美成人精品 | 午夜影院免费体验区 | 亚洲国产精品日韩av不卡在线 | 日本爱爱| 亚洲+变态+欧美+另类+精品 | 成人黄色在线视频 | 精品国产精品三级精品av网址 | www.日韩系列 | 国产91久久精品一区二区 | 国产黄色小视频在线观看 | 精品96久久久久久中文字幕无 | 日韩在线观看网站 | 欧美精品福利 | 欧美五月婷婷 | 欧美一区二区三区在线观看 | 欧美成人第一页 | 欧美精品一区二区三区四区五区 | av网站免费观看 | 欧美成视频 | 欧美综合在线视频 | 亚洲综合久久精品 | av三级| 久久丝袜| 亚洲精品中文字幕中文字幕 | 国产欧美精品区一区二区三区 | 久久久亚洲成人 | 免费特黄视频 | 亚洲成人免费电影 | 久久成人一区 | 91动漫在线观看 | 国产精品视频yy9299一区 | caoporn免费| 国产91网址 | 韩国精品一区 | 精品99久久久久久 | 日韩一区二区三区在线播放 | 久久久久久国产精品 | 免费午夜视频在线观看 | 四虎影| 日韩在线| 99re在线视频 |