请看下面两段代码:
module PC(
input PCwr,clk,rst,Z,
input [31:0] NPC,
output reg [31:0] PC
);
always @(posedge clk) begin
if(!rst)
begin
PC <= 32'h0000_0000;
end
else begin
if(PCwr&Z)
begin
PC <= NPC;
end
else begin
PC <= PC;
end
//$display(PC);
end
end
endmodule
module PC(
input PCwr,clk,rst,Z,
input [31:0] NPC,
output reg [31:0] PC
);
always @(posedge clk) begin
if(!rst)
begin
PC <= 32'h0000_0000;
end
else begin
if(PCwr*Z)
begin
PC <= NPC;
end
else begin
PC <= PC;
end
//$display(PC);
end
end
endmodule
这两段代码在仿真时都可以通过,但上板后却出现不同的效果。
第一段是正确的,使用位运算在进行条件判断;第二段在仿真时可以正常运行,但在板上却没办法给PC赋成新的值,所以在写verilog的时候还是尽量使用位运算,上板子不容易出现这种错误,明明逻辑正确但无法得到预期结果。
可能的原因是*会调用乘法器,导致延迟的发生。