所以,我必須創建一個帶進位和執行的通用N位加法器。 我迄今做了兩個完全工作的體系結構中,一個使用所述生成功能,使用一個RTL描述如下:通用加法器「推理體系結構」:模擬錯誤
實體:
library ieee;
use ieee.std_logic_1164.all;
use ieee.numeric_std.all;
entity adder_n is
generic (N: integer:=8);
port (
a,b: in std_logic_vector(0 to N-1);
cin: in std_logic;
s: out std_logic_vector(0 to N-1);
cout: out std_logic);
end adder_n;
架構1和2:
--STRUCT
architecture struct of adder_n is
component f_adder
port (
a,b,cin: in std_logic;
s,cout: out std_logic);
end component;
signal c: std_logic_vector(0 to N);
begin
c(0)<=cin;
cout<=c(N);
adders: for k in 0 to N-1 generate
A1: f_adder port map(a(k),b(k),c(k),s(k),c(k+1));
end generate adders;
end struct;
--END STRUCT
architecture rtl of adder_n is
signal c: std_logic_vector(1 to N);
begin
s<=(a xor b) xor (cin&c(1 to N-1));
c<=((a or b) and (cin&c(1 to N-1))) or (a and b);
cout<=c(N);
end rtl;
現在,我的問題在於我試圖推斷加法器的第三種架構。儘管我創建的以下體系結構編譯得很好,但當我嘗試模擬它時,我在模擬結果處得到了一個模擬錯誤(在Modelsim上)。 我猜numeric_std定義有問題。我試圖避免arith庫,我仍然試圖去適應IEEE標準。 歡迎任何想法!謝謝!
推理拱:
--INFERENCE
architecture inference of adder_n is
signal tmp: std_logic_vector(0 to N);
signal atmp, btmp, ctmp, add_all : integer :=0;
signal cin_usgn: std_logic_vector(0 downto 0);
signal U: unsigned(0 to N);
begin
atmp <= to_integer(unsigned(a));
btmp <= to_integer(unsigned(b));
cin_usgn(0) <= cin;
ctmp <= to_integer(unsigned(cin_usgn));
add_all <= (atmp + btmp + ctmp);
U <= to_unsigned(add_all,N);
tmp <= std_logic_vector(U);
s <= tmp(0 to N-1);
cout <= tmp(N);
end inference;
-- END
仿真錯誤:
# Cannot continue because of fatal error.
# HDL call sequence:
# Stopped at C:/altera/14.1/modelsim_ase/test1_simon/adder_inference.vhd 58 Architecture inference
如果讀取可以識別'adder_n(推理)'中的第58行,它會有所幫助。 – user1155120
對於'U <= to_unsigned(add_all,N);'我顯示了一個綁定檢查錯誤。作業的左側和右側有不同的長度。 'U'的長度是N + 1,而'to_unsigned(add_all,N)'的長度是N的表達式爲N. – user1155120
它確實是一個長度問題,但是在改變U信號的長度後,我仍然得到相同的錯誤。順便說一句,第58行是你提到的路線。 完整的錯誤報告如下: >#**致命:(vsim-3420)數組長度不匹配。左是9(0到8)。正確的是8(7 downto 0)。 – Nailtha