用VHDL实现两个BCD码相加

一木 2.3K 0
BCD码就是二进制表示十进制,只能从0000到1001
注意实体名和文件名要一致
library ieee;
use ieee.std_logic_1164.all;
use ieee.std_logic_unsigned.all;
entity bcd is
port(
		a,b:in std_logic_vector(3 downto 0);
		sum:out std_logic_vector(7 downto 0));
		end bcd;
		architecture rtl of bcd is
		signal temp :std_logic_vector(7 downto 0);
		begin
		temp<=("0000"&a)+("0000"&b);
		with temp select               --select语句记住用逗号
		sum<=temp+6 when"00001010"to"00010010",--加6就能与二进制一致
			temp   when "00000000"to"00001001",
			(others=>'Z')when others;
			end rtl;

发表评论 取消回复
表情 图片 链接 代码

分享