有符号类型(signed):byte int integer time
无符号类型(unsigned):bit logic reg
二值逻辑:bit byte short int int long int
四肢逻辑:logic reg wire integer
////////////signed vs unsigned/////////////////
initial begin: signed_vs_unsigned
byte b0; //signed
bit[7:0] b1; //unsigned
b0 = 'b1000_0000;
$display("byte variable b0 = %d", b0);
b1 = b0;
$display("bit vector variable b1 = %d", b1);
end
b0为 byte类型 有符号 最高位1代表负数,b0=-128;
b1为bit类型 无符号 b1=128;
对于四状态类型的数据,缺省值为X,双状态类型的数据,缺省值是0. 四状态的X\Z转换为二状态后为0;
//////////struct type////////////
initial begin: struct_type
typedef struct {
bit[7:0] addr;
bit[31:0] data;
bit is_write;
int id;
} trans_t;
trans_t t1, t2, t3;
t1 = '{'h10, 'h1122_3344, 'b1, 'h1000};
$display("t1 data content is %p", t1); // t1 data content is '{addr:'h10, data:'h11223344, is_write:'h1, id:4096}
//体会此种结构体的输出方式,可用于tc中的数据包打印。
t2.addr = 'h20;
t2.data = 'h5566_7788;
t2.is_write = 'b0;
t2.id = 'h2000;
$display("t2 data content is %p", t2);
end