現(xiàn)代計算機-第4章2010ppt課件_第1頁
現(xiàn)代計算機-第4章2010ppt課件_第2頁
現(xiàn)代計算機-第4章2010ppt課件_第3頁
現(xiàn)代計算機-第4章2010ppt課件_第4頁
現(xiàn)代計算機-第4章2010ppt課件_第5頁
已閱讀5頁,還剩54頁未讀 繼續(xù)免費閱讀

下載本文檔

版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領

文檔簡介

1、第第4 4章章“定點數(shù)邏輯運算定點數(shù)邏輯運算/ /浮點數(shù)運算浮點數(shù)運算部分作業(yè):部分作業(yè):P136 P136 4-11,4-12 4-11,4-12Homework運算器部分內(nèi)容提要運算器部分內(nèi)容提要一一.定點數(shù)加定點數(shù)加/減法減法二二.定點數(shù)乘定點數(shù)乘/除法除法三三. 定點數(shù)邏輯運算定點數(shù)邏輯運算四四.浮點數(shù)的運算浮點數(shù)的運算 - 定點數(shù)加定點數(shù)加/減法運算方法減法運算方法及實現(xiàn)及實現(xiàn)- 定點數(shù)加定點數(shù)加/減法運算中的溢出問題減法運算中的溢出問題- 定點數(shù)乘法算法及實現(xiàn)定點數(shù)乘法算法及實現(xiàn)- 定點數(shù)除法算法及實現(xiàn)定點數(shù)除法算法及實現(xiàn)- 邏輯運算及實現(xiàn)邏輯運算及實現(xiàn)- 位移運算及實現(xiàn)位移運算及

2、實現(xiàn)- 浮點數(shù)運算及實現(xiàn)浮點數(shù)運算及實現(xiàn)三三.定點數(shù)邏輯運算定點數(shù)邏輯運算 定點數(shù)的邏輯運算 定點數(shù)的位移運算及實現(xiàn)定點數(shù)邏輯運算及實現(xiàn)定點數(shù)邏輯運算及實現(xiàn)- logical shifter (邏輯位移)- Arithmetic shifter (算數(shù)位移)- Circle shifter (循環(huán)位移)定點數(shù)的位移運算及實現(xiàn)定點數(shù)邏輯運算及實現(xiàn)定點數(shù)邏輯運算及實現(xiàn)- logical shifter (邏輯位移)- Arithmetic shifter (算數(shù)位移)- Circle shifter (循環(huán)位移) 定點數(shù)的邏輯運算定點數(shù)的邏輯運算 AND , OR , XOR , NOT , ec

3、t. - Do not concentrated on carry 運算:運算:實現(xiàn):實現(xiàn): 定點數(shù)的邏輯運算定點數(shù)邏輯運算及實現(xiàn)定點數(shù)邏輯運算及實現(xiàn)- logical shifter (邏輯位移)- Arithmetic shifter (算數(shù)位移)- Circle shifter (循環(huán)位移) 定點數(shù)的位移運定點數(shù)的位移運算及實現(xiàn)算及實現(xiàn)- do not concentrated on sign010100111010011000101001Example:logical left shifterlogical right shifter - no mater negative or po

4、sitive number after shifting ,their sign bit keeps unchangingRule of Arithmetic shifterRule of Arithmetic shifter1 010011000101001Arithmetic left shifterArithmetic right shifter101010011 (補碼)(補碼) 例:例:低位低位 1 移丟影響精度移丟影響精度11010011 (補碼)(補碼) 1 010011011101001高位高位 1 移丟移丟(正確正確)Arithmetic left shifterArithm

5、etic right shifter11低位低位 1 移丟影響精度移丟影響精度設機器數(shù)字長為設機器數(shù)字長為 8 位含一位符號位),寫出位含一位符號位),寫出A = +26時,三種機器數(shù)時,三種機器數(shù)左、右移一位和兩位后的表示形式及對應的真值,并分析結(jié)果的正確性。左、右移一位和兩位后的表示形式及對應的真值,并分析結(jié)果的正確性。解:解:A = +26那么那么 A原原 = A補補 = A反反 = 0,0011010 + 600,0 00110 +1300, 001101+1040,1101000 + 520,0110100 +260,0011010移位前移位前A原原=A補補=A反反對應的真值對應的真

6、值機機 器器 數(shù)數(shù)移位操作移位操作1212=+11010 Example 1設機器數(shù)字長為設機器數(shù)字長為 8 位含一位符號位),寫出位含一位符號位),寫出A = 26時,三種機器數(shù)左、時,三種機器數(shù)左、右移一位和兩位后的表示形式及對應的真值,并分析結(jié)果的正確性。右移一位和兩位后的表示形式及對應的真值,并分析結(jié)果的正確性。解:解:A = 26 61,0000110 131,0001101 1041,1101000 521,0110100 261,0011010移位前移位前對應的真值對應的真值機機 器器 數(shù)數(shù)移位操作移位操作1212原碼原碼= 11010 Example 2 61,1111001

7、131,1110010 1041,0010111 521,1001011 261,1100101移位前移位前對應的真值對應的真值機機 器器 數(shù)數(shù)移位操作移位操作1212 71,1111001 131,1 110011 1041,0011000 521,1001100 261,1100110移位前移位前對應的真值對應的真值機機 器器 數(shù)數(shù)移位操作移位操作1212補碼補碼反碼反碼Example 2 cont circle shifterE.g.Example 10selABDBasic Building Block8-bit right shifter10101010101010101010101

8、0101010101010101010101010S2 S1 S0A0A1A2A3A4A5A6A7R0R1R2R3R4R5R6R7 Example: Technology-dependent solutions: transistor per switchBasic switchBasic switchExample:For circle right shifter , choose “右一” & “左三”Technology-dependent solutions: transistor per switch 浮點數(shù)的加/減運算 浮點數(shù)的乘/除運算浮點數(shù)的算數(shù)運算浮點數(shù)的算數(shù)運算N

9、= Sr jScientific notationS mantissa j exponent r radiximplicit)In computer r = 2 or 4 or 8 or 16When r = 2N = 11.0101= 0.110101210 = 1.1010121 = 1101.012-10 = 0.001101012100 Inside computer S pure decimal、positive or Negativej integer、 positive or Negativenormalized The computer version of this nota

10、tion is called floating-pointBinaryjf j1 j2 jm Sf S1 S2 Sn j ExponentS SignificandSfn The number of bits determine precisionm The number of bits determine rangejf and m indicates place value (point position)Sign bit of Significand Magnitude of SignificandMagnitude of ExponentSign bit of Significand

11、of Exponent Sign of FP IEEE 754 A fraction with a nonzero leftmost digit is said to be normalized Condition of normalized FP : |S| |S| 1/2 |S| 0.1,XXXX |S| 1/4 |S| 0.01,XXXX |S| 1/16 |S| 0.0001,XXXXr = 2r = 4r = 16 For different radix , the normalized format of FP is different r = 2Shift the fractio

12、n left 1 bit and the exponent decreased by 1 r = 4r = 16positive number : 0.1 XXXX Negative number : 1.1 XXXXpositive number : 0.1 XXXXNegative number : 1.0 XXXXShift the fraction right 1 bit and the exponent increased by 1 Shift the fraction left 2 bits and the exponent decreased by 1 Shift the fra

13、ction right 2 bits and the exponent increased by 1 Shift the fraction left 4 bits(2 hexadecimal digits) and the exponent decreased by 1 Shift the fraction right 4 bits(2 hexadecimal digits) and the exponent increased by 1 Example:r = 2normalized fraction(sign and magnitude)normalized fraction(comple

14、ment)For a 32 bit number (8 bit exponent ,23 bit mantissa)Review of FP Ranges2( 2m1)( 1 2n)2( 2m1)212( 2m1)( 1 2n)2( 2m1)21最小負數(shù)最小負數(shù)最大負數(shù)最大負數(shù)最大正數(shù)最大正數(shù)最小正數(shù)最小正數(shù)負數(shù)區(qū)負數(shù)區(qū)正數(shù)區(qū)正數(shù)區(qū)下溢下溢0上溢上溢上溢上溢Overflow exponent biggest exponent that can be represented in this systemunderflow exponent smallest exponent that can b

15、e represented in this systemReview of FP RangesReview of Overflow/underflow for FPNormalized FP Overflow/underflow Conditions:Overflow : Exponent has a magnitude bigger than the biggest exponent number that can be represented in this system Cause a floating-point overflow trap.underflow : Exponent h

16、as a magnitude smaller than the smallest exponent number that can be represented in this system set the fraction to zero and continue. 浮點數(shù)的加/減運算 Check for zeros Align significands (adjusting exponents) Add or subtract significands Normalize resultFloating-Point addition Algorithm x = Sx 2jxy = Sy 2j

17、yj = jx jy = jx= jy jx jy jx jy adjusts small one to big oneSy 1, Sx 1, = 0 0 0jy+1 jx+1Method 1: mantissa which has small exponent right shift 1 bit, increment exponent 1,untill two numbers exponents are same Method 2: compute jx jy (getting ready to align binary point)alignedjy jxjx jyRule of alig

18、n :Example:1x = 0.1101 201 y = (0.1010) 211 Answer:x補補 = 00, 01; 00.1101 y補補 = 00, 11; 11.0110 j補補 = jx補補 jy補補= 2 00, 0111, 0111, 10Sx補補 = 00.0011 Sy補補= 11.011011.1001 Sx 2 jx+ 2 x+y補補 = 00, 11; 11. 1001x補補 = 00, 11; 00.0011 01+對階后的對階后的Sx補補 2. compute mantissa舍掉舍掉; x + y =?1. Align : x+y補補 = 00, 11;

19、 11. 1001Normalized : x+y補補 = 00, 10; 11. 0010 x + y = ( 0.1110)210 Example:1 cont3. normalizationleft shift result, decrement result exponent continue until MSB of data is disagree with sign bitx = 0.1101 210 y = 0.1011 201 x +y ?( exponent 3 bits,mantissa 6 bits) x補補 = 00, 010; 00. 110100y補補 = 00,

20、 001; 00. 101100j補補 = jx補補 jy補補 = 00, 010 11, 111100, 001 Sy 1, jy+1 y補補 = 00, 010; 00. 010110+Example:21. Align :Answer:x +y補補 = 00, 010; 01. 001010 x +y補補 = 00, 011; 00. 100101 x +y = 0. 100101 2113. normalizationExample:2 cont2. compute mantissaSx補補 = 00. 110100Sy補補 = 00. 010110 aligned Sy補01. 00

21、1010+Overflow and right normalized在在 對階對階 和和 右規(guī)右規(guī) 過程中,可能遇到舍入問題不同的舍入過程中,可能遇到舍入問題不同的舍入方法結(jié)果的精度不同。方法結(jié)果的精度不同。 (3) 0 舍舍 1 入法:遇入法:遇 0舍棄,遇舍棄,遇1則在保留末位加一則在保留末位加一(2) 恒置恒置 “1” 法法: 不管右移多少位,總將保留位抹位置不管右移多少位,總將保留位抹位置 1 常用舍入方法:常用舍入方法:(1) 截尾法截尾法 :遇舍入時:遇舍入時,將欲舍的尾數(shù)舍棄將欲舍的尾數(shù)舍棄浮點數(shù)加減運算的溢出由階碼來決定與尾數(shù)無關(guān)。但溢浮點數(shù)加減運算的溢出由階碼來決定與尾數(shù)無關(guān)

22、。但溢出的性質(zhì)由尾數(shù)的符號確定。尾數(shù)符號位為正,則為正出的性質(zhì)由尾數(shù)的符號確定。尾數(shù)符號位為正,則為正溢出。尾數(shù)符號位為負則為負溢出溢出。尾數(shù)符號位為負則為負溢出例例2:某次浮點加減運算結(jié)果為:某次浮點加減運算結(jié)果為 X + Y補補= 00.111 , 10.1011100111對其進行右規(guī)格化,即尾數(shù)左移一為成為:對其進行右規(guī)格化,即尾數(shù)左移一為成為:11.0101110011 階階碼應加碼應加1,成為,成為 01.000(大于大于+7),本次運算產(chǎn)生溢出,本次運算產(chǎn)生溢出(負溢出負溢出)。例例1:某次浮點加減運算結(jié)果為:某次浮點加減運算結(jié)果為 X + Y補補= 11.010 , 00.00

23、00110111對其進行左規(guī)格化,即尾數(shù)右移對其進行左規(guī)格化,即尾數(shù)右移4為成為:為成為:00.1101110000, 階碼應減階碼應減4,成為,成為 10.110(小于小于-8),本次運算產(chǎn)生溢出,本次運算產(chǎn)生溢出(正溢出正溢出)。 規(guī)格化如下溢規(guī)格化如下溢 按機器按機器0處理處理,上溢按溢出處理上溢按溢出處理x = ( )2-5 y = () 2-4 5878 x y =?( exponent 3 bits,mantissa 6 bits)x補補 = 11, 011; 11. 011000y補補 = 11, 100; 00. 111000j補補 = jx補補 jy補補 = 11, 011 00, 100 11, 111 Sx 1, jx+ 1 x補補 = 11, 100; 11. 101100 x = ( 0.101000)2-101y = ( 0.111000)2-100+Example:31. Align :Answer:Sx補補 = 11. 101100Sy補補 = 11. 001000+110.110100 x-y補補 = 11, 100; 10. 110100

溫馨提示

  • 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
  • 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。

最新文檔

評論

0/150

提交評論