浮点数的表示和计算

上传人:博****1 文档编号:464194796 上传时间:2023-03-03 格式:DOCX 页数:13 大小:35.21KB
返回 下载 相关 举报
浮点数的表示和计算_第1页
第1页 / 共13页
浮点数的表示和计算_第2页
第2页 / 共13页
浮点数的表示和计算_第3页
第3页 / 共13页
浮点数的表示和计算_第4页
第4页 / 共13页
浮点数的表示和计算_第5页
第5页 / 共13页
点击查看更多>>
资源描述

《浮点数的表示和计算》由会员分享,可在线阅读,更多相关《浮点数的表示和计算(13页珍藏版)》请在金锄头文库上搜索。

1、计算机组成原理实验报告年级、专业、班级姓名实验题目浮点数的表示和计算实验时间实验地点A 主 404实验成绩实验性质验证性 设计性 口综合性教师评价:口算法/实验过程正确;口源程序/实验内容提交程序结构/实验步骤合理;口实验结果正确;口语法、语义正确;口报告规范;其他:评价教师签名:一、实验目的(1) 深入掌握二进制数的表示方法以及不向进制数的转换;(2) 掌握二进制不向编码的表示方法;(3) 掌握IEEE 754中单精度浮点数的表示和计算。二、实验项目内容假设没有浮点表示和计算的硬件,用软件方法采用仿真方式实现IEEE 754单精度浮点数的表示及运算功能,具体要求如下:(1) 程序需要提供人机

2、交互方式(GUI或者字符界面)供用户选择相应的功能;(2) 可接受十进制实数形式的输入,在内存中以IEEE 754单精度方式表示,支持以二进制和十六进制的方式显示输出;(3) 可实现浮点数的加减乘除运算;(4) 可以使用80X86或MIPS或ARMT编指令,但是不能使用浮点指令,只能利用整数运算指令来编写软件完成。三、实验过程或算法(源程序)1 .本次项目我们采用单精度浮点数格式读入两个浮点数,并读入一个操作符,然后根据操作符类型选择运算类型,加法指令如下:sum:subu $sp, $sp, 32sw $ra, 20($sp)sw $fp, 16($sp)addiu $fp, $sp, 28

3、sw $a0, 0($fp)#calculate the first numberandi $s2, $s0, 0x # 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,0x # s5 is the signsrl $s5,$s5, 31andi$s

4、6, $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# add subbgt $t0, 0,sumL2# sub add2 .减法指令如下:mysub: subu $sp, $sp, 32sw $ra, 20($sp)sw $fp, 16($sp)addiu $fp, $sp, 28sw $a0, 0($fp)#calculate the fir

5、st numberandi $s2, $s0, 0x # 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, 0x # s5 is the signsrl $s5,$s5, 31andi$s6, $s1, 0x7f800000# s6 is the

6、exponentsrl $s6,$s6, 23andi$s7, $s1, 0x007fffff# s7 is the fractionaddi $s7, $s7, 0x00800000sub $t0,$s3,$s6blt $t0,0,subL1# +,-bgt $t0,0,subL2# -,+beq $t0,0,subL3# +,+ or -,-3 .乘法指令如下:srl$t3,$s1,31sll$t4,$s0,1srl$t4,$t4,24#expsll$t5,$s1,1srl $t5, $t5, 24# exp # 0Ifracsll $t6,$s0,9srl$t6,$t6,9ori$t6,

7、$t6,0x00800000sll$t6,$t6,8addi$t4,$t4,1#0Ifracsll$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, $t2,31# finalsignmultu$t6,$t7mfhi$t5#regularandi$t8,$t5,0x beq $t8, 0x, mutilnextmutilnex

8、t: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, $zero# save resultli $v0,4la $a0,msg3syscallli $v0,2mtc1$t2, $f12syscallla$a0, msg0# new lineli $v0, 4syscalllw $ra, 20($sp)lw $fp, 16($sp

9、)addiu $sp, $sp, 32jr $ra4 .除法指令如下:divideStart:srl $t2, $s0, 31sll $t4, $s0, 1srl$t4,$t4,24#expsll$t5,$s1,1srl$t5,$t5,24#expsll$t6,$s0,9srl$t6, $t6, 9ori$t6, $t6, 0x00800000 sll $t7, $s1, 9 srl $t7, $t7, 9ori$t7, $t7, 0x00800000sub $t4, $t4, $t5addi $t4, $t4,sub $t5, $t5, $t5# final exp127divideComp

10、areSign:addsll $t2, $t2, 31sub $t8, $t8, $t8sub $t3, $t3, $t3sub $t5, $t5, $t5$t2, $t2, $t3# final sign# use to record divid# use to record remainder# use as counterdividecompare:bge $t5, 24, dividebreakout #compare the two numberblt $t6, $t7, dividelowerdividegreater:sub $t6, $t6, $t7#divide is low

11、ersll$t6, $t6, 1sll$t8, $t8, 1 addi $t8, $t8, 1jdividecomparedividelower:sll $t6, $t6,1sll$t8, $t8, 1addi$t5, $t5,1jdividecomparedividebreakout: blt $t8, 0x00800000, dividedoSll bge $t8, 0x01000000, dividedoSrl j divideresultdividedoSll: sll$t8, $t8, 1subi$t4, $t4, 1blt $t8, 0x00800000, dividedoSll

12、j divideresultdividedoSrl: srl $t8, $t8, 1addi $t4, $t4, 1 bge $t8, 0x01000000, dividedoSrl j divideresultdivideresult:bgt $t4, 255, divideoverFlowsll$t8,$t8,9srl$t8,$t8,9sll$t4,$t4,24srl$t4,$t4,1add $t2,$t2,$t4add $t2,$t2,$t8li $v0,la $a0,msg3#output messagesyscallli $v0,mtcl$t2, $f12syscallj divie

13、dend5.十进制转换为二进制指令如下:dex2: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 $t6=0sub$t7,$t7,$t7# set $t7=0addi$t5,$zero,32# set $t5=32 as a counteraddi$t8,$zero,0x # set $t8=1000 0000 0000 0000 00000000 0000 0000beginLoop:

14、addi$t5,$t5, -1# counter -and$t7,$t8,$t9srl$t8,$t8, 1srlv$t7, $t7,$t5li $v0,1syscallbeq $t5, $t6, Exist #if equals jump existj beginLoop6.十进制转换为十六进制指令如下:dex16: subu $sp, $sp, 32sw $ra, 20($sp)sw $fp, 16($sp)addiu $fp, $sp, 28sw $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,

展开阅读全文
相关资源
正为您匹配相似的精品文档
相关搜索

最新文档


当前位置:首页 > 商业/管理/HR > 营销创新

电脑版 |金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号