Verilog提供了reg和wire数据类型,但是对于功能验证来说远远不够,所以SystemVerilog提供了很多更加丰富的数据类型,下面将一一介绍。
我们先来考古下,一开始Verilog中的“reg”是用来建模时序逻辑(触发器或者锁存器)的,后来对这个概念进行了扩展:
reg就是一个变量,也可以用来建模组合逻辑。
Systemverilog进一步进行了扩展,引入了logic变量,从此大一统。
另外,追随潮流。SystemVerilog还支持了面向对象的特性,以支撑功能验证环境的模块化和可重用需求。
整数数据类型可以不同维度进行划分:
下面是一个关于整数数据类型的示例:
integer a; //4 state - 32 bit signed
int b; //2 state - 32 bit signed
shortint c; //2 state - 16 bit signed
longint d; //2 state - 64 bit signed
logic [7:0] A1; //4-state - unsigned ‘logic’
logic signed [7:0] sl1; //4-state - signed ‘logic’
byte bl1; //2-state signed ‘byte’
reg [7:0] r1; //4-state - unsigned ‘reg’
initial
begin
a = 'h xxzz_ffff; //integer - 4 state - 32 bit signed
b = -1; //int - 2 state - 32 bit signed
c = 'h fxfx; //shortint - 2 state - 16 bit signed
d = 'h ffff_xxxx_ffff_zzzz;
//longint - 2 state - 64 bit signed
A1 = -1 ; //signed assignment to unsigned 'logic’
sl1 = -1; //signed assignment to signed 'logic'
bl1 = -1; //signed byte
r1 = 8'b xzxz_0101; //'reg' - unsigned 4-state
end
initial
begin #10;
$display("a = %h b = %h c = %h d = %h", a, b, c, d);
$display("A1 = %0d sl1=%0d bl1 = %0d r1 = %b",A1,sl1,bl1,r1);
#10 $fnish(2);
end
endmodule
在本例中,
在testbench中,我们为每个变量赋值不同的数字。其中一些赋值中有“x”,以显示2-state vs. 4-state变量如何处理“x”。
我们还为一些变量赋值正负值,看看signed vs. unsigned 变量的区别:
仿真log:
a = xxzzffff
b = ffffffff
c = f0f0
d = ffff0000ffff0000
A1 = 255
sl1= -1
bl1 = -1
r1 = xzxz0101
V C S S i m u l a t i o n R e p o r t
unsigned 4-state “logic” 和unsigned 4-state “reg”是等价的,它们之间没有区别。“reg”被保留是出于历史遗留的原因。
此外,还可以显式地将有符号的数字赋值给变量。例如,1 'sb1是有符号数赋值,而1 ' b1是无符号赋值。
logic [7:0] L1 ;//unsigned logic type
L1 = 4’sb1001; //= 8’b11111001 //Sign extension
L1 = 1’sb1; //= 8’b1111_1111 //Sign extensionL1 = 8’sb1; //= 8’b0000_0001 //NO sign extension because of //explicit width being same as vector declaration
L1 = 8’sbX; //=8’bxxxx_xxxx
原作者:验证哥布林
更多回帖