Verilog中net和 register声明语法 举例: reg ai //一个标量寄存器 wand w;//一个标量wand类型net reg[3:0]v;//从MsB到LsB的4位寄存器向量 reg[7:0]m,n;//两个8位寄存器 tri[15:0]busa;//16位三态总线 wire[o:31]w1,w2;//两个32位wire,MsB为bit0
Verilog中net和register声明语法 • 举例: reg a; //一个标量寄存器 wand w; // 一个标量wand类型net reg [3: 0] v; // 从MSB到LSB的4位寄存器向量 reg [7: 0] m, n; // 两个8位寄存器 tri [15: 0] busa; // 16位三态总线 wire [0: 31] w1, w2; // 两个32位wire,MSB为bit0
选择正确的数据类型 输入端口可以由 输出端口可以是 net/ register驱动,但输 net/ register类型,输出 入端口只能是net 端口只能驱动net 双向端口输入输出只 in2 能是ne类型 module topi module DUT (Y A b)i wIre y output yi reg a, bi 若Y,A,B说明为 input A,B;∠re则会产生错误 DUT ul(y, a, b)i w工xeY,A,B initial begin and (Y A b) 0;b=0; endmodule #5a end 在过程块中只能给 register类型赋值 endmodule
选择正确的数据类型 module top; wire y; reg a, b; DUT u1 (y, a, b) ; initial begin a = 0; b = 0; #5 a = 1; end endmodule module DUT (Y, A, B); output Y; input A, B; wire Y, A, B; and (Y, A, B) ; endmodule 输入端口可以由 net/register驱动,但输 入端口只能是net 输出端口可以是 net/register类型,输出 端口只能驱动net 在过程块中只能给 register类型赋值 若Y,A,B说明为 reg则会产生错误。 in1 in2 O A B Y 双向端口输入/输出只 能是net类型
选择数据类型时常犯的错误 信号类型确定方法总结如下: 信号可以分为端口信号和内部信号。出现在端口列表中的信号是端口信号,其它的信号为内 部信号。 对于端口信号,输入端口只能是n类型。输出端口可以是net类型,也可以是 register类型。若 输出端口在过程块中赋值则为 register类型;若在过程块外赋值包括实例化语句),则为n类 型 内部信号类型与输出端口相同,可以是ne或 register类型。判断方法也与输出端口相同。若在 过程块中赋值,则为 Register类型;若在过程块外赋值,则为net类型。 若信号既需要在过程块中赋值,又需要在过程块外赋值。这种情况是有可能出现的,如决断 信号。这时需要一个中间信号转换。 下面所列是常出的错误及相应的错误信息 error message) 用过程语句给一个ne类型的或忘记声明类型的信号赋值。 信息: illegal… assignment 将实例的输出连接到声明为 Register类型的信号上。 信息:<name> has illegal output port specification 将模块的输入信号声明为 register类型 信息: incompatible declaration,< signal name>……
选择数据类型时常犯的错误 • 用过程语句给一个net类型的或忘记声明类型的信号赋值。 信息:illegal …… assignment. • 将实例的输出连接到声明为register类型的信号上。 信息:<name> has illegal output port specification. • 将模块的输入信号声明为register类型。 信息:incompatible declaration, <signal name> …… 下面所列是常出的错误及相应的错误信息(error message) • 信号可以分为端口信号和内部信号。出现在端口列表中的信号是端口信号,其它的信号为内 部信号。 • 对于端口信号,输入端口只能是net类型。输出端口可以是net类型,也可以是register类型。若 输出端口在过程块中赋值则为register类型;若在过程块外赋值(包括实例化语句),则为net类 型。 • 内部信号类型与输出端口相同,可以是net或register类型。判断方法也与输出端口相同。若在 过程块中赋值,则为register类型;若在过程块外赋值,则为net类型。 • 若信号既需要在过程块中赋值,又需要在过程块外赋值。这种情况是有可能出现的,如决断 信号。这时需要一个中间信号转换。 信号类型确定方法总结如下:
选择数据类型时常犯的错误举例 example. V 修改后 修改前: module example(ol, 02, a, b, c, d); module example(ol, 02, a, b, c, d); input a, b, c, d; input a, b, c, d: output ol, 02; output o1, 02 ∥/regc,d; regc. d: ∥/rego2 reg o2 reg ol and ul(o2, c, d); and ul(o2, c, d)= always @(a or b) always @(a or b) if(a)ol= b; else ol=0 if (a)ol=b; else ol=0 endmodule endmodule
选择数据类型时常犯的错误举例 修改前: module example(o1, o2, a, b, c, d); input a, b, c, d; output o1, o2; reg c, d; reg o2 and u1(o2, c, d); always @(a or b) if (a) o1 = b; else o1 = 0; endmodule 修改后: module example(o1, o2, a, b, c, d); input a, b, c, d; output o1, o2; // reg c, d; // reg o2 reg o1; and u1(o2, c, d); always @(a or b) if (a) o1 = b; else o1 = 0; endmodule example.v
选择数据类型时常犯的错误举例 Compiling source file example. v 第一次编译信息 Error! Incompatible declaration, (c)defined as input verilog-c examplev at line 2 IVerilog-IDDIL example.v,5: Error! Incompatible declaration, (d) defined as input at line 2 Verilog-IDDILI example.v, 5: Error! Gate(ul) has illegal output specification Verilog-GHIOSI example. v,8: 3 errors Compiling source file"example.v 第二次编译信息 Error! Illegalleft-hand-side assignment IVerilog-ILHSAI example. v,1l:01=b Error! Illegal left-hand-side assignment Ⅴ erilog- ILHSA example. v,12:01=0 2 errors
选择数据类型时常犯的错误举例 Compiling source file "example.v" Error! Illegal left-hand-side assignment [Verilog-ILHSA] "example.v", 11: o1 = b; Error! Illegal left-hand-side assignment [Verilog-ILHSA] "example.v", 12: o1 = 0; 2 errors 第一次编译信息 verilog –c example.v 第二次编译信息 Compiling source file "example.v" Error! Incompatible declaration, (c) defined as input at line 2 [Verilog-IDDIL] "example.v", 5: Error! Incompatible declaration, (d) defined as input at line 2 [Verilog-IDDIL] "example.v", 5: Error! Gate (u1) has illegal output specification [Verilog-GHIOS] "example.v", 8: 3 errors