首页 > 其他分享 >SystemVerilog -- 3.1 SystemVerilog while and do-while loop

SystemVerilog -- 3.1 SystemVerilog while and do-while loop

时间:2024-05-05 18:13:06浏览次数:16  
标签:do begin end cnt while ncsim SystemVerilog

SystemVerilog while and do-while loop

两者都是循环构造,只要给定条件为真,就会执行给定的语句集。while do while

循环首先检查条件是否为true,如果条件为true,则执行语句。如果条件被证明是假的,则循环就在哪里结束。while

循环首先执行一次语句,然后检查条件是否为true。如果条件为true,则执行该语句集,直到条件变为false。如果条件为false,则循环将在此处结束。do while

因此,两者之间的区别在于,循环至少执行一次语句集。do while

Syntax

while (<condition>) begin
  // Multiple statements
end

do begin
  // Multiple statements
end while  (<condition>);

Example #1 - while loop

module tb;
  initial begin
    int cnt = 0;
    while (cnt < 5) begin
      $display("cnt = %0d", cnt);
      cnt++;
    end
  end
endmodule

模拟日志

ncsim> run
cnt = 0
cnt = 1
cnt = 2
cnt = 3
cnt = 4
ncsim: *W,RNQUIE: Simulation is complete.

Example #2

module tb;
  initial begin
    int cnt;
    
    while (cnt != 0) begin
      $display("cnt = %0d", cnt);
      cnt++;
    end
  end
endmodule

模拟日志

ncsim> run
ncsim: *W,RNQUIE: Simulation is complete.

Example #3 - do while loop

module tb;
  initial begin
    int cnt = 0;
    do begin
      $display("cnt = %0d", cnt);
      cnt++;
    end while (cnt < 5);
  end
endmodule

模拟日志

ncsim> run
cnt = 0
cnt = 1
cnt = 2
cnt = 3
cnt = 4
ncsim: *W,RNQUIE: Simulation is complete.

Example #4 - do while loop

module begin
  initial begin
    int cnt = 0;
    do begin
      $display("cnt = %0d", cnt);
      cnt++;
    end while (cnt == 0);
  end
end

模拟日志

ncsim> run
cnt = 0
ncsim: *W,RNQUIE: Simulation is complete.

标签:do,begin,end,cnt,while,ncsim,SystemVerilog
From: https://www.cnblogs.com/sys-123456/p/18171603

相关文章

  • windows安装ffmpeg
    官网https://ffmpeg.org/download.html这个是别人已经编译好的,不染源码还需要重新编译解压到一个目录,添加到环境变量......
  • dotnet 泛型委托 ACTION FUNC
    voidMain(){//泛型委托ACTIONFUNC//3.创建委托实例TestDele<string>testDele=newTestDele<string>(HellowDele);testDele("测试委托");//官方版本的泛型委托(不带返回值)Action<string>action=newAction<string>(HellowDele);......
  • Dockerfile
     FROM--platform=$BUILDPLATFORMalpineasprotocARGBUILDPLATFORM=linux/amd64TARGETOS=linuxTARGETARCH=amd64#downloadtheprotocbinaryfromgithub#Weunzipthefileinto/usr/local.Noticethatweareextractingboththeprotoc#binary(/bin/pr......
  • [SDOI2015] 星际战争 题解
    假如将所有激光武器放在一边,所有机器人放在一边,激光武器向它可以伤害的机器人连边,再加超级源/汇点,这就是一个网络流问题。考虑激光武器向机器人连的边容量无限,而机器人向超级汇点连的边容量为机器人的装甲值,而超级源点连向激光武器的边则是用时\(\times\)激光武器伤害。发现假......
  • Cleanmgr,也称为磁盘清理器(Disk Cleanup),是Windows操作系统中的实用工具,用于删除计算机
    cleanmgr|MicrosoftLearnCleanmgr,也称为磁盘清理器(DiskCleanup),是Windows操作系统中的实用工具,用于删除计算机上不需要的临时文件、回收站文件、下载文件以及其他可以安全删除的文件,以释放磁盘空间。功能特点:释放磁盘空间:Cleanmgr可以帮助用户识别并删除不再需要的......
  • docker离线安装
    步骤一:官网下载Docker安装包wgethttps://download.docker.com/linux/static/stable/x86_64/docker-24.0.6.tgz步骤二:解压安装包tar-zxvfdocker-24.0.6.tgz步骤三:将解压后的Docker文件移到/usr/bin目录下sudocpdocker/*/usr/bin/步骤四:将Docker注册为系......
  • TypeError 'tuple' object does not support item assignment
    左手编程,右手年华。大家好,我是一点,关注我,带你走入编程的世界。公众号:一点sir,关注领取编程资料TypeError:'tuple'objectdoesnotsupportitemassignment是一个在Python编程语言中常见的错误,意味着你试图修改一个不可变的元组(tuple)对象中的元素。在Python中,元组是一种不......
  • Sxstrace.exe 是 Windows 操作系统提供的一个工具,用于跟踪和分析应用程序的依赖项解析
    sxstrace|MicrosoftLearnSxstrace.exe是Windows操作系统提供的一个工具,用于跟踪和分析应用程序的依赖项解析过程。该工具可以帮助用户诊断应用程序启动或运行时出现的依赖项错误或加载问题。在Windows中,许多应用程序依赖于共享组件和库文件,如动态链接库(DLL)。当应用......
  • Adobe Photoshop 2024 v25.7 (macOS, Windows) - 照片和设计软件
    AdobePhotoshop2024v25.7(macOS,Windows)-照片和设计软件Acrobat、AfterEffects、Animate、Audition、Bridge、CharacterAnimator、Dimension、Dreamweaver、Illustrator、InCopy、InDesign、LightroomClassic、MediaEncoder、Photoshop、PremierePro、AdobeXD请......
  • Adobe InDesign 2024 v19.4 (macOS, Windows) - 版面设计和桌面出版软件
    AdobeInDesign2024v19.4(macOS,Windows)-版面设计和桌面出版软件Acrobat、AfterEffects、Animate、Audition、Bridge、CharacterAnimator、Dimension、Dreamweaver、Illustrator、InCopy、InDesign、LightroomClassic、MediaEncoder、Photoshop、PremierePro、Adob......