資源描述:
《運(yùn)算方法與運(yùn)算部件08本.ppt》由會(huì)員上傳分享,免費(fèi)在線閱讀,更多相關(guān)內(nèi)容在教育資源-天天文庫。
1、計(jì)算機(jī)組成原理第三章運(yùn)算方法與運(yùn)算部件計(jì)算機(jī)中完成運(yùn)算的主要部件就是CPU中的算術(shù)邏輯運(yùn)算單元ALU計(jì)算機(jī)的運(yùn)算可以分為:數(shù)值運(yùn)算和非數(shù)值運(yùn)算數(shù)值運(yùn)算的基礎(chǔ)是定點(diǎn)與浮點(diǎn),其中以加法為核心1.定點(diǎn)加減運(yùn)算一、補(bǔ)碼加減運(yùn)算計(jì)算機(jī)中,常用補(bǔ)碼進(jìn)行加減運(yùn)算。補(bǔ)碼可將減法變加法進(jìn)行運(yùn)算。補(bǔ)碼運(yùn)算特點(diǎn):符號(hào)位與數(shù)值位一同運(yùn)算。運(yùn)算的基本規(guī)則:[X]補(bǔ)+[Y]補(bǔ)=[X+Y]補(bǔ)[X-Y]補(bǔ)=[X]補(bǔ)-[Y]補(bǔ)=[X]補(bǔ)+[-Y]補(bǔ)由[Y]補(bǔ)求得[-Y]補(bǔ)的方法:對[Y]補(bǔ)(包含符號(hào)位)求反且末位加1。1.[X]補(bǔ)+[Y]補(bǔ)=2·X0+X+2·Y0+Y=2(X0+Y0)+(X+Y)(1)若X0Y0
2、=00,則[X]補(bǔ)+[Y]補(bǔ)=X+Y=[X+Y]補(bǔ);(2)若X0Y0=01或10,則[X]補(bǔ)+[Y]補(bǔ)=2+(X+Y)當(dāng)X+Y>0時(shí),2+(X+Y)>2,進(jìn)位丟失,得:[X]補(bǔ)+[Y]補(bǔ)=X+Y=[X+Y]補(bǔ);當(dāng)X+Y<0時(shí),[X]補(bǔ)+[Y]補(bǔ)=2+(X+Y)=[X+Y]補(bǔ);(3)若X0Y0=11,則[X]補(bǔ)+[Y]補(bǔ)=4+(X+Y)=2+[2+(X+Y)]∵0>X+Y≥-1,∴2>2+(X+Y)≥1此時(shí),[X]補(bǔ)+[Y]補(bǔ)=2+(X+Y)=[X+Y]補(bǔ)(2自然丟失)在模2下,設(shè)[X]補(bǔ)=X0X1X2…Xn,[Y]補(bǔ)=Y0Y1Y2…Yn則[X]補(bǔ)=2·X0+X,[Y]補(bǔ)=2·Y0
3、+Y證明:2、∵[X]補(bǔ)+[Y]補(bǔ)=[X+Y]補(bǔ)∴[Y]補(bǔ)=[X+Y]補(bǔ)-[X]補(bǔ)……①又∵[X-Y]補(bǔ)=[X+(-Y)]補(bǔ)=[X]補(bǔ)+[-Y]補(bǔ)∴[-Y]補(bǔ)=[X-Y]補(bǔ)-[X]補(bǔ)……②①+②得:[Y]補(bǔ)+[-Y]補(bǔ)=[X+Y]補(bǔ)-[X]補(bǔ)+[X-Y]補(bǔ)-[X]補(bǔ)=[X+Y+X-Y]補(bǔ)-[X]補(bǔ)-[X]補(bǔ)=[X+X]補(bǔ)-[X]補(bǔ)-[X]補(bǔ)=0∴[-Y]補(bǔ)=-[Y]補(bǔ)即[X-Y]補(bǔ)=[X]補(bǔ)+[-Y]補(bǔ)=[X]補(bǔ)-[Y]補(bǔ)例1:已知機(jī)器字長n=8,X=44,Y=53,求X+Y=?解:[X]原=00101100,[Y]原=00110101[X]補(bǔ)=00101100,[Y]補(bǔ)=001
4、10101[X]補(bǔ)=00101100+[Y]補(bǔ)=00110101[X+Y]補(bǔ)=01100001真值:X+Y=(+1100001)2=+97例2:已知機(jī)器字長n=8,X=-44,Y=-53,求X+Y=?解:[44]補(bǔ)=00101100,[53]補(bǔ)=00110101[X]補(bǔ)=[-44]補(bǔ)=11010011+1=11010100,[Y]補(bǔ)=[-53]補(bǔ)=11001010+1=11001011[X]補(bǔ)=11010100+[Y]補(bǔ)=11001011[X+Y]補(bǔ)=110011111超出8位,舍棄模值X+Y=(-1100001)2=-97例3:已知機(jī)器字長n=8,X=0.1101,Y=0.01
5、10,求X-Y=?解:[X]補(bǔ)=0.1101000,[Y]補(bǔ)=0.0110000,[-Y]補(bǔ)=1.1010000[X]補(bǔ)=0.1101000+[-Y]補(bǔ)=1.101000010.0111000自然丟失[X-Y]補(bǔ)=(0.0111000)2,X-Y=(0.0111)2例4:已知機(jī)器字長n=8,X=-0.1101,Y=-0.0110求X-Y=?解:[X]補(bǔ)=1.0011000,[Y]補(bǔ)=1.1010000[-Y]補(bǔ)=0.0110000[X]補(bǔ)=1.0011000+[-Y]補(bǔ)=0.01100001.1001000[X-Y]補(bǔ)=(1.1001000)2,X-Y=(-0.0111)22.溢
6、出的檢測溢出:運(yùn)算結(jié)果超出了計(jì)算機(jī)所能表示的數(shù)據(jù)范圍。正溢(上溢):運(yùn)算結(jié)果為正而絕對值超出了表示的范圍。負(fù)溢(下溢):運(yùn)算結(jié)果為負(fù)而絕對值超出了表示的范圍。定點(diǎn)數(shù)的溢出——根據(jù)數(shù)值本身判斷。例:已知機(jī)器字長n=8,X=120,Y=10,求X+Y=?解:[X]補(bǔ)=01111000,[Y]補(bǔ)=00001010,[X]補(bǔ)=01111000+[Y]補(bǔ)=0000101010000010[X+Y]補(bǔ)=10000010,X+Y=11111110X+Y的真值=-1111110=(-126)10運(yùn)算結(jié)果超出機(jī)器數(shù)值范圍發(fā)生溢出錯(cuò)誤。8位計(jì)算機(jī)數(shù)值表達(dá)范圍:(-128~+127)溢出判斷規(guī)則與判斷
7、方法兩個(gè)相同符號(hào)數(shù)相加,其運(yùn)算結(jié)果符號(hào)與被加數(shù)相反則產(chǎn)生溢出;兩個(gè)相異符號(hào)數(shù)相減,其運(yùn)算結(jié)果符號(hào)與被減數(shù)相反則產(chǎn)生溢出。相同符號(hào)數(shù)相減,相異符號(hào)數(shù)相加不會(huì)產(chǎn)生溢出。溢出判斷方法:進(jìn)位判斷法,雙符號(hào)位法。(1)進(jìn)位溢出判斷法S⊕C兩單符號(hào)位的補(bǔ)碼進(jìn)行加減運(yùn)算時(shí),若最高數(shù)值位向符號(hào)位的進(jìn)位值C與符號(hào)位產(chǎn)生的進(jìn)位輸出值S相同時(shí)則無溢出,否則溢出。例:[X]補(bǔ)=1.101[X]補(bǔ)=1.110+[Y]補(bǔ)=1.001+[Y]補(bǔ)=0.100[X+Y]補(bǔ)=10.110[X+Y]補(bǔ)=10.010C