4-2.htm

来自「浙江大学计算机学院计算机组成教材《计算机组成与设计》(潘学增)的课堂教学课件。」· HTM 代码 · 共 561 行 · 第 1/4 页

HTM
561
字号
<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>Negative Numbers负数的表示</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.2 Negative Numbers负数的表示</b></font></h3>                                                                                                          
                                                                                                          
<p align="right"> <font color="#000000"> <a href="chapter4.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;<a href="4-1.htm"><img border="0" src="images/PREV.GIF" width="60" height="45"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;             
&nbsp;&nbsp; <a href="4-3.htm"><img border="0" src="images/FORW.GIF" width="60" height="45"></a>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font></p>                                                                                                    
                                                                                                    
<p align="left"> </p>                                                                                               
                                                                                                
<p align="left"><font color="#000000" size="4">本节问题:<br>         
<img border="0" src="images/SUB.GIF" width="26" height="27"><a href="#进位制的概念">进位制的概念</a><a href="#负数的表示"><br>        
</a><img border="0" src="images/SUB.GIF" width="26" height="27"><a href="#负数的表示">负数的表示</a><a href="#数的真值与机器数"><br>        
</a><img border="0" src="images/SUB.GIF" width="26" height="27"><a href="#数的真值与机器数">数的真值与机器数</a><a href="#机器数的四种表示形式"><br>        
</a><img border="0" src="images/SUB.GIF" width="26" height="27"><a href="#机器数的四种表示形式">机器数的四种表示</a><a href="#本节补充:"><br>        
</a><img border="0" src="images/SUB.GIF" width="26" height="27"><a href="#本节补充:">本节补充</a></font></p>                                                                                              
<p align="left"><font color="#000000" size="4">一:<a name="进位制的概念">进位制的概念</a><br>                                                                                           
minus infinity: The smallest [number that can be represented                                                                                                           
in a particular type of variable], not necessarily or even usually the simple                                                                                                           
negation of plus infinity.——Eric Raymond, The New Hacker's Dictionary,1991</font></p>                                                                                                          
<p align="left"><font color="#000000" size="4">&nbsp;&nbsp;&nbsp; 数字可以用很多种形式表示,但是人们喜欢用10进制,同样计算机喜欢用2进制。因为我们经常处理10进制和2进制数,为了避免混淆,我们用10和2分别作为十进制和二进制的下标。</font></p>                                                                                                         
<p align="left"><font color="#000000" size="4">The value of <i>i</i>th digit d                                                                                                           
:&nbsp;&nbsp;&nbsp; d×base<i>i</i></font></p>                                                                                                          
<p align="left"><font color="#000000" size="4"><i>i</i>从左到右以0开始依次增加1,这样就可以用指数的形式表示数了。</font></p>                                                                                                        
<p align="left"><font color="#000000" size="4">For example:1011<sub>two</sub> represents<br>                                                                                                          
&nbsp;&nbsp; (1×2<sup>3</sup>)+(0×2<sup>2</sup>)+(1×2<sup>1</sup>)+(1×2<sup>0</sup>)<sub>ten</sub><br>                                                                                                      
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;                                                                                                      
=(1×8)+(0×4)+(1×2)+(1×1)<sub>ten</sub><br>                                                                                                   
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;                                                                                                  
=8+0+2+1<sub>ten</sub><br>                                                                                                 
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;                                                                                               
=11<sub>ten</sub>                                                                                              
</font>                                                                                              
 </p>                                                                                                 
<p align="left"><font color="#000000" size="4">下面是数字在a MIPS word 中1011<sub>ten</sub>:</font>                                                                                              
 </p>                                                                                                 
<p align="center"><font color="#000000" size="4">(32 bits wide)</font>                                                                                             
 </p>                                                                                                
<div align="center">                                                                                             
  <center>                                                                                             
  <table border="1" cellpadding="0" cellspacing="0" width="94%" bordercolordark="#CC9966" bordercolorlight="#FFCC66">                                                                                             
    <tr>                                                                                             
      <td width="12%">                                                                                             
        <p align="center"><font color="#000000" size="4">0000</font></td>                                                                                           
      <td width="12%">                                                                                           
        <p align="center"><font color="#000000" size="4">0000</font></td>                                                                                           
      <td width="12%">                                                                                           
        <p align="center"><font color="#000000" size="4">0000</font></td>                                                                                           
      <td width="12%">                                                                                           
        <p align="center"><font color="#000000" size="4">0000</font></td>                                                                                           
      <td width="13%">                                                                                           
        <p align="center"><font color="#000000" size="4">0000</font></td>                                                                                           
      <td width="13%">                                                                                           
        <p align="center"><font color="#000000" size="4">0000</font></td>                                                                                           
      <td width="13%">                                                                                           
        <p align="center"><font color="#000000" size="4">0000</font></td>                                                                                           
      <td width="13%">                                                                                           
        <p align="center"><font color="#000000" size="4">1011</font></td>                                                                                           
    </tr>                                                                                           
  </table>                                                                                           
  </center>                                                                                           
</div>                                                                                           
<p align="left"><font color="#000000" size="4"><b><i>least significant bit</i></b>                                                                                            
被用来指代最右边的第0位,<b><i>most significant bit</i></b>                                                                                              
指代最左边的第31位。<br>                                                                                             
The MIPS word 有32bits长,因此我们可以有2<sup>32</sup>个不同的32位数字,从0到2<sup>32</sup>-1(4,294,967,295<sub>ten</sub>):<br>                                                                                         
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0000 0000 0000 0000 0000 0000 0000 0000<sub>two</sub>=0<sub>ten</sub><br>                                                                                         
                                                                                     
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0000 0000 0000 0000 0000 0000 0000 0001<sub>two</sub>=1<sub>ten</sub><br>                                                                                       
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0000 0000 0000 0000 0000 0000 0000 0010<sub>two</sub>=2<sub>ten</sub><br>                                                                                       
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ...<br>                                                                                     
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1111 1111 1111 1111 1111 1111 1111 1101<sub>two</sub>=4,294,967,293<sub>ten</sub><br>                                                                                      
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1111 1111 1111 1111 1111 1111 1111 1110<sub>two</sub>=4,294,967,294<sub>ten</sub><br>                                                                                      
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1111 1111 1111 1111 1111 1111 1111 1111<sub>two</sub>=4,294,967,295<sub>ten</sub><br>                                                                                      
                                                                                      
其他常用的还有八进制0-7,十六进制012...9ABCDEF。</font>                                                                                     
                                                                                     
 </p>                                                                                           
<p align="left"><font color="#000000" size="4">二:<a name="负数的表示">负数的表示</a>                                                                                   
                                                                                   
</font>                                                                                   
                                                                                   
 </p>                                                                                         
<p align="left"><font color="#000000" size="4">&nbsp;&nbsp;&nbsp; Computer programs calculate both positive and                                                                                     
negative numbers,因此我们要能够将负数和正数区分开来。由于a                                                                                     
32-bit word有很多个,必须在正数和负数之间找到平衡点(balanced),但是0没有正负之分,不能够有两种表示0的方式,so                                                                                     
32-bit computer 用如下的规则:<br>                                                                                    
&nbsp;&nbsp;&nbsp; the most significant bit表示符号位,0代表正数,1代表负数。因此硬件只需要检测most                                                                                     
significant bit就可以分辨正负数了。符号位被称为the <b><i>sign </i></b>bit。由于有了符号位,我们就可以通过下面的形式计算机出二进制数的十进制值。</font>                                                                              
                                                                              
 </p>                                                                                    
<p align="left"><font color="#000000" size="4">For example:&nbsp;&nbsp;&nbsp; (<i><b>x</b></i>31×2<sup>31</sup>)+(<i><b>x</b></i>30×2<sup>30</sup>)+(<b><i>x</i></b>29×2                                                                             
<sup>29</sup>)+...+(<b><i>x</i></b>1×2<sup>1</sup>)+(<i><b>x</b></i>0×2<sup>0</sup>)</font>                                                                                
                                                                                
 </p>                                                                                      
<p align="left"><font color="#000000" size="4">三:<a name="数的真值与机器数">数的真值与机器数</a>                                                                             
                                                                             
</font>                                                                             
                                                                             
 </p>                                                                                   
<p align="left"><font color="#000000" size="4">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 数学上的数叫数的真值,如-12;数在计算机中的二进制表示形式称为机器数,如四位数机器                   
数1111的真值为-1。MIPS 中有32位,则共有0--2<sup>32</sup>-1个不同的32位数,因此正数从0--2<sup>31</sup>-1(2,147,483,647),负数从-1                                                                                 
<sub>ten</sub>(1111...1111<sub>two</sub>)到-2,147,483,647<sub>ten</sub>(1000...0001<sub>two</sub>),只有一个负数-2147483648没有相对应的正数,同时上面的表示有符号二进制数的方法称为<b><i>two's                                                                                
complement</i></b>(补码)。</font>                                                                               
                                                                               
 </p>                                                                                     
<p align="left"><font color="#000000" size="4">四:<a name="机器数的四种表示形式">机器数的四种表示形式</a>                                                                            
                                                                            
</font>                                                                            
                                                                            
 </p>                                                                                  
<ol>                                                                       
  <li>                                                                       
    <p align="left"><font color="#000000" size="4">原码:(sign and magnitude)即数字的二进制形式前加上符号位。如四位原码:+3的原码为<b>0</b>011,-3的原码为<b>1</b>011。</font></li>                                                                         
  <li>                                                                         
    <p align="left"><font color="#000000" size="4">反码:(one's complement)对于整数的定义为,如果x为正数(&gt;=0),则其反码为其原码;如果x为负数,invert                                                                           
    every 0 to 1 and every 1 to 0,则其反码为2<sup>n</sup>+x-1。如四位二进制中,+3:0011;-3:2<sup>4</sup>-0011-0001=1100。又如+0:0000;<br>                                                                     
    -0:2<sup>4</sup>-0000-0001=1111。</font>                                                                     
  <li>                                                                     
    <p align="left"><font size="4"><font color="#000000">补码:(two's complement)对于整数的定义为,如果x为正数(&gt;=0),则其补码为其原码;如果x为负数,invert                                                                      
    every 0 to 1 and every 1 to 0,then add 1 to the result。<br>                                                                     
    对于整数而言,[x]<sub>补</sub>=2<sup>n</sup>+x。<br>                                                                    
    Example: x=-0.1011,[x]<sub>补</sub>=10.0000-0.1011=1.0101;<br>                                                                  
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; x=0.1011,[x]<sub>补</sub>=10.0000+0.1011=<b><u>1</u></b>0.1011最左边的溢出位舍去;<br>                                                                  
    特性:a: x+(-x)=0;&nbsp; b:+0和-0统一;&nbsp;&nbsp; c:求值方便,<b>连同符号位取反加一</b>。<br>                                                                 
    Example: What is the decimal value of this 32-bit two's complement number?<br>                                                                  
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 1111 1111 1111 1111 1111 1111                                                                   
    1111 1100<sub>two<br>                                                                  
    </sub>Answer: Substituting into the bit values in the formula above:<br>                                                                 
    &nbsp;&nbsp;&nbsp;-(0000 0000 0000 0000 0000 0000 0000 0011+0000 0000 0000  
    0000 0000 0000 0000 0001)<br>                                                            

⌨️ 快捷键说明

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