📄 8.3.1b.htm
字号:
<html>
<head>
<title>编译原理</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<link type="text/css" rel="stylesheet" href="../css/specification.css">
</head>
<body>
<table align=right width=300>
<tr>
<td><img src="../images/previous.gif" onmouseover="javascript:style.cursor='hand'" onclick="vbscript:window.location.href='8.3.1.htm'"></td>
<td><img src="../images/next.gif" onmouseover="javascript:style.cursor='hand'" onclick="vbscript:window.location.href='8.3.2.htm'"></img></td>
</tr>
</table>
<br><br>
</table>
<P><B><FONT class=example><img border="0" src="images/dingyi.gif" width="32" height="31">例
8.2 </FONT> </B>考虑图8.6中显示的示意性源代码的片殷。它计算两个长度为20的向量a和b的点乘。在我们的目标机器上完成该计算的三地址语句序列见图8.7。</P>
<table>
<tr>
<td width=150> </td>
<td>
<P><font color="#0000FF">begin</font> <BR> prod:=0; <BR> i:=1; <BR> <font color="#0000FF">do begin</font>
<BR> prod:=prod+prod a[i] *b[i]; <BR> i:=i+1;<br>
<font color="#0000FF">end</font>
<BR> <font color="#0000FF">while</font> i<=20 <BR> <font color="#0000FF">end</font>;</P>
<P>图8.6 计算向量点积程序</P>
</td>
</tr>
</table>
<P>现在我们采用算法8.1来生成图8.7的三地址代码的基本块。由规则(a),语句(1)为一个入口语句。由规则(b),语句(3)也是一个入口语句,因为从最后一条语句可以转移到该语句。由规则(b),接在语句(14)后的语句是一个入口语句(图8.6仅是一个程序的片段)。因此,语句(1)和(2)组成一个基本块,从语句(3)开始的程序的余下部分组成一个基本块。</P>
<center>
<table>
<tr>
<td>
<br> (1) prod:=0
<br> (2) i:=1
<br> (3) t<SPAN class=down><sub>1</sub></SPAN>:=4*i
<br> (4) t<SPAN class=down><sub>2</sub></SPAN>:=a-4
<br> (5) t<SPAN class=down><sub>3</sub></SPAN>:=t<SPAN class=down><sub>2</sub></SPAN>[t<SPAN class=down><sub>1</sub></SPAN>] <FONT size=+0 color="#008000">/* 计算a[i],见7.3.2节的<br>
公式(7.3)—(7.5)*/ </FONT>
<br> (6) t<SPAN class=down><sub>4</sub></SPAN>:=4*i
<br> (7) t<SPAN class=down><sub>5</sub></SPAN>:=b-4
<br> (8) t<SPAN class=down><sub>6</sub></SPAN>:=t<SPAN class=down><sub>5</sub></SPAN>[t<SPAN class=down><sub>4</sub></SPAN>]<FONT size=+0 color="#008000">/*计算b[i]*/ </FONT>
<br> (9) t<SPAN class=down><sub>7</sub></SPAN>:=t<SPAN class=down><sub>3</sub></SPAN>*t<SPAN class=down><sub>6</sub></SPAN>
<br> (10)t<SPAN class=down><sub>8</sub></SPAN>:=prod+t<SPAN class=down><sub>7</sub></SPAN>
<br> (11)prod:=t<SPAN class=down><sub>8</sub></SPAN>
<br> (12)t<SPAN class=down><sub>9</sub></SPAN>:=i+1
<br> (13)i:=t<SPAN class=down><sub>9</sub></SPAN>
<br> (14)if i<=20 <font color="#0000FF"> goto</font>(3)</P>
<p>图8.7 计算向量点积的三地址代码 </p>
</td>
</tr>
</table>
</center>
</td></tr></table>
<br>
<table align=right width=300>
<tr>
<td><img src="../images/previous.gif" onmouseover="javascript:style.cursor='hand'" onclick="vbscript:window.location.href='8.3.1.htm'"></td>
<td><img src="../images/next.gif" onmouseover="javascript:style.cursor='hand'" onclick="vbscript:window.location.href='8.3.2.htm'"></img></td>
</tr>
</table>
</BODY>
<html><script language="JavaScript">
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -