📄 00241.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN">
<html>
<head>
<title>2.6 字符串文本</title>
<meta http-equiv="Content-Type" content="text/html; charset=GB2312" />
<meta name="generator" content="Doc-O-Matic" />
<meta http-equiv="Content-Style-Type" content="text/css" />
<link rel="STYLESHEET" href="default.css" type="text/css" />
<script type="text/javascript" src="scripts.js"></script>
</head>
<body class="Element700" onload="onBodyLoadEx('systemverilog31a.html', 'topic', '00241.html');" onmousedown="onBodyMouseDown();">
<!-- Begin Popups -->
<div class="Element801" id="popup00007">
<div class="Element800">
<div class="Element14">
链接</div>
<div class="Element11">
<div class="Element10">
<a href="00857.html" target="topic">第二章 文本值</a></div>
</div>
</div>
</div>
<!-- End Popups -->
<!-- Begin Page Header -->
<div class="Element710" id="areafixed">
<div class="Element92">
<table width="100%" cellspacing="0" cellpadding="0">
<tr><td width="33%">
<div class="Element1">
<a href="#" onmousedown="showPopup(this, 'popup00007');"><img src="seealsolink.png" border="0" alt="" title=""></a> SystemVerilog 3.1a语言参考手册</div>
</td><td width="34%">
<div class="Element2">
</div>
</td><td width="33%">
<div class="Element90">
<a href="00240.html" target="topic"><img src="btn_prev_lightblue.gif" border="0" alt="Previous" title="Previous" onmouseover="switchImage(this, 'btn_prev_lightblue_hover.gif');" onmouseout="switchImage(this, 'btn_prev_lightblue.gif');"></a><a href="00857.html" target="topic"><img src="btn_up_lightblue.gif" border="0" alt="Up" title="Up" onmouseover="switchImage(this, 'btn_up_lightblue_hover.gif');" onmouseout="switchImage(this, 'btn_up_lightblue.gif');"></a><a href="00242.html" target="topic"><img src="btn_next_lightblue.gif" border="0" alt="Next" title="Next" onmouseover="switchImage(this, 'btn_next_lightblue_hover.gif');" onmouseout="switchImage(this, 'btn_next_lightblue.gif');"></a></div>
</td></tr></table><div class="Element5">
2.6 字符串文本</div>
</div>
</div>
<!-- End Page Header -->
<!-- Begin Client Area -->
<div class="Element720" id="areascroll">
<div class="Element721">
<!-- Begin Page Content -->
<div class="Element58">
<a name="描述"></a><div class="Element11">
<div class="Element10">
<p class="Element10">
字符串文本由引号包围并且拥有自己的数据类型。非打印字符或其它特殊字符都使用一个反斜杠(<span style="color: #800080">\</span>)作为开始。SystemVerilog加入了下列特殊字符串字符: </p><div class="Element170">
<a href="#" onclick="CopyElementToClipboard('code00005');">Copy Code</a></div>
<div class="Element13"><div class="Element12" id="code00005"><pre class="Element12"><span style="color: #800080">\</span>v <span style="color: #008000">// 垂直TAB</span>
<span style="color: #800080">\</span>f <span style="color: #008000">// 换页</span>
<span style="color: #800080">\</span>a <span style="color: #008000">// 响铃</span>
<span style="color: #800080">\</span><span style="color: #0000FF">x</span><span style="color: #FF0000">02</span> <span style="color: #008000">// 十六进制数</span></pre></div></div>
<p class="Element10">
一个字符串文本必须包含在一个单一的行中,除非新的行紧跟着一个反斜杠(<span style="color: #800080">\</span>)。在这种情况下,反斜杠和新行字符会被忽略。对字符串文本的长度没有预定义的限制。 </p>
<p class="Element10">
</p>
<p class="Element10">
与Verilog-2001一样,一个字符串文本可以赋值到一个整数类型。如果尺寸不同,它会进行右调整。 </p><div class="Element170">
<a href="#" onclick="CopyElementToClipboard('code00006');">Copy Code</a></div>
<div class="Element13"><div class="Element12" id="code00006"><pre class="Element12"><span style="color: #0000FF">byte</span> c1 <span style="color: #800080">=</span> <span style="color: #575D94">"A"</span><span style="color: #800080">;</span>
<span style="color: #0000FF">bit</span> <span style="color: #800080">[</span><span style="color: #FF0000">7</span><span style="color: #800080">:</span><span style="color: #FF0000">0</span><span style="color: #800080">]</span> d <span style="color: #800080">= </span><span style="color: #575D94">"\n"</span><span style="color: #800080">;</span>
<span style="color: #0000FF">bit</span> <span style="color: #800080">[</span><span style="color: #FF0000">0</span><span style="color: #800080">:</span><span style="color: #FF0000">11</span><span style="color: #800080">][</span><span style="color: #FF0000">7</span><span style="color: #800080">:</span><span style="color: #FF0000">0</span><span style="color: #800080">]</span> c2 <span style="color: #800080">= </span><span style="color: #575D94">"hello world\n"</span><span style="color: #800080">;</span>
<span style="color: #008000">// c2的值为{8'h68, 8'h65, 8'h6c, 8'h6c, 8'h6f, 8'h20,</span>
<span style="color: #008000"> // 8'h77, 8'h6f, 8'h72, 8'h6c, 8'h64, 8'h0a}</span>
<span style="color: #0000FF">bit</span> <span style="color: #800080">[</span><span style="color: #FF0000">0</span><span style="color: #800080">:</span><span style="color: #FF0000">10</span><span style="color: #800080">][</span><span style="color: #FF0000">7</span><span style="color: #800080">:</span><span style="color: #FF0000">0</span><span style="color: #800080">]</span> c3 <span style="color: #800080">= </span><span style="color: #575D94">"hello world\n"</span><span style="color: #800080">;</span>
<span style="color: #008000">// c3的值为{8'h65, 8'h6c, 8'h6c, 8'h6f, 8'h20,</span>
<span style="color: #008000"> // 8'h77, 8'h6f, 8'h72, 8'h6c, 8'h64, 8'h0a}</span>
<span style="color: #0000FF">bit</span> <span style="color: #800080">[</span><span style="color: #FF0000">0</span><span style="color: #800080">:</span><span style="color: #FF0000">9</span><span style="color: #800080">][</span><span style="color: #FF0000">7</span><span style="color: #800080">:</span><span style="color: #FF0000">0</span><span style="color: #800080">]</span> c4 <span style="color: #800080">= </span><span style="color: #575D94">"hello world\n"</span><span style="color: #800080">;</span>
<span style="color: #008000">// c4的值为{8'h6c, 8'h6c, 8'h6f, 8'h20,</span>
<span style="color: #008000"> // 8'h77, 8'h6f, 8'h72, 8'h6c, 8'h64, 8'h0a}</span>
<span style="color: #0000FF">bit</span> <span style="color: #800080">[</span><span style="color: #FF0000">0</span><span style="color: #800080">:</span><span style="color: #FF0000">12</span><span style="color: #800080">][</span><span style="color: #FF0000">7</span><span style="color: #800080">:</span><span style="color: #FF0000">0</span><span style="color: #800080">]</span> c5 <span style="color: #800080">=</span> <span style="color: #575D94">"hello world\n"</span><span style="color: #800080">;</span>
<span style="color: #008000">// c5的值为{8'h00, 8'h68, 8'h65, 8'h6c, 8'h6c, 8'h6f, 8'h20,</span>
<span style="color: #008000"> // 8'h77, 8'h6f, 8'h72, 8'h6c, 8'h64, 8'h0a}</span></pre></div></div>
<p class="Element10">
一个字符串文本可以被赋值到一个非压缩字节数组。如果尺寸不同,它会进行左调整。 </p><div class="Element170">
<a href="#" onclick="CopyElementToClipboard('code00007');">Copy Code</a></div>
<div class="Element13"><div class="Element12" id="code00007"><pre class="Element12"><span style="color: #0000FF">byte</span> c6<span style="color: #800080">[</span><span style="color: #FF0000">0</span><span style="color: #800080">:</span><span style="color: #FF0000">12</span><span style="color: #800080">] =</span> <span style="color: #575D94">"hello world\n"</span><span style="color: #800080">;</span></pre></div></div>
<p class="Element10">
</p>
<div class="Element63">
<div class="TableDiv">
<table cellspacing="0" class="Table1">
<tr>
<td class="Element65" valign="top" width="100%">
<div class="Element66">
FPGA技术网疑问 </div></td></tr><tr>
<td class="Element67" valign="top" width="100%">
<div class="Element68">
关于这一处的左调整,ModelSim SE PLUS 6.1a的实现似乎与参考手册的规定不符。在ModelSim SE PLUS 6.1a仍然进行右调整,也就是C6的值为:<br>{8'h00, 8'h68, 8'h65, 8'h6c, 8'h6c, 8'h6f, 8'h20, 8'h77, 8'h6f, 8'h72, 8'h6c, 8'h64, 8'h0a} </div></td></tr></table></div></div>
<p class="Element10">
</p>
<p class="Element10">
压缩数组和非压缩数组将在<a href="00874.html" target="topic">第四章</a>中讨论。字符串文本与数组文本的差别将在接下来的<a href="00242.html" target="topic">2.7节</a>中讨论。 </p>
<p class="Element10">
</p>
<p class="Element10">
字符串文本还可以被强制转换成一个压缩数组或非压缩数组,这与将字符串文本赋值到一个压缩数组或非压缩数组遵守相同的规则。强制类型转换将在<a href="00385.html" target="topic">3.14节</a>中讨论。 </p>
<p class="Element10">
</p>
<p class="Element10">
SystemVerilog 3.1a还包含一个<span style="color: #0000FF">string</span>数据类型,字符串文本可以赋值给这种类型的变量。<span style="color: #0000FF">string</span>类型的变量具有任意的长度,它们可以动态地改变大小以便容纳任意字符串。 </p>
<p class="Element10">
</p>
<p class="Element10">
字符串文本是一个压缩数组(宽度是8位的整数倍),当字符串文本赋值到一个<span style="color: #0000FF">string</span>类型或在一个使用<span style="color: #0000FF">string</span>类型操作码的表达式中使用(参看<a href="00396.html" target="topic">3.7节</a>)的时候,它们可以被隐式地转换成<span style="color: #0000FF">string</span>类型。</p></div>
</div>
<a name="Group"></a><div class="Element14">
<a onclick="toggleVisibilityStored('Group');" class="a_Element14"><img src="sectionminus.png" border="0" alt="" title="" id="imgGroup">Group</a></div>
<div id="divGroup">
<div class="Element11">
<div class="Element10">
<p class="Element10">
<a href="00857.html" target="topic">第二章 文本值</a></p></div>
</div>
</div>
<a name="Links"></a><div class="Element14">
<a onclick="toggleVisibilityStored('链接');" class="a_Element14"><img src="sectionminus.png" border="0" alt="" title="" id="img链接">链接</a></div>
<div id="div链接">
<div class="Element11">
<div class="Element10">
<a href="00857.html" target="topic">第二章 文本值</a></div>
</div>
</div>
</div>
<!-- End Page Content -->
<!-- Begin Page Footer -->
<hr width="98%" align="center" size="1" color="#CCCCCC" />
<table align="center" cellpadding="0" cellspacing="0" border="0">
<tbody>
<tr height="10">
<td></td>
</tr>
<tr align="center">
<td>
<script type="text/javascript"><!--
google_ad_client = "pub-5266859600380184";
google_ad_width = 468;
google_ad_height = 60;
google_ad_format = "468x60_as";
google_ad_type = "text_image";
google_ad_channel ="";
google_page_url = document.location;
//--></script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</td>
</tr>
<tr height="15">
<td></td>
</tr>
<tr align="center">
<td>
<font size=2>除非特别声明,原文版权归作者所有,如有转摘请注明原作者以及译者(<a href="http://www.fpgatech.net/" target="_blank">FPGA技术网</a>)信息。<br />
如果您对本主题有何建议或意见,请登陆<a href="http://www.fpgatech.net/forum/forumdisplay.php?fid=18" target="_blank">FPGA开发者家园</a>提交,您的参与是我们前进的动力。</font>
<script language="javascript" type="text/javascript" src="http://js.users.51.la/195685.js"></script>
<noscript><a href="http://www.51.la/?195685" target="_blank"><img alt="我要啦免费统计" src="http://img.users.51.la/195685.asp" style="border:none" /></a></noscript>
</td>
</tr>
</tbody>
</table>
<!-- End Page Footer -->
</div>
</div>
<!-- End Client Area -->
</body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -