Ich habe einen Zweifel in folgenden VHDL-Code in Bezug auf Indexüberlauf von len
:Index Überlauf in VHDL std_logic_vector
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;
Was sollte die richtige Verhalten, wenn myPtr = 0
:
- Would
len(3) <= temp(0);
passieren? - Oder würde es einen Index über die Strömungssituation geben? Das heißt,
len(3)
bleibt immer bei0
.
Vielen Dank im Voraus.
Wenn myPtr = 0 und Sie ein Ereignis mit ansteigender Flanke haben, dann wäre len (myPtr-si) <= temp (0) len (0-1) <= temp (0) und Sie haben einen negativen Index ... und ich bin mir ziemlich sicher, dass das nicht in Ordnung ist. – 23ars
Das naheliegendste potentielle potentielle Problem ist, wenn MyPtr = 0 minus 1 (si) -1 ergibt, die außerhalb des Bereichs von MyPtr (small_int Bereich 0 bis 3) und außerhalb der Grenzen von len (3 downto 0) liegt. – user1155120
Genau das, was ich geschrieben habe! – 23ars