2013-02-18 50 views
0

我在做我自己的滾動/移動功能的學校工作。 下面是我寫的代碼,但是當我嘗試編譯它時,我在rownum上得到語法錯誤< = rol(rowcount,1);VHDL位旋轉函數語法錯誤?

library ieee; 
use ieee.std_logic_1164.all; 
use ieee.numeric_std.all; 

architecture main of proj is 

function "rol" (a: std_logic_vector; n : natural) 
       return std_logic_vector is 
begin 
return std_logic_vector(unsigned(a) rol n); 
end function; 

signal rownum : std_logic_vector(2 downto 0); 
signal rowcount : std_logic_vector(2 downto 0); 

begin 

process begin 
wait until rising_edge(i_clock); 
**rownum<=rol(rowcount,1);** 

end process; 

end architecture main; 

回答

1

有幾件事情需要在這裏解決。

首先,你需要一個實體聲明:

entity proj is 
    port(
    i_clock : in std_logic 
    ); 
end proj; 

這聲明什麼信號是你的實體的輸入和輸出。在這種情況下,它只是一個時鐘。您可以根據需要添加rownum和rowcount輸入和輸出。

您的函數名不應該以引號括起來,並且重載現有的運算符也不是一個好主意。

function rol_custom (a: std_logic_vector; n : natural) 
      return std_logic_vector is 
begin 
return std_logic_vector(unsigned(a) rol n); 
end function; 

這裏的綜合代碼:

library ieee; 
use ieee.std_logic_1164.all; 
use ieee.numeric_std.all; 

entity proj is 
    port(
    i_clock : in std_logic 
    ); 
end proj; 

architecture main of proj is 

function rol_custom (a: std_logic_vector; n : natural) 
       return std_logic_vector is 
begin 
return std_logic_vector(unsigned(a) rol n); 
end function; 

signal rownum : std_logic_vector(2 downto 0); 
signal rowcount : std_logic_vector(2 downto 0); 

begin 

process begin 
wait until rising_edge(i_clock); 
rownum<=rol_custom(rowcount,1); 

end process; 

end architecture main; 

然而,即使現在應該綜合,結果將沒有任何意義,因爲行數並沒有被賦予了價值。爲了定義它,您可能需要添加一個基於特定條件(計數器?)來驅動信號的進程,或者將其作爲輸入添加到實體定義中。

0

如果您的向量代表數字,您應該爲它們使用數字類型。根據需要使用ieee.numeric_std庫和unsignedsigned類型。然後rol就會工作。你不需要創建自己的。