Verilog中的if语句和分配电线 [英] If statement and assigning wires in Verilog
本文介绍了Verilog中的if语句和分配电线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图弄清楚基于组合逻辑分配电线的基础.
I am trying to figure out the basics of assigning wires based on combinational logic.
我有:
wire val;
wire x;
wire a;
wire b;
always @*
begin
if(val == 00)
//I want to assign x = a
if(val == 01)
//I want to assign x = b
end
其中a
和b
是具有值的导线-x
是进入寄存器的导线.
where a
and b
are wires with values - and x
is a wire going into a register.
如果您能为我指出需要改变的正确方向,将不胜感激.
If you can point me in the right direction to what I need to change, it would be much appreciated.
推荐答案
首先要问的是:您是否试图将这些导线用作输入?还是使用这些作为连接? 第二件事:您想要一个可综合的代码吗? 而且您不能在Always块内分配电线,必须使用reg
First thing to ask is: are you trying to use those wires as inputs? Or are you using those as connections? Second thing: Do you want a synthesizable code? And you cant assign wires inside an always block, you have to use reg
因此,意见是:
//**************************************************************************************
module(a, b, out); //You have to define an interface, and all Verilog modules starts with module
input val[1:0]; //you have to use [] in order to indicate the length. In this case 2 bits, since you want to ask for 00;
input a;
input b;
output out;
reg x;
always @* //NOTE: You are describing combo logic, since there is no clock signal
begin
if(val == 2'b00)
x = a;
else if(val == 2'b01)
x = b;
else
x = 0; //If you are describing combo logic, you have to cover ALL val cases, in order to evade latches
end
assign out = x; //This is how you assign values in Verilog
endmodule
这篇关于Verilog中的if语句和分配电线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文