在Quartus Prime V16.0上编译时,我在Verilog中遇到了这个模块的问题。目标是如果总共8个输入位中的任何一个位是1,则返回一个特定的8位数00011000的输出。这个if语句有效吗?如果不是,什么是更好的实现方法?运算符在返回1时是这样工作的吗?从我对它的研究来看。
or运算符的输入是4位A (in7:4)和4位B (in3:0)
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是定义为从Case3模块检索输出以供进一步使用的连接变量。
发布于 2017-10-04 14:03:12
您可以根据自己的目的执行类似以下代码的操作。
module case3 (in, out);
input [7:0] in;
output [7:0] out;
assign out[7:0] = (|in) ? 8'b00011000 : <Else Case>;
endmodule在这里,|in将对in的所有位执行or,并将返回单个位输出。因此,如果in的任何位为1,那么|in将返回1。
发布于 2017-10-03 00:08:59
正如上面的评论所说,甚至很难知道从哪里开始。所以,我将回答这个问题,希望通过我的回答,你会得到一些关于你应该去哪里的指导。如果这是家庭作业,那么恭喜你!-我已经为你做了家庭作业。不管是不是,如果你的意图是学习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免责声明:我没有测试过这一点。(我怎么能呢?其中有一点缺失。)
https://stackoverflow.com/questions/46524785
复制相似问题