• systemverilog中输入输出系统任务和函数(一)——显示相关的任务



    前言

    在systemverilog中提供了许多输入输出的系统任务和函数,本文主要介绍以下这些显示相关的任务。

    • $display | $displayb | $displayh | $displayo
    • $write | $writeb | $writeh | $writeo
    • $strobe | $strobeb | $strobeh | $strobeo
    • $monitor | $monitorb | $monitorh | $monitoro | $monitoroff | $monitoron

    一、显示相关的任务

    1.1 $display | $displayb | $displayh | $displayo

    $display 十进制显示。
    $displayb 二进制显示。
    $displayh 十六进制显示。
    $displayo 八进制显示。

    示例1:

    module disp;
    initial begin
    $display("\\\t\\\n\"\123");
    end
    endmodule
    
    • 1
    • 2
    • 3
    • 4
    • 5

    仿真输出:

    \ \
    "S
    
    • 1
    • 2

    示例2:

    module disp;
    logic [31:0] rval;
    pulldown (pd);
    initial begin
    rval = 101;
    $display("rval = %h hex %d decimal",rval,rval);
    $display("rval = %o octal\nrval = %b bin",rval,rval);
    $display("rval has %c ascii character value",rval);
    $display("pd strength value is %v",pd);
    $display("current scope is %m");
    $display("%s is ascii value for 101",101);
    $display("simulation time is %t", $time);
    end
    endmodule
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14

    仿真输出:

    rval = 00000065 hex 101 decimal
    rval = 00000000145 octal
    rval = 00000000000000000000000001100101 bin
    rval has e ascii character value
    pd strength value is StX
    current scope is disp
    e is ascii value for 101
    simulation time is 0
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    示例3:

    module printval;
    logic [11:0] r1;
    initial begin
    r1 = 10;
    $display( "Printing with maximum size - :%d: :%h:", r1,r1 );
    $display( "Printing with minimum size - :%0d: :%0h:", r1,r1 );
    end
    endmodule
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8

    仿真结果:

    Printing with maximum size - : 10: :00a:
    Printing with minimum size - :10: :a:
    
    • 1
    • 2

    示例4:

    Format Value     Displays
    %d     32'd10    : 10:
    %0d    32'd10    :10:
    %h     32'd10    :0000000a:
    %0h    32'd10    :a:
    %3d    32'd5     : 5:
    %3d    32'd100   :100:
    %3d    32'd1234  :1234:
    %3h    32'h5     :005:
    %3h    32'h100   :100:
    %3h    32'h1234  :1234:
    %s     "abc"     :abc:
    %3s    "a"       : a:
    %3s    "abc"     :abc:
    %3s    "abcdef"  :abcdef:
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15

    1.2 $write | $writeb | $writeh | $writeo

    $write 十进制显示。
    $writeb 二进制显示。
    $writeh 十六进制显示。
    $writeo 八进制显示。
    $write和$display的用法一致。
    $write和$display的区别是,$display后边会自动增加一个回车,而$write后边没有回车。

    1.3 $strobe | $strobeb | $strobeh | $strobeo

    $strobe 十进制显示。
    $strobeb 二进制显示。
    $strobeh 十六进制显示。
    $strobeo 八进制显示。
    $strobe和$display的用法一致。
    $strobe和$display的区别是,当$strobe 被调用的时刻所有活动都完成了,才打印文本,这包括所有阻塞性和非阻塞性赋值的作用。
    在写仿真结果时请尽量使用$strobe 少用$display 或$write ,这保证了选通的线网和寄存器被写入稳定的值。
    示例:

    initial
    begin
    a = 0;
    $display(a);          // displays 0
    $strobe(a);           // displays 1 ...
    a = 1;                   // ... 因为这条语句
    end
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    1.4 $monitor | $monitorb | $monitorh | $monitoro | $monitoroff | $monitoron

    当启动一个带有一个或多个参数的$monitor任务时,仿真器则建立一个处理机制,使得每当参数列表中变量或表达式的值发生变化时,整个参数列表中变量或表达式的值都将输出显示。

    示例:

    $monitor($time,,"rxd=%b txd=%b",rxd,txd)
    
    • 1

    在多模块调试的情况下,许多模块中都调用了$monitor,因为任何时刻只能有一个$monitor起作用,因此需配合$monitoron与$monitoroff使用,把需要监视的模块用$monitoron打开,在监视完毕后及时用$monitoroff关闭,以便把$monitor 让给其他模块使用。$monitor与$display的不同处还在于$monitor往往在initial块中调用,只要不调用$monitoroff,$monitor便不间断地对所设定的信号进行监视。

    1.5 $display | $strobe | $monitor区别

    用$display()系统任务来显示当前变量的值。
    用$strobe()系统任务来显示用非阻塞赋值的变量值。
    用$monitor()监控和输出参数列表中的表达式或变量值。


    总结

    本文主要介绍systemverilog中,显示相关的任务。

  • 相关阅读:
    2022CCPC桂林 E. Draw a triangle (gym104008E)
    Jina AI正式将DocArray捐赠给Linux基金会
    LRU缓存
    代码随想录Day52 | 300. 最长递增子序列 | 674. 最长连续递增序列 | 718. 最长重复子数组
    CubeFS - 新一代云原生存储系统
    性能测试fangan
    趋动云模型--猫狗识别
    归并排序 图解 递归 + 非递归 + 笔记
    AE调试(非人脸场景)
    gpio模拟串口通信
  • 原文地址:https://blog.csdn.net/hh199203/article/details/126095653