2014-10-20 31 views
0

我在二進制乘法電路中爲寄存器(製作移位寄存器電路)寫了一段VHDL代碼。一旦我在Quartus II中分析它,就會顯示幾個語法錯誤。用於寄存器的VHDL代碼,用於二進制乘法電路

這是我的代碼:

ENTITY memory IS 
PORT (can_load, can_shift, can_ad, sb_input, ab_input, UserInput : IN BIT; 
     Out_Bit, Z : OUT BIT); 
END memory; 

ARCHITECTURE logic OF memory IS 
    SIGNAL State: BIT := '0'; 
    BEGIN 
     IF (can_load = '1') THEN 
      State <= UserInput; 
     ELSE 
      IF (can_ad = '1') THEN 
       Z <= State; --Z is the output that goes to the 4 bit adder 
       State <= ab_input; 
      END IF; 
      IF (can_shift = '1') THEN 
       Out_Bit <= State; 
       State <= sb_input; 
      END IF; 
     END IF; 
END logic; 

這是錯誤消息:

信息:********************** *********************************************

信息:運行Quartus II 64位分析&合成 信息:版本14.0.0構建200 06/17/2014 SJ網絡版 信息:正在處理:Sun Oct 19 16:28:22 2014 Info:Versi on 14.0.0 Build 200 06/17/2014 SJ Web版 信息:正在處理:Sun 10月19日16:28:22 2014

信息:命令:quartus_map --read_settings_files = on --write_settings_files =關閉內存 - C內存

警告(20028):並行編譯未獲得許可,已被禁用

錯誤(10500):VHDL語法錯誤在memory.vhd(9)近文字 「IF」;錯誤(10500):memory.vhd(9)在文本附近發生VHDL語法錯誤「THEN」時出現「end」或「(」或標識符(「if」是保留關鍵字)或併發語句錯誤(10500) 「;期待」< =「

錯誤(10500):memory.vhd(11)在文本」ELSE「附近出現VHDL語法錯誤;期待」結束「,或」(「或標識符(」else「保留關鍵字),或併發語句

錯誤(10500):在memory.vhd(12)附近的文本 「THEN」 VHDL語法錯誤;需要 「< =」

錯誤(10500):VHDL語法memory.vhd錯誤(15)文字「IF」附近; (10500):在文本「THEN」附近的memory.vhd(16)處出現VHDL語法錯誤;或者(如果「if」是保留關鍵字)或「體系結構」。期望「< =」

錯誤(10500):memory.vhd(19)在文本「IF」附近的VHDL語法錯誤;期待 「;」,或標識符( 「如果」 是保留關鍵字),或 「結構」

信息(12021):實測值0設計單位,包括0的實體,在源文件memory.vhd

我已經檢查了幾本書的正確語法和代碼示例,但是我找不到我的錯誤在哪裏。

我也試圖帶走括號中的部分是這樣的:

IF (can_load = '1') THEN 

有這樣的事情:

IF can_load = '1' THEN 

但我結束了與大多數相同的語法錯誤。

我很感謝任何幫助解決這個問題。謝謝。

+0

如果... THEN是一個順序語句。您正在架構的並行處理區域中使用它。在體系結構內的進程中使用它。 – 2014-10-20 00:09:23

+0

謝謝你,我做到了,它工作。我不知道我不能在程序之外使用IF ... THEN。 – DAVID 2014-10-22 03:04:03

回答

0

我使用不同的工具來演示錯誤:

ghdl -a memory.vhdl
memory.vhdl:9:9:一個生成的語句必須有標籤
memory.vhdl:9 :29:「產生」可望而不是「然後」
ghdl:編譯錯誤

注意分析儀抱怨一個生成的語句。這是因爲if語句是僅在進程或其他併發語句或子程序中找到的順序語句。

帶條件方案的生成語句(因此if)是一個併發進程語句,需要一個標籤。

把if語句的過程:

entity memory is 
port (can_load, can_shift, can_ad, sb_input, ab_input, userinput : in bit; 
     out_bit, z : out bit); 
end memory; 

architecture logic of memory is 
    signal state: bit := '0'; 
begin 
SOME_PROCESS: 
    process (userinput, ab_input, state, sb_input) 
    begin 
     if can_load = '1' then 
      state <= userinput; 
     else 
      if can_ad = '1' then 
       z <= state; --z is the output that goes to the 4 bit adder 
       state <= ab_input; 
      end if; 
      if can_shift = '1' then 
       out_bit <= state; 
       state <= sb_input; 
      end if; 
     end if; 
    end process; 
end logic; 

分析。

注意我加userinputab_inputstate,並且sb_input的過程敏感列表(一切,出現了在賦值語句的右側)。

state的存在也提出了另一點。在當前模擬週期中,新值state不可用。在你的例子中,out_bit的值將是執行該過程之前發現的值state

而且在大多數情況下,if語句條件中的括號是多餘的。當左側右側評估順序不足以確定正確含義時(例如混合運算符andor),運算符是函數並且函數是表達式,則需要括號。

+0

謝謝。你的回答非常有幫助。我會確保考慮到你的所有建議。 :) – DAVID 2014-10-22 03:06:44