浮點(diǎn)數(shù)的表示和計(jì)算_第1頁(yè)
浮點(diǎn)數(shù)的表示和計(jì)算_第2頁(yè)
浮點(diǎn)數(shù)的表示和計(jì)算_第3頁(yè)
浮點(diǎn)數(shù)的表示和計(jì)算_第4頁(yè)
浮點(diǎn)數(shù)的表示和計(jì)算_第5頁(yè)
已閱讀5頁(yè),還剩5頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、計(jì)算機(jī)組成原理實(shí)驗(yàn)報(bào)告年級(jí)、專(zhuān)業(yè)、班級(jí)姓名實(shí)驗(yàn)題目浮點(diǎn)數(shù)的表示和計(jì)算實(shí)驗(yàn)時(shí)間實(shí)驗(yàn)地點(diǎn)a 主 404實(shí)驗(yàn)成績(jī)實(shí)驗(yàn)性質(zhì)驗(yàn)證性設(shè)計(jì)性口綜合性教師評(píng)價(jià):口算法/實(shí)驗(yàn)過(guò)程正確;口源程序/實(shí)驗(yàn)內(nèi)容提交程序結(jié)構(gòu)/實(shí)驗(yàn)步驟合理;口實(shí)驗(yàn)結(jié)果正確;口語(yǔ)法、語(yǔ)義正確;口報(bào)告規(guī)范;其他:評(píng)價(jià)教師簽名:一、實(shí)驗(yàn)?zāi)康?1) 深入掌握二進(jìn)制數(shù)的表示方法以及不向進(jìn)制數(shù)的轉(zhuǎn)換;(2) 掌握二進(jìn)制不向編碼的表示方法;(3) 掌握ieee 754中單精度浮點(diǎn)數(shù)的表示和計(jì)算。二、實(shí)驗(yàn)項(xiàng)目?jī)?nèi)容假設(shè)沒(méi)有浮點(diǎn)表示和計(jì)算的硬件,用軟件方法采用仿真方式實(shí)現(xiàn)ieee 754單精度浮點(diǎn)數(shù)的表示及運(yùn)算功能,具體要求如下:(1)程序需要提供人機(jī)交互方

2、式( gui或者字符界面)供用戶選擇相應(yīng)的功能;(2)可接受十進(jìn)制實(shí)數(shù)形式的輸入,在內(nèi)存中以ieee 754單精度方式表示,支持以二進(jìn)制和十六進(jìn)制的方式顯示輸出;(3)可實(shí)現(xiàn)浮點(diǎn)數(shù)的加減乘除運(yùn)算;(4)可以使用80x86或mips或arm匯編指令,但是不能使用浮點(diǎn)指令,只能利 用整數(shù)運(yùn)算指令來(lái)編寫(xiě)軟件完成。三、實(shí)驗(yàn)過(guò)程或算法(源程序)1.本次項(xiàng)目我們采用單精度浮點(diǎn)數(shù)格式讀入兩個(gè)浮點(diǎn)數(shù),并讀入一個(gè)操作符,然 后根據(jù)操作符類(lèi)型選擇運(yùn)算類(lèi)型,加法指令如下:sum:subu $sp, $sp, 32sw $ra, 20($sp)sw $fp, 16($sp)addiu $fp, $sp, 28sw $

3、a0,0($fp)#calculate the first numberandi$s2, $s0,0x80000000# s2 is the signsrl $s2,$s2, 31andi$s3, $s0,0x7f800000# s3 is the exponentsrl $s3,$s3, 23andi$s4, $s0,0x007fffff# s4 is the fractionaddi $s4, $s4, 0x00800000 #calculate the second numberandi$s5, $s1,0x80000000# s5 is the signsrl $s5,$s5, 31a

4、ndi$s6, $s1,0x7f800000# s6 is the exponentsrl $s6,$s6, 23andi$s7, $s1,0x007fffff# s7 is the fractionaddi $s7, $s7, 0x00800000sub $t0,$s3, $s6blt $t0,0, suml1# addsubbgt $t0,0, suml2# subaddbeq $t0,0, suml32.減法指令如下:mysub: subu $sp, $sp, 32 sw $ra, 20($sp)sw $fp,16($sp)addiu$fp, $sp, 28sw $a0,0($fp)#c

5、alculate the first numberandi$s2, $s0,0x80000000# s2 is the signsrl $s2,$s2, 31andi$s3, $s0,0x7f800000# s3 is the exponentsrl $s3,$s3, 23andi$s4, $s0,0x007fffff# s4 is the fractionaddi $s4, $s4, 0x00800000 #calculate the second numberxori$s5, $s1,0x80000000# s5 is the signsrl $s5,$s5, 31andi$s6, $s1

6、,0x7f800000# s6 is the exponentsrl $s6,$s6, 23andi$s7, $s1,0x007fffff# s7 is the fractionaddi $s7, $s7, 0x00800000sub $t0, $s3, $s6blt $t0,0, subl1bgt $t0, 0, subl2beq $t0, 0, subl3# +,-# -,+# +,+ or -,-3.乘法指令如下:mutilstart: srl$t2, $s0, 31srl $t3, $s1, 31sll $t4, $s0, 1srl$t4, $t4, 24# expsll$t5, $s

7、1, 1srl$t5, $t5, 24# exp # 01fracsll $t6,$s0, 9srl$t6, $t6, 9ori$t6, $t6, 0x00800000sll$t6, $t6, 8addi$t4, $t4,1# 01fracsll$t7, $s1, 9srl$t7, $t7, 9ori$t7, $t7, 0x00800000sll$t7, $t7, 8addi$t5, $t5,1sub$t4, $t4, 127add$t4, $t4, $t5# final expsub$t5, $t5, $t5mutilcomparesign:add$t2, $t2, $t3sll$t2, $

8、t2, 31# final signmultu $t6, $t7mfhi$t5#regularandi$t8, $t5,0x80000000beq$t8, 0x80000000, mutilnextsll$t5, $t5, 1sub$t4, $t4, 1mutilnext:sll $t5, $t5,1# ieee754sub$t4, $t4, 1srl$t5, $t5, 9# final fractionmutilfinal: sll$t4, $t4,24srl$t4, $t4, 1addu$t2, $t2, $t4addu$t2, $t2, $t5# resultadd $s2,$t2, $

9、zero# save resultli $v0,4la $a0,msg3syscallli $v0,2mtc1$t2, $f12syscallla$a0, msg0# new lineli$v0, 4syscalliw$ra,20($sp)iw $fp,16($sp)addiu$sp, $sp, 32jr$ra4.除法指令如下dividestart:srl$t2, $s0, 31srl$t3,$s1, 31sll$t4,$s0, 1srl$t4,$t4, 24# expsll$t5,$s1, 1srl$t5,$t5, 24# expsll$t6,$s0, 9srl$t6,$t6, 9ori$t

10、6,$t6, 0x00800000sll$t7,$s1, 9srl$t7,$t7, 9ori$t7,$t7, 0x00800000sub$t4,$t4, $t5# final expaddi$t4, $t4,127sub$t5,$t5, $t5dividecomparesign:add$t2, $t2, $t3sll$t2,$t2, 31# final signsub$t8,$t8, $t8# use to record dividsub$t3,$t3, $t3# use to record remaindersub$t5,$t5, $t5# use as counterdividecompa

11、rebge $t5,24, dividebreakout #compare the two numberblt$t6,$t7, dividelowerdividegreater:sub $t6,$t6, $t7#divide is lowersll$t6,$t6, 1sll$t8,$t8, 1addi$t8, $t8,1addi$t5, $t5,1jdividecomparedividelower:sll$t6, $t6,1sll$t8,$t8, 1addi$t5, $t5,1jdividecomparedividebreakout: blt$t8,0x00800000, dividedosl

12、lbge$t8,0x01000000, dividedosrlj divideresultdividedosll: sll$t8, $t8, 1$t4, $t4, 10x00800000, dividedosllleresultsubiblt $t8,j dividdividedosrl: srl$t8, $t8, 1addi$t4, $t4, 1bge $t8,0x01000000, dividedosrlj divideresultdivideresult:bgt $t4, 255, divideoverflowsll $t8,$t8, 9srl $t8,$t8, 9sll $t4,$t4

13、, 24srl $t4,$t4, 1add $t2,$t2, $t4add $t2,$t2, $t8add $s2,$t2, $zero# save resultli $v0,4la $a0,msg3#output messagesyscall li $v0,2mtc1$t2, $f12syscallj diviedenddex2:subu $sp, $sp, 32sw $ra,20($sp)sw $fp,16($sp)addiu$fp, $sp, 28sw $a0,0($fp)add $a0,$s2, $zeroadd $t9,$zero, $a0sub $t6,$t6, $t6# set

14、$t6=0sub $t7,$t7, $t7# set $t7=0addi$t5, $zero, 32# set $t5=32 as a counteraddi$t8, $zero, 0x80000000# set $t8=1000 00005.十進(jìn)制轉(zhuǎn)換為二進(jìn)制指令如下:0000 0000 00000000 0000 0000beginloop:addi$t5,$t5, -1# counter -and$t7, $t8,$t9srl$t8,$t8, 1srlv $t7,$t7, $t5add $a0, $t7,$zero#output one bitli $v0,1syscallbeq $t5

15、, $t6, exist #if equals jump exist j beginloop6.十進(jìn)制轉(zhuǎn)換為十六進(jìn)制指令如下:dex16: subu $sp, $sp, 32 sw $ra, 20($sp) sw $fp, 16($sp) addiu $fp, $sp, 28 sw $a0, 0($fp) sub $t0, $t0, $t0# use as countersrloop: bge $t0, 8, dex16end #16addi $t0,$t0, 1srl $t1,$s2, 28sll $s2,$s2, 4bgt $t1,9, outcharli $v0,1add $a0,$t1

16、, $zerosyscallj srloopoutchar: addi$t1, $t1, 55 # change to charli $v0,11add $a0, $t1, $zerosyscallj srloopdex16end:la $a0, nsg0 # new line li $v0, 4 syscall lw $ra, 20($sp) lw $fp, 16($sp) addiu $sp, $sp, 32 jr $ra四、實(shí)驗(yàn)結(jié)果及分析和(或)源程序調(diào)試過(guò)程1.實(shí)驗(yàn)結(jié)果:本次實(shí)驗(yàn)我們以十進(jìn)制實(shí)數(shù)形式的輸入兩個(gè)浮點(diǎn)數(shù),在內(nèi)存中以 ieee 754單精 度方式表示,執(zhí)行運(yùn)算操作后,以十進(jìn)制

17、形式把結(jié)果輸出,并且可以以二進(jìn)制和十六 進(jìn)制的方式顯示輸出,下圖是執(zhí)行加法運(yùn)算,并輸出二進(jìn)制形式:hnpuit a op: 1, add 2.3. miol 4. aiv cl. qui t1i tie f lirs t float mg value i s 1.25ihe second floating value i s : 1. 1 充ih! rgasmit i s. 2.375input b. the tarm at t o cratjuut : 5_ biaary b hex :5diooooaocooi woooooooooaocooogooinput b. op: 1, add2

18、. sul3. mial4.diw0.qm t下圖是執(zhí)行乘法操作,并輸出十六進(jìn)制形式:hnpiit b. op: l add2. sill3. nnol4.aiwcl.quitrth 名 tijts t fleat liigvalliejl 后 5the second fluatingr虹uis_0. 5the reasul t i s. 1.25input a. the f ormat to outjut: 5. binary 6 hex :63fmmoooinput 且 0f. l. add 2 *ufb 3. niul 4. div 0, quit減法運(yùn)算如下圖:titput a op

19、:1 . add 2. sub 3. mj. 4. div g. -jui t2iile first ft口ating value i e 710iksv&lutike reasultginput t tht fr*nat tc output ;5. binwry 6 kx ;6cl200000ikput t op- 1 add 2. sub 3 mli1 4 div q, git除法運(yùn)算如下圖:iiupiit a op :1. add 2. wub 3, mul 4- da v 0. qni tailie first floating value i s 112. 24the second

20、floating value i s :2th總 reasult is! 6.12inpiit b th* format tg tput ;5 binary & xu苦 二 5plooooool looool 111010111dooo1010input & op:1 .3己d 2. sub 3. mul 4. dir g. q-uit當(dāng)輸入錯(cuò)誤,如除數(shù)為 0時(shí),會(huì)顯示錯(cuò)誤信息并退出,如下圖:input a op 11l add 2. sub 3. mil 4. div 0. qui t4i he f 11rmit fld all ng value is: 1iht second floafi

21、nc valu# is;0error1 - prograim is finishe! running: 一2 .實(shí)驗(yàn)分析:本次實(shí)驗(yàn)我們使用 mips匯編指令,利用整數(shù)運(yùn)算指令來(lái)編寫(xiě)了一個(gè)浮點(diǎn)數(shù)運(yùn)算 程序,通過(guò)在 mars 4.4軟件上進(jìn)行調(diào)試運(yùn)行,得到了正確結(jié)果,本次實(shí)驗(yàn)實(shí)現(xiàn)了以 下功能:(1)程序提供了人機(jī)交互方式(字符界面)供用戶選擇相應(yīng)的功能;(2)接受十進(jìn)制實(shí)數(shù)形式的輸入,在內(nèi)存中以ieee 754單精度方式表示,支持以二進(jìn)制和十六進(jìn)制的方式顯示輸出;(3)實(shí)現(xiàn)了浮點(diǎn)數(shù)的加減乘除運(yùn)算;(4)沒(méi)有使用浮點(diǎn)指令,只利用了整數(shù)運(yùn)算指令來(lái)完成軟件的編寫(xiě)。3 . 成員分工:力口、減、乘、除四個(gè)運(yùn)

22、算指令程序的編寫(xiě)。:十進(jìn)制轉(zhuǎn)二進(jìn)制,十進(jìn)制轉(zhuǎn)十六進(jìn)制代碼的編寫(xiě)。實(shí)驗(yàn)報(bào)告由兩人共同完成。備注:1、教師在布置需撰寫(xiě)實(shí)驗(yàn)報(bào)告的實(shí)驗(yàn)前,應(yīng)先將報(bào)告書(shū)上的“實(shí)驗(yàn)題 目”、“實(shí)驗(yàn)性質(zhì)”、“實(shí)驗(yàn)?zāi)康摹?、“?shí)驗(yàn)項(xiàng)目?jī)?nèi)容”等項(xiàng)目填寫(xiě)完成, 然后再下發(fā)給學(xué)生。2、教師在布置需撰寫(xiě)報(bào)告的實(shí)驗(yàn)項(xiàng)目時(shí),應(yīng)告知學(xué)生提交實(shí)驗(yàn)報(bào)告的最后期限。3、學(xué)生應(yīng)按照要求正確地撰寫(xiě)實(shí)驗(yàn)報(bào)告:1) 在實(shí)驗(yàn)報(bào)告上正確地填寫(xiě)“實(shí)驗(yàn)時(shí)間” 、 “實(shí)驗(yàn)地點(diǎn)”等欄目。2) 將實(shí)驗(yàn)所涉及的源程序文件內(nèi)容 (實(shí)驗(yàn)操作步驟或者算法) 填寫(xiě)在“ 實(shí)驗(yàn)過(guò)程或算法(源程序) ”欄目中。3) 將實(shí)驗(yàn)所涉及源程序調(diào)試過(guò)程 (輸入數(shù)據(jù)和輸出結(jié)果) 或者實(shí)驗(yàn)的分析內(nèi)容填寫(xiě)在“ 實(shí)驗(yàn)結(jié)果及分析和(或)源程序調(diào)試過(guò)程”欄目中。4) 在實(shí)驗(yàn)報(bào)告頁(yè)腳的“報(bào)告創(chuàng)建時(shí)間: ”處插入完成實(shí)驗(yàn)報(bào)告時(shí)的日期和時(shí)間。5) 學(xué)生將每個(gè)實(shí)驗(yàn)完成后,按實(shí)驗(yàn)要求的文件名通過(guò)網(wǎng)絡(luò)提交(上載) 到指定的服務(wù)器所規(guī)定的共享文件夾中。 每個(gè)實(shí)驗(yàn)一個(gè)電子文檔,如果實(shí)驗(yàn)中有多個(gè)電子文檔(如源程序或圖形等) ,則用

溫馨提示

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

評(píng)論

0/150

提交評(píng)論