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

📄 4.htm

📁 浙江大学计算机学院计算机组成教材《计算机组成与设计》(潘学增)的课堂教学课件。
💻 HTM
字号:
<html>

<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>计算机对过程的支持 </title>


<meta name="Microsoft Theme" content="arcs 011">
<meta name="Microsoft Border" content="none">
</head>

<body background="arctile.jpg" bgcolor="#FFFFFF" text="#000000" link="#3399FF" vlink="#666666" alink="#FF9900">

<p align="center"><font color="#000000">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;        
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;        
&nbsp;&nbsp;<b><font size="6">3.4 </font></b> <strong><big><big><big>计算机对过程的支持</big></big></big>        
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;        
&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</strong></font></p>      
      
<p align="right"><font color="#000000"><a href="index.htm"><img border="0" src="../images/back.gif" align="left" width="60" height="45"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;       
<a href="3.htm"><img border="0" src="../images/prev.gif" width="60" height="45"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;       
<a href="5.htm"><img border="0" src="../images/forw.gif" width="60" height="45"></a></font></p>      
      
<p><strong><font color="#000000">&nbsp;&nbsp;&nbsp;&nbsp; <font size="4">子程序是程序员实现程序结构化的一条有效途径。</font></font></strong></p>   
   
<p><strong><font color="#000000" size="4">&nbsp;&nbsp;&nbsp;&nbsp; 首先让我们来看看支持子程序过程调用的最基本的操作:MIPS提供了一条指令jal(<em>jump     
and link</em>),它的功能是把紧位于jal下的指令地址保存到寄存器$31中,然后跳转到子程序,即跳转和链接。这时$31=PC+4,  
PC是指令jal的地址。</font></strong></p>    
    
<p><strong><font color="#000000" size="4">&nbsp;&nbsp;&nbsp; 比如:&nbsp; jal        
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Procedure   
Address</font></strong></p>      
      
<p><strong><font color="#000000" size="4">我们已经有一条指令jr(jump register)用于链接的.可以用它来执行跳回操作。</font></strong></p>       
       
<p><strong><font color="#000000" size="4">&nbsp;&nbsp;&nbsp; 比如:&nbsp; jr        
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; $31        
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font> </strong></p>       
       
<p><strong><font color="#000000" size="4">这也正是寄存器$31的通常用途所在。对于参数的保存,有两种方法:调用者保存和被调用者保存。现在约定:通常采用被调用者保存,并且$4,$5,$6,$7是专门用以保存参数的。</font></strong></p>    
    
<p><strong><font color="#000000" size="4">下面我们举例来说明:</font></strong></p>    
    
<p><strong><font color="#000000" size="4">假设程序A调用B,B又调用C,C不调用任何其他程序。下面的图中展示了我们在这个程序中所必须执行的步骤:</font></strong></p>    
    
<p><strong><font color="#000000" size="4">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1.&nbsp;<img border="0" src="../images/sub.gif" width="26" height="27">&nbsp; 在       
A 调用 B 后</font></strong></p>      
      
<p><strong><font color="#000000"><font size="4">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
</font>     
</font> </strong><font color="#000000"><!--webbot bot="ImageMap" startspan
text="(307,49) (428, 82) {Memory
} {宋体} 10 B #000000 CT 0  "
text="(65,121) (196, 154) {$29 } {宋体} 10 B #000000 CT 0  "
text="(89,47) (159, 67) {$31} {宋体} 10 B #000000 CT 0  "
text="(62,87) (193, 129) {B's return address} {宋体} 10 B #000000 CT 0  "
src="images/43.bmpO.gif" alt="未命名.bmp (589878 bytes)" border="0"
u-originalsrc="43.bmpO.gif" u-overlaysrc="../_overlay/4.htm_txt_43.bmpO.gif"
width="512" height="384" --><img src="../_overlay/4.htm_txt_43.bmpO_cmp.gif" alt="未命名.bmp (589878 bytes)" border="0" width="512" height="384"><!--webbot
bot="ImageMap" I-CheckSum="9826" endspan --></font></p>

<p><strong><font color="#000000" size="4">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2.&nbsp;<img border="0" src="../images/sub.gif" width="26" height="27">&nbsp; 在B调用C前</font></strong></p>       
       
<p><strong><font color="#000000" size="4">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font> </strong></p>     
     
<p><font color="#000000" size="4"><strong>&nbsp;&nbsp; </strong>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
<!--webbot bot="ImageMap" startspan
text="(256,125) (454, 145) {B's return address} {宋体} 10 B #000000 CT 0  "
text="(320,46) (390, 66) {Memory} {宋体} 10 B #000000 CT 0  "
text="(67,86) (191, 128) {B's return address} {宋体} 10 B #000000 CT 0  "
text="(80,119) (179, 139) {$29} {宋体} 10 B #000000 CT 0  "
text="(92,46) (162, 66) {$31} {宋体} 10 B #000000 CT 0  http://"
src="images/44.bmpO.gif" alt="未命名.bmp (589878 bytes)" border="0"
u-originalsrc="44.bmpO.gif" u-overlaysrc="_overlay/4.htm_txt_44.bmpO.gif"
width="512" height="384" --><img src="_overlay/4.htm_txt_44.bmpO_cmp.gif" alt="未命名.bmp (589878 bytes)" border="0" width="512" height="384"><!--webbot
bot="ImageMap" I-CheckSum="55975" endspan --></font></p>

<p><font color="#000000" size="4">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3.&nbsp;<img border="0" src="../images/sub.gif" width="26" height="27">&nbsp;       
<strong>在B调用C后</strong></font></p>      
      
<p><font color="#000000" size="4">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
<!--webbot bot="ImageMap" startspan
text="(315,54) (385, 74) {Memory} {宋体} 10 B #000000 CT 0  "
text="(267,125) (465, 145) {B's return address} {宋体} 10 B #000000 CT 0  "
text="(95,120) (165, 140) {$29} {宋体} 10 B #000000 CT 0  "
text="(34,84) (232, 117) {C's return 
address} {宋体} 10 B #000000 CT 0  "
text="(96,55) (166, 75) {$31} {宋体} 10 B #000000 CT 0  "
src="images/bamp.gif" alt="bamp.bmp (589878 bytes)" border="0"
u-originalsrc="bamp.gif" u-overlaysrc="_overlay/4.htm_txt_bamp.gif" width="512"
height="384" --><img src="_overlay/4.htm_txt_bamp_cmp.gif" alt="bamp.bmp (589878 bytes)" border="0" width="512" height="384"><!--webbot
bot="ImageMap" I-CheckSum="13450" endspan --></font></p>

<p><font color="#000000" size="4">&nbsp;&nbsp;&nbsp;&nbsp; 4.&nbsp;<img border="0" src="../images/sub.gif" width="26" height="27">&nbsp;       
<strong>在B返回后</strong></font></p>      
      
<p><font color="#000000" size="4">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 
<!--webbot bot="ImageMap" startspan
text="(261,157) (459, 177) {B's return address} {宋体} 10 B #000000 CT 0  "
text="(318,51) (388, 71) {Memeory} {宋体} 10 B #000000 CT 0  "
text="(89,120) (159, 153) {$29
} {宋体} 10 B #000000 CT 0  "
text="(30,85) (228, 118) {B's return 
address} {宋体} 10 B #000000 CT 0  "
text="(91,54) (161, 74) {$31} {宋体} 10 B #000000 CT 0  " src="images/2.gif"
alt="2.bmp (589878 bytes)" border="0" u-originalsrc="2.gif"
u-overlaysrc="_overlay/4.htm_txt_2.gif" width="512" height="384" --><img src="_overlay/4.htm_txt_2_cmp.gif" alt="2.bmp (589878 bytes)" border="0" width="512" height="384"><!--webbot
bot="ImageMap" I-CheckSum="11411" endspan --></font></p>

<p><strong><font color="#000000"><font size="4">在调用C之前,程序B必须将它自己的返回地址存储在寄存器$31中,并且把堆栈指针指向堆栈的新顶端</font></font></strong><font color="#000000">。<strong>因此,C被调用,并且指令</strong></font></p>

<p><strong><em><font color="#000000"><font size="4">jal</font></font></em> <font size="4"> <font color="#000000"> 将寄存器$31改变为存储C的返回地址。在程序C返回到程序B之后,这个旧的返回值从寄存器$31中被重新存储,并且堆栈指针</font></font></strong></p>       
       
<p><strong><font color="#000000" size="4">还原。</font></strong></p>     
     
<p><strong><font color="#000000" size="4">根据上面的分析,我们可以写出该程序的主体代码:</font></strong></p>     
     
<p><strong><font color="#000000" size="4">(我们假定寄存器$29保有堆栈指针,并且$24指向当前堆栈的顶端)</font></strong></p>     
     
<p><strong><font color="#000000" size="4">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; A:&nbsp; ...</font></strong></p>       
       
<p><strong><font color="#000000" size="4">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ...</font></strong></p>       
       
<p><strong><font color="#000000" size="4">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; jal&nbsp; B        
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;        
# call B and save return address in $31</font> </strong></p>       
       
<p><strong><font color="#000000" size="4">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; B:&nbsp; ...</font></strong></p>       
       
<p><strong><font color="#000000" size="4">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ...        
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;        
# now ready to call C&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font> </strong></p>       
       
<p><strong><font color="#000000" size="4">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; add &nbsp;        
$29,$29,$24        
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;        
# adjust stack to make room for next item</font></strong></p>       
       
<p><strong><font color="#000000" size="4">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sw        
&nbsp;&nbsp; $31,0($29)        
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;        
# save the return address</font></strong></p>       
       
<p><strong><font color="#000000" size="4">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; jal&nbsp; C        
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;        
# call C and save return address in $31</font></strong></p>       
       
<p><strong><font color="#000000" size="4">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;        
# return from C to next instruction</font></strong></p>       
       
<p><strong><font color="#000000" size="4">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; lw        
&nbsp;&nbsp; $31,0($29)        
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;        
# restore B's return address...</font></strong></p>       
       
<p><strong><font color="#000000" size="4">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; sub &nbsp;        
$29,$29,$24        
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;        
# adjust stack to pop B's return address</font></strong></p>       
       
<p><strong><font color="#000000" size="4">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ...</font></strong></p>       
       
<p><strong><font color="#000000" size="4">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ...</font></strong></p>       
       
<p><strong><font color="#000000" size="4">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; jr        
&nbsp;&nbsp;&nbsp; $31        
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;        
# return to routine that called B</font></strong></p>       
       
<p><strong><font color="#000000" size="4">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; C:&nbsp; ...</font></strong></p>       
       
<p><strong><font color="#000000" size="4">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ...</font></strong></p>       
       
<p><strong><font color="#000000" size="4">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; jr        
&nbsp;&nbsp;&nbsp; $31        
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;        
# return to routine that called C&nbsp;&nbsp;&nbsp;</font> </strong></p>       
       
<p><strong><font color="#000000"><font size="4">读者请从上面的汇编语言代码与图形的结合中,自行找到其密切联系,以加深“<em>对计算机对子程序的支持</em>”的理解</font>。</font></strong></p>    
    
<p> </p>    
    
<p> </p>    
    
<p> </p>    
</body>    
</html>    

⌨️ 快捷键说明

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