vhdl - 使用无符号向量减法时如何检查结转?
问题描述
我尝试实现一个只有 8 位加减法器的架构。但是有一个问题我无法解决。当我使用减法器架构时,我需要计算进位,但我不能。
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use ieee.numeric_std.all;
entity sub is
port ( a : in std_logic_vector(7 downto 0);
b : in std_logic_vector(7 downto 0);
o : out std_logic_vector(7 downto 0)
);
end sub;
architecture Behavioral of sub is
signal a2,b2 : unsigned (7 downto 0);
begin
a2<=unsigned(a);
b2<=unsigned(b);
o<=std_logic_vector(a2-b2);
end Behavioral;
编辑:我说的是图片中的“c1”和“c5”信号。
解决方案
您需要将两个操作数都扩展一位,因此进位被收集在结果的 MSB 中。结果分解为进位位c
和减法结果o
。
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.numeric_std.all;
entity sub is
port (
a : in std_logic_vector(7 downto 0);
b : in std_logic_vector(7 downto 0);
o : out std_logic_vector(7 downto 0);
c : out std_logic
);
end entity;
architecture rtl of sub is
begin
(c, o) <= std_logic_vector(unsigned('0' & a) - unsigned('0' & b));
end architecture;
注意:这是 VHDL-2008 代码。
推荐阅读
- javascript - 如何使用 { } 执行箭头函数表达式
- bash - Makefile 中的这些行是什么意思?
- javascript - 未捕获的 TypeError:this.state.map 不是函数
- javascript - 管理员 lte 和数据表的问题
- scala - try-catch 在哪些情况下会捕获异常?
- elasticsearch - 弹性搜索服务器 7.1 未运行
- neo4j - 获取“neo4j.service:失败,结果为'start-limit-hit'。” 在安装 Neo4j Server 3.5.7
- sql - 如何仅获取最近加入的对?
- python - 拆分熊猫日期时间索引以创建分类变量
- vue.js - 无限滚动实现将数据渲染两次