📄 4-7.htm
字号:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<meta name="GENERATOR" content="Microsoft FrontPage 4.0">
<meta name="ProgId" content="FrontPage.Editor.Document">
<title>Division 除法运算</title>
<meta name="Microsoft Theme" content="arcs 001">
</head>
<body background="arctile.jpg" bgcolor="#FFFFFF" text="#000000" link="#3399FF" vlink="#666666" alink="#FF9900">
<h3 align="center"><font color="#000000" size="6"><b>4.7 Division 除法运算</b></font></h3>
<p align="right"><font color="#000000"><a href="chapter4.htm"><img border="0" src="images/BACK.GIF" width="60" height="45" align="left"></a>
<a href="4-6.htm"><img border="0" src="images/PREV.GIF" width="60" height="45"></a>
<a href="4-8.htm"><img border="0" src="images/FORW.GIF" width="60" height="45"></a> </font></p>
<p align="left"><font color="#000000" size="4">本节问题:</font></p>
<p align="left"><font color="#000000" size="4"><img border="0" src="images/SUB.GIF" width="26" height="27"><a href="#除法的基本原理">除法的基本原理</a><br>
<img border="0" src="images/SUB.GIF" width="26" height="27"><a href="#第一代除法算法和硬件设计">第一代除法算法和硬件设计</a><br>
<img border="0" src="images/SUB.GIF" width="26" height="27"><a href="#第二代除法算法和硬件设计">第二代除法算法和硬件设计</a><br>
<img border="0" src="images/SUB.GIF" width="26" height="27"><a href="#第三代除法算法和硬件设计">第三代除法算法和硬件设计</a><br>
<img border="0" src="images/SUB.GIF" width="26" height="27"><a href="#加减交替法">加减交替法</a><br>
<img border="0" src="images/SUB.GIF" width="26" height="27"><a href="#带符号数除法运算">带符号数除法运算</a><br>
<img border="0" src="images/SUB.GIF" width="26" height="27"><a href="#MIPS机除法的实现">MIPS机除法的实现</a></font></p>
<p align="left"><font color="#000000" size="4">一:<a name="除法的基本原理">除法的基本原理</a></font></p>
<p align="left"> <font color="#000000" size="4"> 我们根据十进制手工运算方法回忆除法基本原理,divide 1001010<sub>ten</sub>
by 1000<sub>ten</sub>。<br>
1001<sub>ten</sub> Quotient<br>
__________<br>
Divisor1000<sub>ten</sub>|1001010<sub>ten</sub>
Dividend<br>
-1000<br>
________<br>
001010<br>
-1000<br>
<br>
<br>
_______ <br>
10<sub>ten</sub> Remainder<br>
Dividend=Quotient × Divisor + Remainder<br>
这里Remainder要小于Divisor,二进制除法的原理同上。</font></p>
<p align="left"><font color="#000000" size="4">二:<a name="第一代除法算法和硬件设计">第一代除法算法和硬件设计</a></font></p>
<p align="left"><font color="#000000" size="4"> 具体的算法和流程图如下,同时我们需要32-bit Quotient register并将其初始化为0,每一步需要将divisor向右移动一位,因此我们还需要64-bit
Divisor rigister并将Divisor赋于Divisor register的左半部分并每一步向右移动一位。</font></p>
<p align="center"><font color="#000000" size="4"><img border="0" src="images/4-7-pic1.gif" width="721" height="406"></font></p>
<p> <font color="#000000" size="4"> Example: Using a 4-bit
version of the algorithm to save pages, let's try dividing 7<sub>ten</sub> by <br>
2<sub>ten</sub> or 0000 0111<sub>two</sub> by 0010<sub>two</sub>.<br>
Answer:这种方法需要运行n+1步,每一步中的step2通过检测remainder
register 的符号位来看<br>
remainder是正还是负。如下表:</font></p>
<p align="center"> </p>
<div align="center">
<center>
<table border="1" cellpadding="0" cellspacing="0" width="648" height="231" bordercolordark="#CC9966" bordercolorlight="#FFCC66">
<tr>
<td width="87" height="17" bgcolor="#CCFF99">
<p align="center"><font color="#000000" size="4">Iteration</font></td>
<td width="243" height="17" bgcolor="#CCFF99">
<p align="center"><font color="#000000" size="4">Step</font></td>
<td width="99" height="17" bgcolor="#CCFF99">
<p align="center"><font color="#000000" size="4">Quotient</font></td>
<td width="116" height="17" bgcolor="#CCFF99">
<p align="center"><font color="#000000" size="4">Divisor</font></td>
<td width="91" height="17" bgcolor="#CCFF99">
<p align="center"><font color="#000000" size="4">Remainder</font></td>
</tr>
<tr>
<td width="87" height="19">
<p align="center"><font color="#000000" size="4">0</font></td>
</center>
<td width="243" height="19">
<p align="left"><font color="#000000" size="4">Initial Values</font></td>
<center>
<td width="99" height="19">
<p align="center"><font color="#000000" size="4">0000</font></td>
<td width="116" height="19">
<p align="center"><font color="#000000" size="4">0010 0000</font></td>
<td width="91" height="19">
<p align="center"><font color="#000000" size="4">0000 0111</font></td>
</tr>
<tr>
<td width="87" height="56" rowspan="3">
<p align="center"><font color="#000000" size="4">1</font></td>
</center>
<td width="243" height="18">
<p align="left"><font color="#000000" size="4">1: Rem=Rem-Div</font></td>
<center>
<td width="99" height="18">
<p align="center"><font color="#000000" size="4">0000</font></td>
<td width="116" height="18">
<p align="center"><font color="#000000" size="4">0010 0000</font></td>
<td width="91" height="18">
<p align="center"><font color="#000000" size="4">1110
0111</font></td>
</tr>
</center>
<tr>
<td width="243" height="17">
<p align="left"><font color="#000000" size="4">2b:Rem<0 =>+Div,sll
Q,Q0=0 </font></td>
<center>
<td width="99" height="17">
<p align="center"><font color="#000000" size="4">0000</font></td>
<td width="116" height="17">
<p align="center"><font color="#000000" size="4">0010 0000</font></td>
<td width="91" height="17">
<p align="center"><font color="#000000" size="4">0000 0111</font></td>
</tr>
</center>
<tr>
<td width="243" height="21">
<p align="left"><font color="#000000" size="4">3: Shift Div right</font></td>
<center>
<td width="99" height="21">
<p align="center"><font color="#000000" size="4">0000</font></td>
</center>
<td width="116" height="21">
<p align="center"><font color="#000000" size="4">0001 0000</font></td>
<center>
<td width="91" height="21">
<p align="center"><font color="#000000" size="4">0000 0111</font></td>
</tr>
<tr>
<td width="87" height="56" rowspan="3">
<p align="center"><font color="#000000" size="4">2</font></td>
</center>
<td width="243" height="19">
<p align="left"><font color="#000000" size="4">1: Rem=Rem-Div</font></td>
<center>
<td width="99" height="19">
<p align="center"><font color="#000000" size="4">0000</font></td>
<td width="116" height="19">
<p align="center"><font color="#000000" size="4">0001 0000</font></td>
<td width="91" height="19">
<p align="center"><font color="#000000" size="4">1111
0111</font></td>
</tr>
</center>
<tr>
<td width="243" height="18">
<p align="left"><font color="#000000" size="4">2b:Rem<0 =>+Div,sll
Q,Q0=0 </font></td>
<center>
<td width="99" height="18">
<p align="center"><font color="#000000" size="4">0000</font></td>
<td width="116" height="18">
<p align="center"><font color="#000000" size="4">0001 0000</font></td>
<td width="91" height="18">
<p align="center"><font color="#000000" size="4">0000 0111</font></td>
</tr>
</center>
<tr>
<td width="243" height="19">
<p align="left"><font color="#000000" size="4">3: Shift Div right</font></td>
<center>
<td width="99" height="19">
<p align="center"><font color="#000000" size="4">0000</font></td>
<td width="116" height="19">
<p align="center"><font color="#000000" size="4">0000 1000</font></td>
<td width="91" height="19">
<p align="center"><font color="#000000" size="4">0000 0111</font></td>
</tr>
<tr>
<td width="87" height="51" rowspan="3">
<p align="center"><font color="#000000" size="4">3</font></td>
</center>
<td width="243" height="17">
<p align="left"><font color="#000000" size="4">1: Rem=Rem-div</font></td>
<center>
<td width="99" height="17">
<p align="center"><font color="#000000" size="4">0000</font></td>
<td width="116" height="17">
<p align="center"><font color="#000000" size="4">0000 1000</font></td>
<td width="91" height="17">
<p align="center"><font color="#000000" size="4">1111
1111</font></td>
</tr>
</center>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -