If statement Verilog-If条件
在Quartus Prime V16.0上编译时,我在Verilog中遇到了此模块的问题。如果8个总输入位中的任何一位为1,则目标是以特定的8位数字[00011000]返回输出。这个if语句有效吗?如果没有,什么是更好的实施方法?操作员是否以这种方式返回1?根据我的研究,它的作用 or运算符的输入为[7:4]中的4位A和[3:0]中的4位BIf statement Verilog-If条件,if-statement,binary,switch-statement,logic,verilog,If Statement,Binary,Switch Statement,Logic,Verilog,在Quartus Prime V16.0上编译时,我在Verilog中遇到了此模块的问题。如果8个总输入位中的任何一位为1,则目标是以特定的8位数字[00011000]返回输出。这个if语句有效吗?如果没有,什么是更好的实施方法?操作员是否以这种方式返回1?根据我的研究,它的作用 or运算符的输入为[7:4]中的4位A和[3:0]中的4位B module case3 (in, out); input [7:0] in; output [7:0] out; wire x, y; assign
module case3 (in, out);
input [7:0] in;
output [7:0] out;
wire x, y;
assign x = 1;
if (x == or(y, in[7:4], in[3:0]))
assign out[7:0] = 8'b00011000;
endmodule
我的主模块中的函数调用如下所示:
case3 u3(
.in(SW[7:0]),
.out(wire3)
);
Wire3是一个wire变量,定义用于检索Case3模块的输出以供进一步使用。如上所述,甚至很难知道从何处开始。所以,我将回答这个问题,希望通过我的回答,你能得到一些关于你应该去哪里的指导。如果这是家庭作业,那么恭喜你我已经为你做了家庭作业。不管是不是,如果你想学习Verilog,那么你需要试着理解为什么它是这样写的 所以,假设您的规范是 如果8个总输入位中的任何一位为1,则目标是以特定的8位数字[00011000]返回输出 我认为像这样的事情会起作用:
module case3 (in, out); // This is very old-fashioned syntax. Since 2001, we've been writing
input [7:0] in; // module case3 (input [7:0] in, output reg [7:0] out);
output [7:0] out; // 'out' must be a 'reg'. By default outputs are wires and it is
reg[7:0] out; // illegal to assign to a wire from an 'always' block
always @(*) // 'if' is illegal outside an 'initial' block or an 'always' block.
// Verilog is NOT a programming language, it is a HARDWARE DESCRIPTION
// language. Lines inside a 'module' are NOT executed sequentially,
// but concurrently, ie all at once, just like hardware.
// Lines inside an 'initial' or 'always' block are executed sequentially:
// think of an 'always' block is "a little bit of software that models
// a little bit of hardware".
if (in) // if 'in' is non-zero, Verilog considers it to be 'true'
out = 8'b00011000; // don't say 'assign' - it is legal here, but means something weird
// and there is no need to say out[7:0]
else
out = // who knows? You didn't say.
endmodule
免责声明:我没有测试过这个。我怎么能?缺少一点。您可以根据需要执行以下代码
module case3 (in, out);
input [7:0] in;
output [7:0] out;
assign out[7:0] = (|in) ? 8'b00011000 : <Else Case>;
endmodule
这里| in将对in的所有位进行oring,并返回一个位输出。因此,如果in的任何一位是1,那么| in将返回1。即使从这里开始也很难知道,但我建议回到你的课本,回顾一下Verilog原语的用法,你的'or'there'用法,赋值语句的用法3 always block。最后,你的问题陈述是不完整的。当输入都是0时会发生什么?即使这是合法的语法,也存在其他逻辑问题。只需添加到Brian的评论中,请同时查看您的术语,案例3不是一个函数。所以,首先开始阅读verilog hdl的概念。它不是一种通用编程语言。如果您的问题得到解决,请标记一个答案。@Serge out是reg,而不是导线。看看我代码的第4行。