module data_type; // TODO-2: distinguish bit and logic initial begin: bit_vs_logic bit v1; logic v2; wait(b_bit_vs_logic == 1); $display("bit_vs_logic process block started"); v2 = 'bx; $display("logic variable v2 = %d", v2); v1 = v2; $display("bit variable v1 = %b", v1); v2 = 'bz; $display("logic variable v2 = %b", v2); v1 = v2; $display("bit variable v1 = %b", v1);
//不管z和x,bit都是0 end // TODO-3: enum type initial begin: enum_type typedef enum {IDLE, START, PROC, END} state_t; state_t st1, st2; wait(b_enum_type == 1); $display("enum_type process block started"); st1 = IDLE; $display("st1 value = %0d (int)", st1); $display("st1 value = %s (string)", st1); // implicit conversion $display("st1 value = %s (string)", st1.name()); st2 = state_t'(1); //注意此处赋值 $display("st1 value = %0d (int)", st2); $display("st1 value = %s (string)", st2.name()); end // TODO-4: struct type initial begin: struct_type typedef struct { //要试一下packet bit[7:0] addr; bit[31:0] data; bit is_write; int id; } trans_t; trans_t t1, t2, t3; wait(b_struct_type == 1); $display("struct_type process block started"); t1 = '{'h10, 'h1122_3344, 'b1, 'h1000}; //赋值 $display("t1 data content is %p", t1); // 结构体的输出%p,输出的是整形 t2.addr = 'h20; t2.data = 'h5566_7788; t2.is_write = 'b0; t2.id = 'h2000; $display("t2 data content is %p", t2); t3 = t2; t3.data = 'h99AA_BBCC; t3.id = 'h3000; $display("t3 data content is %p", t3); $display("t2 data content is %p", t2); end endmodule
// TODO-1 understand how to formulate a new string initial begin: string_format string s1, s2, s3, s4, s5; wait(b_string_format == 1);$display("string_format process block started"); s1 = "Welcome"; s2 = "www.rockeric.com"; s3 = {s1, " to ", s2}; // concatenation operator '{...}' $display("s3 content: %s", s3); s4 = $sformatf("%s to %s", s1, s2); // system format function $display("s4 content: %s", s4); s5 = $psprintf("%s to %s", s1, s2); // system format function 和{},sformatef一样的 $display("s5 content: %s", s5); end // TODO-2 understand how s3 is composed with s1 and s2 initial begin: string_builtin_function string s1, s2, s3; int i1; wait(b_string_builtin_function == 1); $display("string_builtin_function process block started"); s1 = "RockerIC is established in "; i1 = 2015; s2.itoa(i1); // integer converted to string “2015” $display("s2 = %s", s2); s3 = {s1.len()+s2.len(){" "}}; // 开辟空间,不开后面不能加入进来try to comment this line and check the result $display("s3 content: [%s]", s3); for(int i=0; i<s1.len()+s2.len(); i++) begin //拼接 s3[i] = i < s1.len() ? s1[i] : s2[i-s1.len()]; // s3[i] = i < s1.len() ? {s3,s1[i]} : {s3,s2[i-s1.len()]}; //如果不开辟空间,可以拼接 end $display("s3 content: %s", s3); end
标签:grammar,string,s2,t2,SV,st1,bit,display From: https://www.cnblogs.com/Dukefish/p/17092394.html