Verilog 字符串

字符串简介

一个字符串是由双引号"括起来并包含在一行中的字符序列。
在表达式和赋值语句中,用作操作数的字符串被视为由8bit ASCII码值表示的无符号整数常量。

字符串声明

字符串变量是wire/reg类型的变量,宽度等于字符串中的字符个数乘以8。

reg [8*12 -1 : 0] stringVar; // 可以存储12个字符
initial begin
    stringVal = "Hello World!";
end

字符串操作

可以使用Verilog的运算符来操作字符串,操作的值都是以8bit ASCII值为一个整体。
$display自动地在输出后进行换行,$write则在输出后不换行。在$display和$write中输出格式控制是用双引号括起来的字符串。

// 字符串打印
$display("%s is stored as %h", stringVar,stringVar);
// 字符串拼接
stringVar = {"Hello ","World!"};
  • 当一个变量声明的位宽大于保存被赋字符串所需的位宽时,左边的多余位宽在赋值后用0填充。
  • 如果字符串长度大于声明的字符串变量的位宽,则该字符串将被向左截断,最左边的字符将丢失。

格式说明符,%和格式字符组成,将输出地数据转换成指定的格式输出。
在这里插入图片描述
转义字符
在这里插入图片描述

输出数字( 八进制、十进制、十六进制)时:

  • 如果对应所有位都为不定值,则输出小写x, 部分位为不定态输出大写X。
  • 如果对应所有位都为高阻值,则输出小写z, 部分位为高阻值输出大写Z。

输出字符画

在线生成字符画网站

  • 根据文字生成字符画
    • https://patorjk.com/software/taag/#p=display&f=Graffiti&t=Type%20Something%20
  • 根据图片生成字符画
    • https://www.degraeve.com/img2txt.php
    • http://life.chacuo.net/convertphoto2char
  • 根据流程图生成字符画
    • https://asciiflow.com/
`timescale 1ns / 1ns

module tb_ascii_pic();

initial begin
        show_pass();
        # 100 ;
        $stop;
end

task automatic show_pass();
begin: pass
    $display("pwd: %m");
    $display(".----------------.  .----------------.  .----------------.  .----------------. " ); 
    $display("| .--------------. || .--------------. || .--------------. || .--------------. |");
    $display("| |   ______     | || |      __      | || |    _______   | || |    _______   | |");
    $display("| |  |_   __ \   | || |     /  \     | || |   /  ___  |  | || |   /  ___  |  | |");
    $display("| |    | |__) |  | || |    / /\ \    | || |  |  (__ \_|  | || |  |  (__ \_|  | |");
    $display("| |    |  ___/   | || |   / ____ \   | || |   '.___`-.   | || |   '.___`-.   | |");
    $display("| |   _| |_      | || | _/ /    \ \_ | || |  |`\____) |  | || |  |`\____) |  | |");
    $display("| |  |_____|     | || ||____|  |____|| || |  |_______.'  | || |  |_______.'  | |");
    $display("| |              | || |              | || |              | || |              | |");
    $display("| '--------------' || '--------------' || '--------------' || '--------------' |");
    $display("'----------------'  '----------------'  '----------------'  '----------------' " );   
    $display("time: %t",$time );
end
endtask

task automatic show_fail();
begin: fail
    $display("pwd: %m");
    $display(".----------------.  .----------------.  .----------------.  .----------------. " ); 
    $display("| .--------------. || .--------------. || .--------------. || .--------------. |");
    $display("| |  _________   | || |      __      | || |     _____    | || |   _____      | |");
    $display("| | |_   ___  |  | || |     /  \     | || |    |_   _|   | || |  |_   _|     | |");
    $display("| |   |  _|      | || |   / ____ \   | || |      | |     | || |    | |   _   | |");
    $display("| |  _| |_       | || | _/ /    \ \_ | || |     _| |_    | || |   _| |__/ |  | |");
    $display("| | |_____|      | || ||____|  |____|| || |    |_____|   | || |  |________|  | |");
    $display("| |              | || |              | || |              | || |              | |");
    $display("| '--------------' || '--------------' || '--------------' || '--------------' |");
    $display("'----------------'  '----------------'  '----------------'  '----------------' " );
    $display("time: %t",$time );
end
endtask

endmodule

在这里插入图片描述

  • 8
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

暴风雨中的白杨

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值