将 `others` 表达式与 `signed` cast 组合
Combining `others` expression with `signed` cast
设 var
代表大小为 m
的有符号向量(库 IEEE.NUMERIC_STD.ALL)。
设foo
为std_logic_vector(n-1 downto 0)
类型的另一个变量,其中n小于m。
我想连接 foo
左边的“0”,然后在右边用零填充它直到它的大小为 m
,然后将结果存储在 var
中。
我试过了
rdsor <= signed('0' & divisor & others=>'0');
但 Xilinx 抱怨合成时出现以下消息:
Syntax error near "others".
我该如何做我想做的事?
您需要使用 others
作为 聚合 的一部分,而不是 连接 的一部分。这是一个使用聚合和 属性 的解决方案(这取决于您使用 VHDL 2008):
rdsor <= (rdsor'LEFT => '0', (rdsor'LEFT-1) downto (rdsor'LEFT-divisor'LENGTH) => signed(divisor), others => '0');
假设 rdsor
等同于您的理论 var
并且除数等同于 foo
您可以在过程语句中使用两个赋值:
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity jsevillamol is
end entity;
architecture fum of jsevillamol is
constant M: natural := 42;
constant N: natural := 23;
signal rdsor: signed (M - 1 downto 0);
signal divisor: std_logic_vector (N - 1 downto 0);
begin
-- rdsor <= signed('0' & divisor & others=>'0');
process (divisor)
begin
rdsor <= (others => '0');
rdsor (rdsor'LEFT downto rdsor'LEFT - divisor'LENGTH)
<= signed('0' & divisor);
end process;
end architecture;
之所以可行,是因为 rdsor
的每个元素都是一个单独的信号,并且在 投影输出波形 中的任何特定时间只有一个值。通过在第二个分配的波形元素中不提供 after
time_expression,rdsor
切片的元素将被分配第二个分配表达式值。 (第一个分配的元素被第二个取代)。这种覆盖投影输出波形的方法通常用于在使用 if 语句覆盖不完整条件之前提供默认值。
这个例子分析、阐述和模拟,虽然没有做任何有趣的事情,但它证明了索引范围的构建是正确的。
请注意,它避免了 Matthew Taylor 的回答中提出的串联与聚合问题。
对于对工具 VHDL 修订不敏感的方法中的单个信号分配:
architecture fie of jsevillamol is
constant M: natural := 42;
constant N: natural := 23;
signal rdsor: signed (M - 1 downto 0);
signal divisor: std_logic_vector (N - 1 downto 0);
subtype other is signed (rdsor'LEFT - divisor'LENGTH - 1 downto 0);
begin
-- rdsor <= signed('0' & divisor & others=>'0');
rdsor <= '0' & signed(divisor) & other'(others => '0');
end architecture;
这使用串联并将 others
归入聚合。尾随的“0”部分有一个子类型声明,以允许聚合表达式成为限定表达式的目标。
该架构还分析、阐述和模拟证明索引算法是正确的。
设 var
代表大小为 m
的有符号向量(库 IEEE.NUMERIC_STD.ALL)。
设foo
为std_logic_vector(n-1 downto 0)
类型的另一个变量,其中n小于m。
我想连接 foo
左边的“0”,然后在右边用零填充它直到它的大小为 m
,然后将结果存储在 var
中。
我试过了
rdsor <= signed('0' & divisor & others=>'0');
但 Xilinx 抱怨合成时出现以下消息:
Syntax error near "others".
我该如何做我想做的事?
您需要使用 others
作为 聚合 的一部分,而不是 连接 的一部分。这是一个使用聚合和 属性 的解决方案(这取决于您使用 VHDL 2008):
rdsor <= (rdsor'LEFT => '0', (rdsor'LEFT-1) downto (rdsor'LEFT-divisor'LENGTH) => signed(divisor), others => '0');
假设 rdsor
等同于您的理论 var
并且除数等同于 foo
您可以在过程语句中使用两个赋值:
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity jsevillamol is
end entity;
architecture fum of jsevillamol is
constant M: natural := 42;
constant N: natural := 23;
signal rdsor: signed (M - 1 downto 0);
signal divisor: std_logic_vector (N - 1 downto 0);
begin
-- rdsor <= signed('0' & divisor & others=>'0');
process (divisor)
begin
rdsor <= (others => '0');
rdsor (rdsor'LEFT downto rdsor'LEFT - divisor'LENGTH)
<= signed('0' & divisor);
end process;
end architecture;
之所以可行,是因为 rdsor
的每个元素都是一个单独的信号,并且在 投影输出波形 中的任何特定时间只有一个值。通过在第二个分配的波形元素中不提供 after
time_expression,rdsor
切片的元素将被分配第二个分配表达式值。 (第一个分配的元素被第二个取代)。这种覆盖投影输出波形的方法通常用于在使用 if 语句覆盖不完整条件之前提供默认值。
这个例子分析、阐述和模拟,虽然没有做任何有趣的事情,但它证明了索引范围的构建是正确的。
请注意,它避免了 Matthew Taylor 的回答中提出的串联与聚合问题。
对于对工具 VHDL 修订不敏感的方法中的单个信号分配:
architecture fie of jsevillamol is
constant M: natural := 42;
constant N: natural := 23;
signal rdsor: signed (M - 1 downto 0);
signal divisor: std_logic_vector (N - 1 downto 0);
subtype other is signed (rdsor'LEFT - divisor'LENGTH - 1 downto 0);
begin
-- rdsor <= signed('0' & divisor & others=>'0');
rdsor <= '0' & signed(divisor) & other'(others => '0');
end architecture;
这使用串联并将 others
归入聚合。尾随的“0”部分有一个子类型声明,以允许聚合表达式成为限定表达式的目标。
该架构还分析、阐述和模拟证明索引算法是正确的。