⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 8.5.2_2.htm

📁 建立《编译原理网络课程》的目的不仅使学生掌握构造编译程序的原理和技术
💻 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.2c.htm'"></td>
<td><img src="../images/next.gif" onmouseover="javascript:style.cursor='hand'" onclick="vbscript:window.location.href='8.5.2_2b.htm'"></img></td>
</tr>
</table>
<br><br>

<table><tr><td>&nbsp&nbsp&nbsp&nbsp</td>
<td class="content" width="868">
<P><font class="definition2">为其它类型的语句生成目标代码</font></P>
<P>对于三地址语句中的索引和指针运算,可用与处理二目运算的相同的方式进行解决。表8.4给出了由索引赋值a:=b[i]和a[i]:=b所生成的目标代码。其中假定,在第一个赋值中的b是静态分配的,在第二个赋值中的a也是静态分配的。</P>
<P>i的当前地址决定着生成什么样的代码。i的位置可概括为以下三种情况:i是在寄存器Ri中;i是在存储单元Mi中;i是在栈中,其偏移地址为Si且指向适用于i的活动记录的指针是在寄存器A之内。寄存器R是在调用函数getreg之后返回的寄存器。对于第一个赋值,如果a在该基本块中有下次引用且寄存器R是可用的,则将保留a在寄存器R中。</P>
<P align=center>表8.4&nbsp&nbsp索引赋值的代码序列</P>
<TABLE align=center border=1 cellPadding=5 cellSpacing=0 height=45 width="90%">
<TBODY>
<TR>
<TD height=102 rowSpan=2 width="12%">
<DIV align=center>语句</DIV></TD>
<TD colSpan=2 height=21>
<DIV align=center>i在寄存器R<SPAN class=down>i</SPAN>中</DIV></TD>
<TD colSpan=2 height=21>
<DIV align=center>i在存储单元M<SPAN class=down>i</SPAN>中</DIV></TD>
<TD colSpan=2 height=21>
<DIV align=center>i在栈中</DIV></TD></TR>
<TR>
<TD height=22 width="23%">
<DIV align=center>代码</DIV></TD>
<TD height=22 width="6%">
<DIV align=center>开销</DIV></TD>
<TD height=22 width="24%">
<DIV align=center>代码</DIV></TD>
<TD height=22 width="6%">
<DIV align=center>开销</DIV></TD>
<TD height=22 width="23%">
<DIV align=center>代码</DIV></TD>
<TD height=22 width="6%">
<DIV align=center>开销</DIV></TD></TR>
<TR>
<TD width="12%">
<DIV align=center>a:=b[i]</DIV></TD>
<TD height=2 width="23%">
<DIV align=center>MOV b(R<SPAN class=down>i</SPAN>),R</DIV></TD>
<TD height=2 width="6%">
<DIV align=center>2</DIV></TD>
<TD height=12 width="24%">
<DIV align=center>MOV M<SPAN class=down>i</SPAN>,R<SPAN 
class=down>i</SPAN><BR>MOV b(R),R</DIV></TD>
<TD height=12 width="6%">
<DIV align=center>4</DIV></TD>
<TD height=12 width="23%">
<DIV align=center>MOV S<SPAN class=down>i</SPAN>(A),R<BR>MOV b(R),R</DIV></TD>
<TD height=12 width="6%">
<DIV align=center>4</DIV></TD></TR>
<TR>
<TD height=2 width="12%">
<DIV align=center>a[i]:=b</DIV></TD>
<TD height=2 width="23%">
<DIV align=center>MOV b,a(R<SPAN class=down>i</SPAN>)</DIV></TD>
<TD height=2 width="6%">
<DIV align=center>3</DIV></TD>
<TD height=2 width="24%">
<DIV align=center>MOV Mi,R<BR>MOV b,a(R)</DIV></TD>
<TD height=2 width="6%">
<DIV align=center>5</DIV></TD>
<TD height=2 width="23%">
<DIV align=center>MOV Si(A),R<BR>MOV b,a(R)</DIV></TD>
<TD height=2 width="6%">
<DIV align=center>5</DIV></TD></TR></TBODY></TABLE>
<P>表8.5给出了由指针赋值a:=*p和*p:=a生成的目标代码。p的当前位置决定了生成什么样的代码。类似先前,可概括为以下三种情况:p开始在寄存器Rp中;在存储单元Mp中;在一个栈中,其偏移地址为Sp且指向适用于p的活动记录的指针在寄存器A内。寄存器R是在调用函数getreg之后返回的寄存器。在第二个赋值中我们假定a是静态分配的。</P>
<P align=center>表8.5&nbsp&nbsp指针赋值的代码序列</P>
<TABLE align=center border=1 cellPadding=5 cellSpacing=0 height=45 width="87%">
<TBODY>
<TR>
<TD height=102 rowSpan=2 width="12%">
<DIV align=center>语句</DIV></TD>
<TD colSpan=2 height=21>
<DIV align=center>p在寄存器R<SPAN class=down>p</SPAN>中</DIV></TD>
<TD colSpan=2 height=21>
<DIV align=center>在存储单元M<SPAN class=down>p</SPAN>中</DIV></TD>
<TD colSpan=2 height=21>
<DIV align=center>p在栈中</DIV></TD></TR>
<TR>
<TD height=22 width="23%">
<DIV align=center>代码</DIV></TD>
<TD height=22 width="6%">
<DIV align=center>开销</DIV></TD>
<TD height=22 width="24%">
<DIV align=center>代码</DIV></TD>
<TD height=22 width="6%">
<DIV align=center>开销</DIV></TD>
<TD height=22 width="23%">
<DIV align=center>代码</DIV></TD>
<TD height=22 width="6%">
<DIV align=center>开销</DIV></TD></TR>
<TR>
<TD width="12%">
<DIV align=center>a:=*p</DIV></TD>
<TD height=2 width="23%">
<DIV align=center>MOV *R<SPAN class=down>p</SPAN>,a</DIV></TD>
<TD height=2 width="6%">
<DIV align=center>2</DIV></TD>
<TD height=12 width="24%">
<DIV align=center>MOV Mp,R<BR>MOV *R,R</DIV></TD>
<TD height=12 width="6%">
<DIV align=center>3</DIV></TD>
<TD height=12 width="23%">
<DIV align=center>MOV Sp(A),R<BR>MOV *R,R</DIV></TD>
<TD height=12 width="6%">
<DIV align=center>3</DIV></TD></TR>
<TR>
<TD height=2 width="12%">
<DIV align=center>*p:=a</DIV></TD>
<TD height=2 width="23%">
<DIV align=center>MOV a,*R<SPAN class=down>p</SPAN></DIV></TD>
<TD height=2 width="6%">
<DIV align=center>2</DIV></TD>
<TD height=2 width="24%">
<DIV align=center>MOV Mp,R<BR>MOV a,*R</DIV></TD>
<TD height=2 width="6%">
<DIV align=center>4</DIV></TD>
<TD height=2 width="23%">
<DIV align=center>MOV a,R<BR>MOV R,*S<SPAN class=down>p</SPAN>(A)</DIV></TD>
<TD height=2 width="6%">
<DIV align=center>4</DIV></TD></TR></TBODY></TABLE>


</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.2c.htm'"></td>
<td><img src="../images/next.gif" onmouseover="javascript:style.cursor='hand'" onclick="vbscript:window.location.href='8.5.2_2b.htm'"></img></td>
</tr>
</table>

</BODY>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -