2012-05-04 56 views
3

在Verilog中我有一個錯誤,我無法過去。這是代碼的第一位,然後最後一位未知的verilog錯誤'期待'endmodule''

module Decoder(op,funct,aluop,mwr,mreg,mrd,alusrc,regdst,regwr,btype); 
    input[5:0] op,funct; 
    output[2:0] aluop; 
    output[1:0] btype; 
    output mwr,mreg,mrd,alusrc,regdst,regwr; 
    wire aluop,mwr,mreg,mrd,alusrc,regdst,regwr,btype; 
    case(op) 
     6'b000000: begin 
      case(funct) 
       6'b001010: 
        assign aluop = 3'b010; 
       6'b001100: 
        assign aluop = 3'b111; 
       6'b010001: 
        assign aluop = 3'b011; 
       default: 
        assign aluop = 3'b000;   
      endcase 
      assign btype = 2'b00; 
      assign mwr = 1'b0; 
      assign mreg = 1'b0; 
      assign mrd = 1'b0; 
      assign alusrc = 1'b0; 
      assign regdst = 1'b1; 
      assign regwr = 1'b1; 
      end 

...

default: begin 
     assign aluop = 3'b000; 
     assign mwr = 0; 
     assign mreg = 0; 
     assign mrd = 0; 
     assign alusrc = 0; 
     assign btype = 2'b00; 
     assign regdst = 0; 
     assign regwr = 0; 
     end 
endcase 

endmodule

它不斷給我下面的錯誤

錯誤(10170):Decoder.v(7)附近的Verilog HDL語法錯誤文本「case」;期望「endmodule」 錯誤(10170):Decoder.v(14)附近的文本「6」處的Verilog HDL語法錯誤;期待「endmodule」

它也做到這一點,在每個月底聲明,默認和ENDCASE

我不知道爲什麼它這樣做,我是相當新的VERILOG。

在此先感謝

回答

6

我相信你只允許使用一個case陳述或if/elsealways塊內。我不知道爲什麼你的錯誤信息沒有提供更多有用的信息,但這可能是問題所在。

嘗試重寫類似下面的代碼:

//change wire types to reg type 

always @* 
begin 
    case (op) 
    6'b000000: begin 
     aluop = 3'b000 
    end 
    ... 
    endcase 
end 
+0

儘管解碼器理論上不應該使用寄存器。它真的很重要,但它們是否是寄存器? –

+0

@AlexMousavi僅僅因爲你使用'reg'數據類型並不一定意味着它被合成到一個寄存器。只要解碼器中沒有「保留狀態」,合成就會創建合適的組合邏輯。你可以閱讀這個更多的信息http://www.asic-world.com/tidbits/wire_reg.html – Tim

+0

非常感謝,它的工作。 –

2

這是一個猜測,但是編譯器是抱怨,因爲它很可能是期待IEEE 1364-2001 Verilog和你的代碼是不適用於此版本語言。無論如何,Tim的代碼可能是你正在尋找的功能。

至於爲什麼它無效,Verilog在每個模塊聲明中基本上包含兩個「上下文」。任何直接出現在模塊中的東西都是一個模塊項目。這些包括reg/wire聲明,assign語句,always語句,生成結構和模塊實例。

module mod; 

reg reg1;   //Module item 
wire wire1;   //Module item 
assign wire1 = 0; //Module item 
always reg1 = 0; //Module item 
parameter con1 = 0; //Module item 
//Instances a different module based on con1 
case(con1)   //Module item 
    0:mod2 inst1(reg1); 
    1:mod3 inst1(reg1); 
    2:mod4 inst1(reg1); 
endcase 

endmodule 

其次,有過程上下文中可以有程序語句。這是任務聲明,函數聲明,始終阻塞,初始塊和其他幾個區域內的任何代碼。

module mod2; 
reg a; 

always 
    begin 
    a = 0; //Procedural statement 
    end 

initial 
    a = 0; //Procedural statement 

function func1(input arg1); 
case (arg1) //Procedural statement 
    0:func1 = 0; 
    default:func1 = 9; 
endcase 
endfunction 

endmodule 

自2001年以來,Verilog包含兩種類型的case語句,程序性case語句和生成case語句。程序性案例陳述就像程序性語言一樣工作,但必須出現在程序性上下文中。生成case語句在模擬開始之前進行靜態評估,並且可能僅作爲模塊項出現在模塊聲明上下文中。請注意,第二個上下文需要大小寫表達式不變。

在Verilog的最新版本1364-2005中,生成案例可能直接出現在模塊範圍內,但是在2001版本的語言中,任何生成項目必須用generate..endgenerate關鍵字包圍。如果您的編譯器期待IEEE 1364-2001,那麼您看到的錯誤消息是有道理的。

+0

不理解這個答案的一個詞。你可以嗎?簡化 – AAI