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

 找回密碼
 立即注冊

QQ登錄

只需一步,快速開始

搜索
查看: 22356|回復: 0
打印 上一主題 下一主題
收起左側

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

[復制鏈接]
跳轉到指定樓層
樓主
ID:51269 發表于 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;


三、四位加法器
一)元件化全加器實現
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
分享到:  QQ好友和群QQ好友和群 QQ空間QQ空間 騰訊微博騰訊微博 騰訊朋友騰訊朋友
收藏收藏 分享淘帖 頂 踩
回復

使用道具 舉報

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

本版積分規則

小黑屋|51黑電子論壇 |51黑電子論壇6群 QQ 管理員QQ:125739409;技術交流QQ群281945664

Powered by 單片機教程網

快速回復 返回頂部 返回列表
主站蜘蛛池模板: 国产精品久久国产精品99 | 国产精品123区 | 国产精品日产欧美久久久久 | 欧美精品一区二区三区在线播放 | 久久久久一区二区三区 | 91porn国产成人福利 | 日日摸日日爽 | 91久操视频| 久久婷婷香蕉热狠狠综合 | 久久国产成人 | 久久精品视频99 | 羞羞色视频 | 国产1区2区在线观看 | 天天操伊人 | 成人在线免费视频观看 | 日韩字幕一区 | 丁香久久 | 久久久一二三区 | 一级大黄 | 精品av| 最新伦理片 | 日韩成人在线观看 | 成人午夜电影在线观看 | 中文字幕日韩欧美一区二区三区 | 视频二区| 一区中文字幕 | 亚洲一区二区免费电影 | 91成人精品 | 亚洲色图图片 | 日韩欧美国产精品一区二区 | 操皮视频 | 久久国内 | 日批av| 中文字幕av第一页 | 国产精品色哟哟网站 | 一级黄色毛片 | 天天欧美 | www.久久久久久久久久久久 | 国产激情一区二区三区 | 欧美高清视频一区 | 丝袜美腿一区二区三区动态图 |