verilog - 为什么在我的单周期架构实现中输出没有改变/没有加载?
问题描述
我已经为实现加、减、乘和除的单周期 MIPS 架构编写了代码。有一个 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
解决方案
您memarray
错误地声明为 16 位宽 x 4 字深存储器。你想要一个 4 位宽 x 16 位深:
reg [3:0] memarray [0:15];
当我进行此更改时,我看到Wd
输出发生了变化。
推荐阅读
- amazon-web-services - 无法连接到 RDS 写入器端点
- javascript - Firebase:未捕获的语法错误:无效或意外的令牌->未捕获的参考错误
- node.js - NRWL NX - 为什么我在运行“ng serve express”时得到“找不到名称‘describe’”?
- constraint-programming - 载客量受限的载客车辆路线问题
- xslt - XSL 不会写 xmlns:xsl?
- javascript - chartjs:需要 yAxis 比例附近的彩条
- c++ - c ++将模板化函数应用于元组的每个元素
- javascript - 使用 django REST 和 Vue.js 传播不可迭代实例的无效尝试
- ruby-on-rails - 配置异常在生产模式下启动 Web 应用程序 Ruby
- optimization - 在c中具有多重撤消/重做的文本编辑器