如何解决8 位 ALU 的大问题,程序不会停止,我只需要验证在 verilog 中是否达到规范
我有一个 8 位 ALU 的大问题。首先,代码不会停止运行。其次,给出了规格表,我相信我遗漏了其中一些
这里是规格:
规格 数据输入:A(8 位)、B(8 位) 控制输入:S(1 位)、E(1 位) 输出:W(8位)
如果 E = 0,则输出 W 应为 0。如果 E = 1,则 W = A + B(S = 0)和 W = A - B(S = 1)。
代码如下:
/user/index
这是测试平台:
`timescale 1ns / 1ps
module ALU8bit( Opcode,Operand1,Operand2,Result,flagC,flagZ
);
input [2:0] Opcode;
input [7:0] Operand1,Operand2;
output reg [15:0] Result = 16'b0;
output reg flagC = 1'b0,flagZ = 1'b0;
parameter [2:0] ADD = 3'b000,SUB = 3'b001,MUL = 3'b010,AND = 3'b011,OR = 3'b100,NAND = 3'b101,nor = 3'b110,XOR = 3'b111;
always @ (Opcode or Operand1 or Operand2)
begin
case (Opcode)
ADD: begin
Result = Operand1 + Operand2;
flagC = Result[8];
flagZ = (Result == 16'b0);
end
SUB: begin
Result = Operand1 - Operand2;
flagC = Result[8];
flagZ = (Result == 16'b0);
end
MUL: begin
Result = Operand1 * Operand2;
flagZ = (Result == 16'b0);
end
AND: begin
Result = Operand1 & Operand2;
flagZ = (Result == 16'b0);
end
OR: begin
Result = Operand1 | Operand2;
flagZ = (Result == 16'b0);
end
NAND: begin
Result = ~(Operand1 & Operand2);
flagZ = (Result == 16'b0);
end
nor: begin
Result = ~(Operand1 | Operand2);
flagZ = (Result == 16'b0);
end
XOR: begin
Result = Operand1 ^ Operand2;
flagZ = (Result == 16'b0);
end
default: begin
Result = 16'b0;
flagC = 1'b0;
flagZ = 1'b0;
end
endcase
end
endmodule
非常感谢你们能为我提供的任何帮助。
解决方法
您的 count
变量的范围是 0 到 7。这意味着 count
将始终小于 8,您的 count < 8
表达式将始终为真。这导致 for
循环成为无限循环,这就是模拟永不停止的原因。
变化:
reg [2:0] count = 3'd0;
到:
integer count = 0;
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。