2017-01-01 25 views
-3

數組我想創建一個名爲「A」的數組,並與任何二進制數如何使「的Verilog」(代碼中)

填補它和它的1-d陣列 我的代碼必須做的是SW在MIPS(存儲字) 'M',我想將其存儲在 'S'

謝謝你的價值,

module ALU(m,s,control,out,zeroflag,array); 

input [31:0] m,s; 
input [7:0] control; 
output reg [31:0] out; 
output reg zeroflag; 
reg a [0:2]; // this is the array 

a[2] = 4'b0000; // filled it.. 
a[1] = 4'b1001; 
a[0] = 4'b0110; 

always @(m,s,control,out,zeroflag,array) 
begin 
case(control) 
8'h2B : if(s==8'h0) a[0] = m; 
     out = a[0]; 
    else if(s==8'h1) a[1] = m; 
     out = a[1]; 
    else    a[2] = m; 
     out = a[2]; 

endcase 
end 

always @(out) 
begin 
if(out==0) 
zeroflag <= 1; 
else 
zeroflag <= 0; 
end 
endmodule 

////////////// ////////////////////////////

module test; 
reg [31:0] m,s; 
reg [7:0] control; 
wire [31:0] outpt; 
wire zeroflag; 

ALU rtypeoperations(m,s,control,outpt,zeroflag); 
initial 
begin 
m=32'b0000; s=8'h0; control=8'h2B; //stores m value in array[0] if s=8'h0, stores m value in array[1] if s=8'h1, stores m value in array[2] if s=8'h2, 
end 

initial 
begin 
$monitor("At time = %0t ,result = %b, zero flag = %b ",$time ,outpt,zeroflag); 
end 
endmodule 
+0

發生了什麼而不是您的預期? [數組上的這個問題](http://stackoverflow.com/questions/4846898/verilog-array-syntax)給你的解決方案? – giusti

+0

你需要一個時鐘'存儲單詞' – Greg

回答

0

我在代碼中看到很多問題。這甚至編譯?

首先,您的填充陣列的操作需要在初始塊內。

initial begin 
    a[2] = 4'b0000; // filled it.. 
    a[1] = 4'b1001; 
    a[0] = 4'b0110; 
end 

請注意,初始塊被允許用於FPGA RTL(FPGA能夠對初始值寄存器功率)和用於行爲(測試平臺)碼,但不適合的ASIC。

其次,你的總@(M,S,控制,出,zeroflag,陣列)包含在靈敏度列表輸出。它只應該是投入。

第三 - 你的代碼需要一些時鐘。現在,一切都是組合邏輯的寫法。

最後,學會正確地縮進你的代碼。以下是針對編碼指南的一條建議:https://github.com/NetFPGA/netfpga/wiki/VerilogCodingGuidelines