浮点数的表示和计算
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
《计算机组成原理》实验报告
sw $aO, O($fp) #calculate the first nu mber
andi $s2, $s0, 0x80000000 # s2 is the sig n
srl $s2, $s2, 31
andi $s3, $s0, 0x7f800000 # s3 is the exp onent
srl $s3, $s3, 23
andi $s4, $s0, 0x007fffff # s4 is the fractio n
addi $s4, $s4, 0x00800000 #calculate the seco nd number
andi $s5, $s1, 0x80000000 # s5 is the sig n
srl $s5, $s5, 31
andi $s6, $s1, 0x7f800000 # s6 is the exp onent
srl $s6, $s6, 23
andi $s7, $s1, 0x007fffff # s7 is the fractio n
addi $s7, $s7, 0x00800000
sub $t0, $s3, $s6
bit $t0, 0, sumL1 # add sub
bgt $t0, 0, sumL2 # sub add
beq $t0, 0, sumL3
2.减法指令如下:
mysub: subu $sp, $sp, 32
sw $ra, 20($sp)
sw $fp, 16($sp)
addiu $fp, $sp, 28
sw $a0, 0($fp) #calculate the first nu mber
andi $s2, $s0, 0x80000000 # s2 is the sig n
srl $s2, $s2, 31
andi $s3, $s0, 0x7f800000 # s3 is the exp onent
srl $s3, $s3, 23
andi $s4, $s0, 0x007fffff # s4 is the fractio n
addi $s4, $s4, 0x00800000 #calculate the seco nd number
xori $s5, $s1, 0x80000000 # s5 is the sig n
srl $s5, $s5, 31
andi $s6, $s1, 0x7f800000 # s6 is the exp onent
srl $s6, $s6, 23
andi $s7, $s1, 0x007fffff # s7 is the fractio n
addi $s7, $s7, 0x00800000
sub $t0, $s3, $s6
blt $t0, 0, subL1 # +,-
bgt $t0, 0, subL2 # -,+
beq $t0, 0, subL3 # +,+ or -,-
3.乘法指令如下:
mutilStart: srl $t2, $s0, 31
srl $t3, $s1, 31
sll $t4, $s0, 1
srl $t4, $t4, 24 # exp
sll $t5, $s1, 1
srl $t5, $t5, 24 # exp # 0...1frac
sll $t6, $s0, 9
srl $t6, $t6, 9
ori $t6, $t6, 0x00800000
sll $t6, $t6, 8
addi $t4, $t4, 1 # 0...1frac
sll $t7, $s1, 9
srl $t7, $t7, 9
ori $t7, $t7, 0x00800000
sll $t7, $t7, 8
addi $t5, $t5, 1
sub $t4, $t4, 127
add $t4, $t4, $t5 # final exp
sub $t5, $t5, $t5
mutilCompareSig n:add $t2, $t2, $t3
sll $t2, $t2, 31 # final sig n
multu $t6, $t7
mfhi $t5
#regular
andi $t8, $t5,0x80000000
beq$t8, 0x80000000, muti In ext
sll $t5, $t5, 1
sub $t4, $t4, 1
mutil next: sll $t5, $t5, 1 # IEEE754
sub $t4, $t4, 1
srl $t5, $t5, 9 # final fracti on
mutilFi nal: sll $t4, $t4, 24
srl $t4, $t4, 1
addu $t2, $t2, $t4
addu $t2, $t2, $t5 # result
add $s2, $t2, $zero # save result
li $v0, 4
la $a0, msg3
syscall
li $v0, 2
mtc1 $t2, $f12
syscall
la $a0, nsg0 # new line
li $v0, 4
syscall