4-2.htm

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

HTM
561
字号
                        
    =-4<sub>ten</sub></font></font>                                                         
    </li>                                                           
  <li>                                                                    
    <p align="left"><font color="#000000" size="4">数的小数表示:设x=x<sub>0</sub>.x<sub>1</sub>x<sub>2</sub>...x<sub>n</sub><br>                                                     
    <img border="0" src="images/4-2-pic1.gif" width="451" height="80">                                                 
    </font>                                                 
    </li>                                                   
  <li>                                                             
    <p align="left"><font color="#000000" size="4">硬件对软件的接口支持:<br>                                                
    &nbsp;&nbsp;&nbsp; 在硬件中,内存地址从0一直到最大地址,换句话说就是没有负数地址。然而程序有时候既要处理正数和负数,有时候只处理正数,因此程序设计语言必须声明以示区别。在C语言中第一种情况可以声明为<i>integers                                                       
    </i>(declared as <i>int </i>in the program),后一种情况可以声明为<i>unsigned                                                       
    integers </i>(unsigned int)。<br>                                                     
    &nbsp;&nbsp;&nbsp; comparison instructions必须能够处理两种情况。有符号数和无符号的数;对unsigned                                                       
    integers,最高位为1的数一定比最高位为0的数大。MIPS提供了两种不同的比较指令:<i>set on less than </i>(slt) and <i>set                                                       
    on less than immediate </i>(slti) work with signed integers; <i>set on less                                                       
    than unsigned </i>(sltu) and <i>set on less than immediate unsigned</i>  (sltiu)。<br>                                                     
    Example: Suppose register $16 has the binary number<br>                                                      
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;                                                      
    1111 1111 1111 1111 1111 1111                                                       
    1111 1111<sub>two</sub><br>                                                      
    and that register $17 has the binary number<br>                                                     
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;                                                     
    0000 0000 0000 0000 0000 0000 0000 0001<sub>two</sub> &nbsp;<br>                                                   
    What are the values of registers $8 and $9 after these two                                                    
    instructions?<br>                                                   
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; slt&nbsp;&nbsp;&nbsp;                                                    
    $8,$16,$17 #signed comparison<br>                                                   
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;                      
    sltu&nbsp;&nbsp; $9,$16,$17 #unsigned comparison<br>                                                   
    Answer:如果$16是一个integer则其值为-1,如果$16是一个unsigned                                                    
    integer则其值为4,294,967,295<sub>ten</sub>。因此register $8 has the value 1,由于-1<sub>ten</sub>&lt;1<sub>ten</sub>;register                                                
    $9 has the value 0,由于4,294,967,295<sub>ten</sub>&gt;1<sub>ten</sub>;</font>                                            
    </li>                                                
  <li>                                                                  
    <p align="left"><font color="#000000" size="4">计算机如何求一个二进制数的负数:<br>                                          
    在进行加减运算之前,我们首先给二进制数取反码(invert                                             
    every 0 to 1 and every 1 to 0,then add 1 to the result。<br>                                            
    Example: Negate 2<sub>ten</sub>,and then check the result by negating -2<sub>ten</sub>.<br>                                            
    Answer:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 2<sub>ten</sub>=000 0000                                           
    0000 0000 0000 0000 0000 0010<sub>two</sub><br>                                          
    Negating this number by inverting the bits and adding 1:<br>                                         
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;                                          
    1111 1111 1111 1111 1111 1111 1111 1101<sub>two</sub><br>                                         
    &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;&nbsp;  
    1<sub>two<br>                                     
    </sub>&nbsp;&nbsp;&nbsp;&nbsp;&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 1110<sub>two</sub><br>                                       
    &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;                                     
    -2<sub>ten</sub><br>                                    
    Going the other direction,1111 1111 1111 1111 1111 1111 1111 1110<sub>two</sub>is                                     
    first inverted and then incremented:<br>                                    
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;                                   
    0000 0000 0000 0000 0000 0000                                     
    0000 0001<sub>two<br>                                   
    &nbsp; </sub>+&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;&nbsp;  
    1<sub>two</sub><br>                               
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; --------------------------------------------<br>                                 
    &nbsp; =&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 0000 0000 0000 0000 0000 0000 0000 0010<sub>two&nbsp;</sub></font>                               
    </li>                                 
</ol>                         
    <p align="left"><font size="4">&nbsp;&nbsp; <font color="#000000"><sub>由于数:</sub>1111 1111 1111 1111 1111 1111 1111 1110<sub>two的符号位为1,故有值:</sub><br>                                
    &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;  
    2<sub>ten</sub>                               
    </font> 
    </font> 
<p align="left"><font color="#000000" size="4">7&nbsp;&nbsp; 符号扩展技术(sign extension)<br>                              
&nbsp;&nbsp;&nbsp;&nbsp; 如何能够把一个n位的数替换成一个多于n位的数。在MIPS中计算机数为32位,在存储、输出、转移、比较的指令中,立即数为16bits的补码,从-32768到32767。如果要把立即数存到a                               
    32-bit register中,计算机必须能够把16-bit的数字转换成32-bit的等价数。将立即数的右面16位保持不变,将符号位复制(replicate)到新的左边的16位中。<br>                              
    Example: Convert 16-bit binary versions of 2<sub>ten</sub>and -2<sub>ten</sub>to                              
    32-bit binary numbers.<br>                             
    Answer: The 16-bit binary version of the number 2 is<br>                             
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;                              
    0000 0000 0000 0010<sub>two</sub>=2<sub>ten</sub><br>                             
    It is converted to a 32-bit number by making 16 copies of the value in the                             
    most significant bit(0) and placing that in the left-hand half of the word.                             
    The right half get the old value:<br>                            
    &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>                            
    Let's negate the 16-bit version of 2.Thus 0000 0000 0000 0010 becomes<br>                           
    &nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp; 1111 1111 1111 1110<sub>two</sub><br>                          
    Creating a 32-bit version of the negative number means copying the sign bit                           
    16 times and placing it on the left:<br>                          
    &nbsp;&nbsp;&nbsp;&nbsp; 1111 1111 1111 1111 1111 1111 1111 1110<sub>two</sub>=-2<sub>ten</sub>                         
    </font>                         
</p> 
    <p align="left"><font color="#000000" size="4">8。 数的其他表示方式:<br>                      
    A)16进制(hexadecimal)0--9,A--F<br>                      
    B)8进制0--7<br>                      
    C)移码表示(biased notation)<br>                         
     移码将在浮点数(floating point number)中用到。<br>                        
    例如在4-bit的数中,移码即在原补码的表示数基础上加上2<sup>3</sup>,这样0数是1000,最小负数是0000(-8)。例:在N×2<sup>E</sup>中,e<sub>移码</sub>=E+基数值。</font>                     
<p align="left"><font color="#000000" size="4">如在4-bit的数中,基数值=2<sup>4-1</sup></font>                         
<p align="left"><font color="#000000" size="4">五:<a name="本节补充:">本节补充:</a></font><p align="left"><font color="#000000" size="4">本节主要讲了在计算机语言中正整数和负整数的表示,Figure                       
4.1给出了在本节中涉及的MIPS assembly language。</font><p align="center"><font color="#000000" size="4">FIFURE                      
4.1 MIPS architecture revealed thus far.</font>                     
<div align="center">                     
  <center>                     
  <table border="1" cellpadding="0" cellspacing="0" width="97%" height="172" bordercolordark="#CC9966" bordercolorlight="#FFCC66">                     
    <tr>                     
      <td width="15%" height="19">                     
        <p align="center"><font color="#000000" size="4">Category</font></td>                   
      <td width="27%" height="19">                   
        <p align="center"><font color="#000000" size="4">&nbsp;Instruction</font></td>                   
      <td width="19%" height="19">                   
        <p align="center"><font color="#000000" size="4">Example</font></td>                   
      <td width="18%" height="19">                   
        <p align="center"><font color="#000000" size="4">Meaning</font></td>                   
      <td width="21%" height="19">                   
        <p align="center"><font color="#000000" size="4">Comments</font></td>                   
    </tr>                   
    <tr>                   
      <td width="15%" height="54">                   
        <p align="center"><font color="#000000" size="4">Arithmetic</font></td>                   
      <td width="27%" height="54">                   
        <div align="center">                   
          <table border="0" cellpadding="0" cellspacing="0" width="100%">                   
            <tr>                   
              <td width="100%"><font color="#000000" size="4">add</font></td>                   
            </tr>                   
            <tr>                   
              <td width="100%"><font color="#000000" size="4">subtract</font></td>                   
            </tr>                   
            <tr>                   
              <td width="100%"><font color="#000000" size="4">addi</font></td>                   
            </tr>                   
          </table>                   
        </div>                   
      </td>                   
      <td width="19%" height="54">                   
        <div align="center">                   
          <table border="0" cellpadding="0" cellspacing="0" width="100%">                   
            <tr>                   

⌨️ 快捷键说明

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