所以,我试图创建一个显示存储在寄存器库中的最高或最低值的代码(我们将在尝试显示任何内容之前存储一些值)。我的意思是使用一个通过寄存器组地址的计数器,并以某种方式使用比较器和寄存器来比较和存储中间值,但我的所有尝试都失败了。有什么建议吗?
这是我的注册银行,计数器的输出将连接到read_adress
但我不确定如何控制read_data
显示最高或最低值。
library IEEE;
use IEEE.STD_LOGIC_1164.ALL;
use IEEE.NUMERIC_STD.ALL;
entity b_reg is
Generic(m : integer := 4;
n: integer := 2
);
Port (
CLK : in STD_LOGIC;
clear : in STD_LOGIC;
write_data : in STD_LOGIC_VECTOR(m-1 downto 0);
write_adress : in STD_LOGIC_VECTOR(n-1 downto 0);
e_wr : in STD_LOGIC; -- enable writting
read_adress :in STD_LOGIC_VECTOR(n-1 downto 0); -- reading adress
read_data : out STD_LOGIC_VECTOR(m-1 downto 0) -- output
);
end b_reg;
architecture Behavioral of b_reg is
type r_array is array (0 to (2**n)-1) of std_logic_vector(m-1 downto 0);
Signal memoria: r_array;
begin
process(clear,CLK,e_wr) is
begin
if clear='1' then
for i in 0 to 2**n-1 loop
memoria(i) <= (OTHERS => '0');
end loop;
elsif RISING_EDGE(CLK) then
if e_wr ='1' then
memoria(TO_INTEGER(UNSIGNED(write_adress ))) <= write_data; -- writting
end if;
end if;
end process escrever;
process(CLK,memoria,read_adress) is
begin
read_data <= memoria(TO_INTEGER(UNSIGNED(read_adress))); -- reading
end process ler;
end Behavioral;