课上写全减器,题看错了,还以为是用生成语句把两个半减器和一个与门连成一个全减器。现在一看,原来是先生成一个全减器,再用原件例化生成8位全减器1.半减器
找到真值表:

代码:课上我是用两个with——select写的,忘记了vhdl也可以用数组的方式,注意with——select是直接放在结构体下的!
如果是给高阻态,一定大写的Z

--ujs-lili
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_unsigned.ALL;
entity sub_h_suber is
port(x,y:in std_logic;diff,s_out:out std_logic);
end sub_h_suber;
architecture Behavioral of sub_h_suber is
signal a,b: std_logic_vector(1 downto 0);
begina<=x&y;with a selectb<="00" when "00","11" when "01","10" when "10","00" when "11","ZZ" when others;  --大写的ZZ才可以!!!diff<=b(1);s_out<=b(0);
end Behavioral;——仿真代码
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
ENTITY sub_h_suber_tb IS
END sub_h_suber_tb;
ARCHITECTURE behavior OF sub_h_suber_tb IS  -- Component Declaration for the Unit Under Test (UUT)COMPONENT sub_h_suberPORT(x : IN  std_logic;y : IN  std_logic;diff : OUT  std_logic;s_out : OUT  std_logic);END COMPONENT;--Inputssignal x : std_logic := '0';signal y : std_logic := '0';--Outputssignal diff : std_logic;signal s_out : std_logic;-- No clocks detected in port list. Replace <clock> below with -- appropriate port name
BEGIN-- Instantiate the Unit Under Test (UUT)uut: sub_h_suber PORT MAP (x => x,y => y,diff => diff,s_out => s_out);-- Stimulus processstim_proc: processbegin  x<='0';y<='0';wait for 100 ns; x<='0';y<='1';wait for 100 ns;x<='1';y<='0';wait for 100 ns;x<='1';y<='1';wait for 100 ns;end process;
END;

做完别急,先仿真:


可以对照真值表看一下,对的!

2.一位全加器
找到真值表,来做仿真用


代码:

--ujs-lili
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.STD_LOGIC_unsigned.ALL;
entity sub_top isport(x,y,sub_in:in std_logic ;diffr,sub_out:out std_logic);--out忘记写!!!
end sub_top;
architecture Behavioral of sub_top is
component sub_h_suber is
port(x,y:in std_logic;diff,s_out:out std_logic);
end component sub_h_suber;
signal a,b,c : std_logic;
begin
u1:sub_h_suber port map(x=>x,y=>y,diff=>a,s_out=>b);
u2:sub_h_suber port map(x=>a,y=>sub_in,diff=>diffr,s_out=>c);--这个地方是两个都用sub_h_suber,标号不一样就可以
sub_out<=c or b;
end Behavioral;--仿真:
LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
ENTITY sub_tb IS
END sub_tb;
ARCHITECTURE behavior OF sub_tb IS COMPONENT sub_topPORT(x : IN  std_logic;y : IN  std_logic;sub_in : IN  std_logic;diffr : OUT  std_logic;sub_out : OUT  std_logic);END COMPONENT;  --Inputssignal x : std_logic := '0';signal y : std_logic := '0';signal sub_in : std_logic := '0';--Outputssignal diffr : std_logic;signal sub_out : std_logic;
BEGINuut: sub_top PORT MAP (x => x,y => y,sub_in => sub_in,diffr => diffr,sub_out => sub_out);stim_proc: processbegin  x<='0';y<='0';sub_in<='0';wait for 100 ns; x<='0';y<='0';sub_in<='1';wait for 100 ns;x<='0';y<='1';sub_in<='0';wait for 100 ns;x<='0';y<='1';sub_in<='1';wait for 100 ns;x<='1';y<='0';sub_in<='0';wait for 100 ns; x<='1';y<='0';sub_in<='1';wait for 100 ns;x<='1';y<='1';sub_in<='0';wait for 100 ns;x<='1';y<='1';sub_in<='1';wait for 100 ns;   end process;
END;

对照真值表看正确!

3.制作8位减法器,就是生成嘛!
注意点generate的port map之前一定要写原件名!!!
signal stmp:std_logic_vector(8 downto 0);
begin
stmp(0)<=sub_in;sub_out<=stmp(8);
会定义一个中间信号,9位的,第一位用来记录输入进位,最后一位记录输出进位,中间有7位进位是相互传递的,总的来说:外部给一个借位输入,先过第一个全减器,产生进位信号,给stmp,在传递给第二个全减器,那么这样过8个,很清楚,最后一个给sub_out
直接看原理图:
跟我想的不一样,我以为是8个sub串联那种,结果它给我总线形式:

代码:

--ujs-lili
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
entity sub8_top is
port(x,y:in std_logic_vector(7 downto 0);sub_in:in std_logic;diffr:out std_logic_vector(7 downto 0);sub_out:out std_logic);
end sub8_top;
architecture Behavioral of sub8_top is
component sub_top isport(x,y,sub_in:in std_logic ;diffr,sub_out:out std_logic);--out忘记写!!!
end component sub_top;
signal stmp:std_logic_vector(8 downto 0);
begin
stmp(0)<=sub_in;sub_out<=stmp(8);
gensub:for i in 0 to 7 generate
u1:sub_top port map(x(i),y(i),sub_in,diffr(i),stmp(i+1));
end generate;
end Behavioral;__仿真,你要是不懂借位的意思,你把它当作一位的做好了,就前7位都是0LIBRARY ieee;
USE ieee.std_logic_1164.ALL;
-- Uncomment the following library declaration if using
-- arithmetic functions with Signed or Unsigned values
--USE ieee.numeric_std.ALL;
ENTITY sub8_top_tb IS
END sub8_top_tb;
ARCHITECTURE behavior OF sub8_top_tb IS  -- Component Declaration for the Unit Under Test (UUT)COMPONENT sub8_topPORT(x : IN  std_logic_vector(7 downto 0);y : IN  std_logic_vector(7 downto 0);sub_in : IN  std_logic;diffr : OUT  std_logic_vector(7 downto 0);sub_out : OUT  std_logic);END COMPONENT;--Inputssignal x : std_logic_vector(7 downto 0) := (others => '0');signal y : std_logic_vector(7 downto 0) := (others => '0');signal sub_in : std_logic := '0';--Outputssignal diffr : std_logic_vector(7 downto 0);signal sub_out : std_logic;-- No clocks detected in port list. Replace <clock> below with -- appropriate port name
BEGIN-- Instantiate the Unit Under Test (UUT)uut: sub8_top PORT MAP (x => x,y => y,sub_in => sub_in,diffr => diffr,sub_out => sub_out);-- Stimulus processstim_proc: processbegin  x<="00000001";y<="00000000";sub_in<='0';wait for 100 ns; x<="00000001";y<="00000000";sub_in<='0';wait for 100 ns; x<="00000001";y<="00000001";sub_in<='1';wait for 100 ns; x<="11111111";y<="11111110";sub_in<='0';wait for 100 ns; x<="00000000";y<="00000000";sub_in<='0';wait for 100 ns; x<="00000000";y<="00000000";sub_in<='1';wait for 100 ns; x<="00000000";y<="00000001";sub_in<='0';wait for 100 ns; x<="00000000";y<="00000001";sub_in<='1';wait for 100 ns; x<="00000001";y<="00000001";sub_in<='1';wait for 100 ns; end process;
END;


比如看:
x=00000001,y=00000001,sub_in=1,其实x-y=0,你再借个位变成11111111
然后要是不懂400ns之后看,这就跟1位全减器一个意思。
4.总结
半加器,一位全加器(根据原理图连接),生成八位全加器(注意中间9位的信号)

vhdl入门8位全减器相关推荐

  1. (46)VHDL实现4位桶性形移位器

    (46)VHDL实现4位桶性形移位器 1.1 目录 1)目录 2)FPGA简介 3)VHDL简介 4)VHDL实现4位桶性形移位器 5)结语 1.2 FPGA简介 FPGA(Field Program ...

  2. (48)VHDL实现8位奇偶校验电路(process语句语句)

    (48)VHDL实现8位奇偶校验电路(process语句语句) 1.1 目录 1)目录 2)FPGA简介 3)VHDL简介 4)VHDL实现8位奇偶校验电路(process语句语句) 5)结语 1.2 ...

  3. (47)VHDL实现8位奇偶校验电路(for loop语句)

    (47)VHDL实现8位奇偶校验电路(for loop语句) 1.1 目录 1)目录 2)FPGA简介 3)VHDL简介 4)VHDL实现8位奇偶校验电路(for loop语句) 5)结语 1.2 F ...

  4. (49)VHDL实现8位奇偶校验电路(while loop语句)

    (49)VHDL实现8位奇偶校验电路(while loop语句) 1.1 目录 1)目录 2)FPGA简介 3)VHDL简介 4)VHDL实现8位奇偶校验电路(while loop语句) 5)结语 1 ...

  5. verilog复习与vhdl入门

    verilog复习与vhdl入门 1.Verilog回顾 基本结构 verilog以module为单位,module的基本结构: (1)模块声明(内含端口定义),如: ​ module ( ​ inp ...

  6. 原理图以及vhdl设计一位全加器

    原理图设计以及VHDL设计 一位加法器 全加器原理 全加器真值 输出表达式 原理图设计法 VHDL设计法 代码如下: 全加器是用门电路实现两个二进制数相加并求出和的组合线路,称为一位全加器.一位全加器 ...

  7. 用74l138实现一个一位全减器_用pygame实现一个简单的五子棋游戏

    准备 python基础相关准备: pygame的基础知识,参考目光博客的"用Python和Pygame写游戏-从入门到精通" 安装python 3.8.0 在python官网下载, ...

  8. PIC单片机入门_8位AD转换器

    1.前言 PIC16F876的模数转换器 (A/D) 模块有多达 8 个模拟输入通道.如果选择8位A/D 转换器,那么芯片可以将能将一个模拟输入信号转换成相应的 8 位数字信号.采样保持输出是转换器的 ...

  9. 用vhdl实现4位加减法计数器_频率计数器的使用方法介绍

    在目前的市场中测量时间/频率的设备普遍的有示波器,频谱仪和频率计数器三种,其中示波器在进行频率测量时相对测量精度较低误差较大.频谱仪可以准确的测量频率并显示被测信号的频谱,单相对测量速度较慢,无法实时 ...

  10. 用vhdl实现4位加减法计数器_32位加减法器设计

    功能特性 设计思路 基于一位全加器,设计32位并行加法器.并行加法器中全加器的位数与操作数相同,影响速度(延时)的主要因素是进位信号的传递.主要的高速加法器[1]有基本上都是在超前进位加法器(CLA) ...

最新文章

  1. u盘安装centos8黑屏_崩溃!电脑突然黑屏无法启动
  2. 三十、赫夫曼树的设计与代码实现
  3. VTK:可视化之HideAllActors
  4. 作者:王长波,华东师范大学教授、博士生导师、软件学院常务副院长。
  5. python xlwt设置单元格的自定义背景颜色
  6. hbase1.2.4安装
  7. 《企业IT架构转型之道》读书笔记
  8. OpenGLCG技术之Render To Texture
  9. log2 3用计算机怎么按,如何使用计算器计算对数log以2为底3的对数,由于计算器2ndf又叫shift,不同计算器不同,请根据图来,因为有一些别...
  10. Java负数除法和求余运算
  11. 三原色是红黄蓝对吗_为什么三原色是红黄蓝而?
  12. Tansat XCO2数据下载
  13. 微信小程序图片预览禁止保存
  14. java.lang.IllegalStateException: Already resumed, but proposed with update xxxx
  15. 使用XSSFWork创建的xlsx后缀Excel文件无法打开
  16. C语言大作业,可供学习---打字游戏
  17. 数字化转型思考的延伸问题
  18. 人民网报道金雅福集团董事长黄仕坤
  19. 外呼系统的四大技术原理,电销外呼系统常识
  20. Elasticsearch:Async search API

热门文章

  1. 苹果设备解锁工具iToolab UnlockGo Mac
  2. 计算机会考ppt考试,信息技术会考Powerpoint复习要点
  3. java阿拉伯数字转中文或金钱
  4. 电子邮件工作原理及主要协议
  5. 微型计算机原理与接口技术 教案,微机原理与接口技术课程教与学(教学大纲)...
  6. 行测题练习(7-29)【1】
  7. 2021 年 7 款优秀免费自动回复邮件工具(优缺点比较)
  8. Beini奶瓶U盘PE完整教程[2018-11-28]
  9. 基于微信小程序的校园论坛系统开发过程
  10. 编辑器使用方法 1. 下载编辑器 下载 KindEditor 最新版本,下载之后打开 examples/index.html 就可以看到演示。 下载页面: http://www.kindsoft.