📄 8.5.2c.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.5.2b.htm'"></td>
<td><img src="../images/next.gif" onmouseover="javascript:style.cursor='hand'" onclick="vbscript:window.location.href='8.5.2_2.htm'"></img></td>
</tr>
</table>
<br><br>
<table><tr><td>    </td>
<td class="content" >
<P><font class="example"><img border="0" src="images/dingyi.gif" width="32" height="31">例8.4</font> 赋值语句d:=(a-b)+(a-c)+(a-c)可以翻译成如下的三地址语句序列:<br><br>
t:=a-b<br>
u:=a-c<br>
v:=t+u<br>
d:=v+u<br>
<br>
其中d在基本块的出口,假定它是活跃的。上述代码生成算法对此子地址语句序列产生的目标代码如表8.3所示,表中给出了在代码生成过程中寄存器描述器和地址描述器的值,因为a,b,c一直在存储器中,所以在地址描述器中没有显示它们。我们还假定作为临时变量的t,u和v不在存储器中,除非用MOV指令明显地将它们的值存放到存储器之中。</P>
<P>getreg(t:=a-b)返回R0作为存放t的当前值的寄存器。由于a不在R0中,生成指令MOV a,R0和SUB
b,R0,然后更新寄存器描述器以记录R0包含t。</P>
<P>代码生成以此种方式继续进行,直到最后的三地址语句d:=u+v处理完为止,注意,因为这儿的u没有下次引用,R1将变为空。最后,在基本块的出口处生成指令MOV
R0,d,存储活跃变量d的值。</P>
<P align=center>表8.3  代码序列 </P>
<TABLE align=center border=1 cellPadding=5 cellSpacing=0 width="75%">
<TBODY>
<TR>
<TD width="21%">
<DIV align=center>语句</DIV></TD>
<TD width="23%">
<DIV align=center>生成的代码</DIV></TD>
<TD width="23%">
<DIV align=center>寄存器描述</DIV></TD>
<TD width="33%">
<DIV align=center>地址描述器</DIV></TD></TR>
<TR>
<TD height=21 width="21%">
<DIV align=center>t:=a-b</DIV></TD>
<TD height=21 width="23%">
<DIV align=center>MOV a,R0</DIV></TD>
<TD height=19 rowSpan=2 width="23%">
<DIV align=center>空寄存器</DIV>
<DIV align=center>R0包含t</DIV></TD>
<TD height=21 rowSpan=2 width="33%">
<DIV align=center>t在R0中</DIV>
<DIV align=center></DIV></TD></TR>
<TR>
<TD width="21%">
<DIV align=center> </DIV></TD>
<TD width="23%">
<DIV align=center>SUB b,R0</DIV></TD></TR>
<TR>
<TD width="21%">
<DIV align=center></DIV></TD>
<TD width="23%">
<DIV align=center></DIV></TD>
<TD width="23%">
<DIV align=center></DIV></TD>
<TD width="33%">
<DIV align=center></DIV></TD></TR>
<TR>
<TD width="21%">
<DIV align=center>u:=a-c</DIV></TD>
<TD width="23%">
<DIV align=center>MOV a,R1</DIV></TD>
<TD width="23%">
<DIV align=center>R0包含t</DIV></TD>
<TD rowSpan=2 width="33%">
<DIV align=center>t在R0中</DIV>
<DIV align=center>u在R1中</DIV></TD></TR>
<TR>
<TD width="21%">
<DIV align=center> </DIV></TD>
<TD width="23%">
<DIV align=center>SUB c,R1</DIV></TD>
<TD width="23%">
<DIV align=center>R1包含u</DIV></TD></TR>
<TR>
<TD width="21%">
<DIV align=center></DIV></TD>
<TD width="23%">
<DIV align=center></DIV></TD>
<TD width="23%">
<DIV align=center></DIV></TD>
<TD width="33%">
<DIV align=center></DIV></TD></TR>
<TR>
<TD height=23 width="21%">
<DIV align=center>v:=t+u</DIV></TD>
<TD height=23 width="23%">
<DIV align=center>ADD R1,R0</DIV></TD>
<TD height=23 width="23%">
<DIV align=center>R0包含v</DIV></TD>
<TD rowSpan=2 width="33%">
<DIV align=center>
<DIV align=center>u在R1中</DIV>v在R0中</DIV></TD></TR>
<TR>
<TD height=2 width="21%">
<DIV align=center> </DIV></TD>
<TD height=2 width="23%">
<DIV align=center> </DIV></TD>
<TD height=2 width="23%">
<DIV align=center>R1包含u</DIV></TD></TR>
<TR>
<TD width="21%">
<DIV align=center></DIV></TD>
<TD width="23%">
<DIV align=center></DIV></TD>
<TD width="23%">
<DIV align=center></DIV></TD>
<TD width="33%">
<DIV align=center></DIV></TD></TR>
<TR>
<TD width="21%">
<DIV align=center>d:=v+u</DIV></TD>
<TD width="23%">
<DIV align=center>ADD R1,R0</DIV></TD>
<TD width="23%">
<DIV align=center>R0包含d</DIV></TD>
<TD width="33%">
<DIV align=center>d在R0中</DIV></TD></TR>
<TR>
<TD height=22 width="21%">
<DIV align=center> </DIV></TD>
<TD height=22 width="23%">
<DIV align=center>MOV R0,d</DIV></TD>
<TD height=22 width="23%">
<DIV align=center> </DIV></TD>
<TD height=22 width="33%">
<DIV align=center>d在R0和存储器中</DIV></TD></TR></TBODY></TABLE>
</td></tr><tr><td width="18"></td>
<td class="content" width="868">
</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.5.2b.htm'"></td>
<td><img src="../images/next.gif" onmouseover="javascript:style.cursor='hand'" onclick="vbscript:window.location.href='8.5.2_2.htm'"></img></td>
</tr>
</table>
</BODY>
<html><script language="JavaScript">
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -