首页 > 其他分享 >SV-grammar

SV-grammar

时间:2023-02-04 22:13:29浏览次数:38  
标签:grammar string s2 t2 SV st1 bit display

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

相关文章

  • G6 Lesson2 Grammar
    GrammarWhatAretheFourKindsofSentence?adeclarativesentencemakesastatement.Itendswithaperiod.Aninterrogativesentenceasksaquestion.Itends......
  • 题解 G. Grammar Path 2020-2021 ICPC NERC (NEERC), North-Western Russia Regional
    传送门【大意】给定一个CNF和一个有向图。有向图上的每一条边都写上了一个字母。要求你从\(s\)到\(t\)走一条尽可能短的路,且将经过的字母写下来后,这个字符串能被......
  • G6 lesson1 grammar
    GrammarWhatisasentence?Asentenceisagroupofwordsthatexpressesacompletethought.Asentencemustincludeacompletesubject,allthewordsthatte......
  • SVG foreignObject All In One
    SVGforeignObjectAllInOneSVGforeignObjectThe<foreignObject>SVGelementincludeselementsfromadifferentXMLnamespace.Inthecontextofabrowser......
  • 推荐一个跨平台支持Word, Excel, CSV, Email等30多种格式的操作库
    更多开源项目请查看:一个专注推荐优秀.Net开源项目的榜单在我们日常项目开发中,经常需要解析操作文档,比如Office文档、Email文件、PDF、Xml、图片、Mp3等音频文件,操作Offi......
  • centerOS7下配置SVN
    1、获得管理员权限2.下载SVN2.1下载SVNyuminstallsubversion2.2查看版本svn--version3.创建SVN版本库3.1创建版本库目录sudomkdir-p/us......
  • svg格式的loading
    <svgxmlns="http://www.w3.org/2000/svg"width="1em"height="1em"fill="currentColor"viewBox="001616"><pathd="M11.411.6A5500138.2l1.21.2.8-.8-2-......
  • Ubuntu中SVN服务端安装
    1.apt命令安装svn客户端ubuntu@VM-0-3-ubuntu:~$sudoapt-getinstallsubversion2.创建svn目录ubuntu@VM-0-3-ubuntu:/$sudomkdir/home/svn3.创建项目仓库(yu......
  • python 将 csv转excel (.xls和.xlsx)的几种方式
    前言excel后缀有2种格式,.xls是从Excel97到Excel2003的默认文件格式,而.xlsx是Excel2007及更高版本的默认文件格式。.xlsx和.xls格式的主要区别在于,.xls格式......
  • vue3+vite npm run build报错TypeError: (0 , import_vite_plugin_svg_icons.createSv
    报错内容如下:failedtoloadconfigfrom/home/app/git_repos/customer-visit-front/vite.config.jserrorduringbuild:TypeError:(0,import_vite_plugin_svg_icons......