vhdl - 如何在 VHDL 中正确使用断言?
问题描述
我在 VHDL 中有一个代码段,这让我不确定它是否正确:a 和 b 是 std_logic_vectors。c1 和 c0 是标准逻辑。这个写对了吗?尤其是“c1 = '1' and c0 = '0'”这部分让我很纠结。
if unsigned(a) > unsigned(b) then
assert(c1 = '1' and c0 = '0')
编辑:这是一个更大的代码段:
signal a: std_logic_vector(3 downto 0);
signal b: std_logic_vector(3 downto 0);
signal c1: std_logic;
signal c0: std_logic;
begin
TEST: forBitComperator port map(a, b, c1, c0);
process
begin
for i in 0 to 2**4-1 loop
for k in 0 to 2**4-1 loop
wait for 0 ns;
a <= conv_std_logic_vector(i, 4);
b <= conv_std_logic_vector(k, 4);
if i > k then
assert c1 = '1' and c0 = '0'
report "error ";
end if;
end loop;
end loop;
wait;
end process;
end;
解决方案
您不确定的部分是正确的。c0
, c1
,'0'
和'1'
都是std_logic
, 所以用这种方式比较它们是正确的。(在 VHDL=
中是相等比较运算符。它不执行赋值,就像在许多软件编程语言中一样)。每次比较的结果都是一个布尔值(true
或false
),因此可以与assert
语句一起使用。
我认为唯一错误的部分是您必须if
以end if
. 通常还建议每当您使用 时assert
,都会report
显示错误消息并设置 a severity
(例如note
、或warning
,具体取决于错误的严重程度)。当然,它也必须以 . 结尾。error
failure
;
所以:
if unsigned(a) > unsigned(b) then
assert c1 = '1' and c0 = '0' report "<Error message>" severity warning;
end if;
推荐阅读
- python - 用正则表达式替换python中两个标签周围的文本
- python - 如何使用环境变量子处理调用?
- r - 这个速度、年龄、里程和年份的公式是什么意思?
- wordpress - 如何根据页面链接动态显示联系表格7?
- sql-server - Microsoft SQL Server - 附加数据库版本失败问题
- c++ - 未解析的符号:链接到其他 cmake 包中包含的静态库
- python - 创建一个累积迭代的数组
- javascript - 一个 Next.js 路由中的两个不同子域
- c# - 如何定义一个接口方法,其不同的实现可以返回
, 列表 , 列表 - > 其中 T 是自定义类
- windows - 仅使用 Firesharp for Windows 桌面推送通知