




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、计算机组成原理实验报告年级、专业、班级姓名实验题目浮点数的表示和计算实验时间实验地点a 主 404实验成绩实验性质验证性设计性口综合性教师评价:口算法/实验过程正确;口源程序/实验内容提交程序结构/实验步骤合理;口实验结果正确;口语法、语义正确;口报告规范;其他:评价教师签名:一、实验目的(1) 深入掌握二进制数的表示方法以及不向进制数的转换;(2) 掌握二进制不向编码的表示方法;(3) 掌握ieee 754中单精度浮点数的表示和计算。二、实验项目内容假设没有浮点表示和计算的硬件,用软件方法采用仿真方式实现ieee 754单精度浮点数的表示及运算功能,具体要求如下:(1)程序需要提供人机交互方
2、式( gui或者字符界面)供用户选择相应的功能;(2)可接受十进制实数形式的输入,在内存中以ieee 754单精度方式表示,支持以二进制和十六进制的方式显示输出;(3)可实现浮点数的加减乘除运算;(4)可以使用80x86或mips或arm汇编指令,但是不能使用浮点指令,只能利 用整数运算指令来编写软件完成。三、实验过程或算法(源程序)1.本次项目我们采用单精度浮点数格式读入两个浮点数,并读入一个操作符,然 后根据操作符类型选择运算类型,加法指令如下: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.十进制转换为二进制指令如下: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.十进制转换为十六进制指令如下: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四、实验结果及分析和(或)源程序调试过程1.实验结果:本次实验我们以十进制实数形式的输入两个浮点数,在内存中以 ieee 754单精 度方式表示,执行运算操作后,以十进制
17、形式把结果输出,并且可以以二进制和十六 进制的方式显示输出,下图是执行加法运算,并输出二进制形式: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下图是执行乘法操作,并输出十六进制形式: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减法运算如下图: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除法运算如下图: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当输入错误,如除数为 0时,会显示错误信息并退出,如下图: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 .实验分析:本次实验我们使用 mips汇编指令,利用整数运算指令来编写了一个浮点数运算 程序,通过在 mars 4.4软件上进行调试运行,得到了正确结果,本次实验实现了以 下功能:(1)程序提供了人机交互方式(字符界面)供用户选择相应的功能;(2)接受十进制实数形式的输入,在内存中以ieee 754单精度方式表示,支持以二进制和十六进制的方式显示输出;(3)实现了浮点数的加减乘除运算;(4)没有使用浮点指令,只利用了整数运算指令来完成软件的编写。3 . 成员分工:力口、减、乘、除四个运
22、算指令程序的编写。:十进制转二进制,十进制转十六进制代码的编写。实验报告由两人共同完成。备注:1、教师在布置需撰写实验报告的实验前,应先将报告书上的“实验题 目”、“实验性质”、“实验目的”、“实验项目内容”等项目填写完成, 然后再下发给学生。2、教师在布置需撰写报告的实验项目时,应告知学生提交实验报告的最后期限。3、学生应按照要求正确地撰写实验报告:1) 在实验报告上正确地填写“实验时间” 、 “实验地点”等栏目。2) 将实验所涉及的源程序文件内容 (实验操作步骤或者算法) 填写在“ 实验过程或算法(源程序) ”栏目中。3) 将实验所涉及源程序调试过程 (输入数据和输出结果) 或者实验的分析内容填写在“ 实验结果及分析和(或)源程序调试过程”栏目中。4) 在实验报告页脚的“报告创建时间: ”处插入完成实验报告时的日期和时间。5) 学生将每个实验完成后,按实验要求的文件名通过网络提交(上载) 到指定的服务器所规定的共享文件夹中。 每个实验一个电子文档,如果实验中有多个电子文档(如源程序或图形等) ,则用
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
评论
0/150
提交评论