2016-06-21 60 views
1

我在組合賦值時遇到了問題。我不明白爲什麼我不能使用總是組合結構集合我的輸出變量。當我使用分配時,我沒有得到分配錯誤。Verilog:在賦值的左側必須具有可變數據類型

我想分配,總是@(*)都來阻擋(組合分配)

module control_unit(input wire [31:0] instruction 
        ,output wire RegDst 
        ,output wire ALUSrc 
        ,output wire RegWrite 
        ,output wire MemRead 
        ,output wire MemWrite 
        ,output wire MemToReg 
        ,output wire Branch 
        ); 

    wire [5:0] opcode; 

    assign opcode = instruction[31:26]; 

    [email protected](*) begin 
     case(opcode) 
      6'b000000: begin    // r-type 
       RegDst = 1'b1; 
       ALUSrc = 1'b0; 
       RegWrite = 1'b1; 
       MemRead = 1'b0; 
       MemWrite = 1'b0; 
       MemToReg = 1'b0; 
       Branch = 1'b0; 
      end 
      . 
      . 
      .      
      default: begin 
       RegDst = 1'b0; 
       ALUSrc = 1'b0; 
       RegWrite = 1'b0; 
       MemRead = 1'b0; 
       MemWrite = 1'b0; 
       MemToReg = 1'b0; 
       Branch = 1'b0; 
      end 
     endcase 
    end // end always_comb 
endmodule 

回答

5

你不能讓一個程序分配到wire。無論always塊是否描述順序或組合邏輯,您都必須對reg進行程序分配。使用以下端口聲明:

   ,output reg RegDst 
       ,output reg ALUSrc 
       ,output reg RegWrite 
       ,output reg MemRead 
       ,output reg MemWrite 
       ,output reg MemToReg 
       ,output reg Branch 
+0

我對線和區別之間的區別有點困惑。根據我的理解,電線用於連接輸入和輸出端口,而reg用於存儲信息?什麼時候爲什麼輸出需要成爲reg? – Sugihara

+0

@Jack:當你正在對它進行過程分配時,輸出需要是一個reg,例如在always塊中。 – toolic

+0

這是由於語義?或者有硬件原因嗎? – Sugihara

相關問題