Verilog中的ALU,模拟时缺少输出
我用verilog编写了一个简单的ALU,如下所示:Verilog中的ALU,模拟时缺少输出,verilog,modelsim,alu,Verilog,Modelsim,Alu,我用verilog编写了一个简单的ALU,如下所示: input [15:0] in; output reg [15:0] out; reg [15:0] r [0:7]; reg [3:0] opcode; reg [3:0] outreg; reg [3:0] var1, var2; reg [15:0] a1, a2; parameter STO = 4'b0000; parameter ADD = 4'b0001; parameter MUL = 4'b0010; always @
input [15:0] in;
output reg [15:0] out;
reg [15:0] r [0:7];
reg [3:0] opcode;
reg [3:0] outreg;
reg [3:0] var1, var2;
reg [15:0] a1, a2;
parameter STO = 4'b0000;
parameter ADD = 4'b0001;
parameter MUL = 4'b0010;
always @ (in)
begin
opcode = in [15:12];
outreg = in [11:8];
var1 = in [7:4];
var2 = in [3:0];
a1 = (var1[3]) ? var1[2:0] : r[var1];
a2 = (var2[3]) ? var2[2:0] : r[var2];
case (opcode)
STO: begin r[outreg] = a1; end
ADD: begin r[outreg] = a1 + a2; end
MUL: begin r[outreg] = a1 * a2; end
SUB: begin r[outreg] = a1 - a2; end
DIV: begin r[outreg] = a1 / a2; end
default: begin $display("error input"); end
endcase
out = r[outreg];
end
在试验台上,我给出如下输入:
initial begin
$monitor("%d", out);
in = 16'h0280; #10; // STO r2, #0
in = 16'h00d0; #10; // STO r0, #5
in = 16'h01c0; #10; // STO r1, #4
in = 16'h2110; #10; // MUL r1, r1, r0
in = 16'h1221; #10; // ADD r2, r2, r1
end
结果应该是(正如我预测的那样)
是这样吗
但modelsim给出的答案如下:
0
5
4
20
并且没有输出
ADD r2, r2, r0
我对答案的预测正确吗?或者发生了什么问题?
$monitor
在每次参数值更改时显示其参数值。你怎么能期望两行20
相当于将其作为一个单独的过程编写
always @(out)
$strobe("%d", out); // like $display except prints only once at the end of the time slot
always @(in or out)
$strobe("%h %d", in,out); // like $display except prints only once at the end of the time slot
及
相当于将其作为一个单独的过程编写
always @(out)
$strobe("%d", out); // like $display except prints only once at the end of the time slot
always @(in or out)
$strobe("%h %d", in,out); // like $display except prints only once at the end of the time slot
一般来说,$monitor只适用于非常简单的情况,而应使用$display或$strobe 我看到的唯一一行是:
$monitor(“%d”,out)代码>我有5行输入$monitor(“%d”,out)代码>仅显示4个输出。。但是,$monitor(“%h,%d”,in,out)代码>可以显示5行。因为out
在20
之后不再更改。因此%h
会更改值,并且可以显示第二行20
。哦,我明白了。非常感谢您不,第二个20行之所以出现,是因为中的更改了hanks,我只发布了我代码的关键部分,SUB/DIV不用于测试,我忘了删除这两行,我可以处理其他问题查看我的答案!
always @(in or out)
$strobe("%h %d", in,out); // like $display except prints only once at the end of the time slot