为什么在我的单周期架构实现中输出没有改变/没有加载?

问题描述 投票:0回答:1

我编写了单周期MIPS架构的代码,它实现了add,sub,multiply和divide。有一个2D Reg阵列,一个控制单元,一个ALU。我想我已经把它写得很好了,但我放在测试台上的操作码似乎没有进入过程:输出完全没有改变,我无法理解为什么。谁能告诉我为什么?

////////////////////////////////////////////fixed
module registermemory(
input [3:0]Ra, Rb, Wa, Wd,
input write, input clk,
output [3:0] A,B
);

reg [15:0] memarray [3:0]; 

integer i;
initial begin
	for(i=0;i<=15;i=i+1)
		memarray[i]<=4'b0101; ///when the entire 2D array has same value?
end
		
integer r1,r2,w1;
always@(clk)
begin
r1=Ra;r2=Rb;w1=Wa;
end

assign A = memarray[r1];
assign B = memarray[r2];//assign used outside always. equal to used inside always.
always@(Wd)
	begin	
		if(write)
			memarray[w1]=Wd;
		end
		
endmodule
///////////////////////////////
module controlblock(opcode,cntrl,Ra,Rb,Wa,write);
input [13:0]opcode;
output reg[1:0]cntrl;
output reg[3:0]Ra;
output reg[3:0]Rb;
output reg[3:0]Wa;
output reg write; //control signal tells that register has to be written in reg file


always@(opcode) ///why @opcode tho?
begin
cntrl=opcode[13:12];            
Ra=opcode[11:8];
Rb=opcode[7:4];
Wa=opcode[3:0];
write=1; //why tho?
end

endmodule
///////////////////////////////
module alu_arith(input[3:0]A, input[1:0] cntrl,
input clk,  
input[3:0]B,
output reg[3:0]Wd
);

always@(clk)
begin
case(cntrl)
	00:Wd=A+B;
	01:Wd=A-B;
	10:Wd=A*B;
	11:Wd=A/B;
default: Wd=4'b0000;
endcase
end
	
endmodule

///////////////////////////////////////////////////////
module concat(input [0:13]opcode, input clk, output[3:0]Wd);

wire[3:0]Ra;wire[3:0]Rb;wire[3:0]Wa;wire written;wire[1:0]cntrl;
wire[3:0]A;wire[3:0]B;wire[3:0]Wd;

controlblock a1(opcode,cntrl,Ra,Rb,Wa,write); //

registermemory a2(Ra, Rb, Wa, Wd,write,clk,A,B
); //

alu_arith a3(A,cntrl,clk,B,Wd); //
endmodule
//////////////////////////////////////////////////////////////
module testbench;
reg clk;
reg[13:0]opcode;
wire[3:0]Wd;
wire[1:0] cntrl;
reg[3:0]A,B;

concat a4(opcode,clk,Wd);

initial
clk=0;

always
#2 clk=!clk;
initial begin
	$display("\ttime \tclk  \tcntrl \tA  \tB  \tWd ");
    $monitor("%d,\t   \t%b   \t%b   \t%b   \t%b   \t%b",
    $time, clk, cntrl, A, B, Wd);
	
	#10 opcode=14'b00010010110100;
	#20 opcode=14'b01100010101010;
end

initial
#50 $finish;	

		
endmodule
verilog cpu-architecture
1个回答
1
投票

您将memarray错误地称为16位宽4字深存储器。你想要一个4位宽乘16深:

reg [3:0] memarray [0:15]; 

当我做出这个改变时,我看到Wd输出发生了变化。

© www.soinside.com 2019 - 2024. All rights reserved.