VHDL 中的索引溢出 std_logic_vector
Index overflow in VHDL std_logic_vector
我对以下关于 len
的索引溢出的 VHDL 代码有疑问:
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
package mypack is
subtype small_int is integer range 0 to 3;
end mypack;
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
use work.mypack.all;
entity top is
port(
CLK : in std_logic;
rst : in std_logic;
myPtr : in small_int;
temp : in unsigned(1 downto 0);
myout : out std_logic_vector(3 downto 0));
end entity;
architecture rtl of top is
signal len : std_logic_vector(3 downto 0) := (others=>'0');
constant si : small_int := 1;
begin
myout <= len;
process(clk,rst) begin
if (RST='1') then
len <= "0000";
elsif rising_edge(CLK) then
len(myPtr - si) <= temp(0);
end if;
end process;
end architecture;
myPtr = 0
时的正确行为是什么:
len(3) <= temp(0);
会发生吗?
- 或者,会不会出现索引溢出的情况?这意味着,
len(3)
将始终保持在 0
。
提前致谢。
在模拟中,超出范围的索引值将产生错误。
在硬件中,超出范围的索引值会导致未定义的操作,因此可能会发生任何更新或不会发生更新。
我对以下关于 len
的索引溢出的 VHDL 代码有疑问:
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
package mypack is
subtype small_int is integer range 0 to 3;
end mypack;
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
use work.mypack.all;
entity top is
port(
CLK : in std_logic;
rst : in std_logic;
myPtr : in small_int;
temp : in unsigned(1 downto 0);
myout : out std_logic_vector(3 downto 0));
end entity;
architecture rtl of top is
signal len : std_logic_vector(3 downto 0) := (others=>'0');
constant si : small_int := 1;
begin
myout <= len;
process(clk,rst) begin
if (RST='1') then
len <= "0000";
elsif rising_edge(CLK) then
len(myPtr - si) <= temp(0);
end if;
end process;
end architecture;
myPtr = 0
时的正确行为是什么:
len(3) <= temp(0);
会发生吗?- 或者,会不会出现索引溢出的情况?这意味着,
len(3)
将始终保持在0
。
提前致谢。
在模拟中,超出范围的索引值将产生错误。
在硬件中,超出范围的索引值会导致未定义的操作,因此可能会发生任何更新或不会发生更新。