輸入數組中獲得計數:Ram = {D D D D D 3 3 3 7 7 7 9 9 8 8};
我期待的輸出如下:在讀取存儲器陣列的內容時需要幫助,並在vhdl
Count = {0 0 0 4 0 0 0 3 2 2 0 0 0 5 0 0};
這就是計算出現的次數,比如有5個D,4個3,3個7,2個9和2個8,這樣Count數組在Dth指數中有5個,第3個指數中有4個,第7個指數中有3個,等等。
我的代碼如下:
architecture behav of Bitcount is
signal cnt: count_type := (others=> (others=>'0'));
use ieee.numeric_std.all;
begin
Countproc:process(clk)
begin
if (clk'event and clk='1') then
if Enable='1' then
if (Read_bit='1') then
for k in 0 to 15 loop
for i in 0 to 15 loop
if (Ram(k) = std_logic_vector(to_unsigned(i, 4)))then
cnt(i) <= cnt(i) + "01";
end if;
end loop;
end loop;
end if;
end if;
Count <= cnt;
end if;
end process Countproc;
end behav;
你應該解釋實際發生的事情。你也應該給一個[MCVE](http://stackoverflow.com/help/mcve)。 –
類型轉換太多(並且在示例中沒有聲明......請參閱MCVE)...更好地選擇類型,並且它會簡化,可能會讓您看到該錯誤。 –
我正在嘗試計數每個輸入存儲器陣列內容的發生次數。和count_type是 - type count_type是std_logic_vector(3 downto 0)的數組(0到15); –