好的只是为了测试我有这个代码
.data
# This shows you can use a .word and directly encode the value in hex
# if you so choose
num1: .word 0x3F800000
num2: .float 1234.567
num3: .float 45.67834
num4: .float 0.0004
result: .word 0
string: .asciiz "\n"
.text
main:
la $t0, num1
lwc1 $f2, 4($t0)
lwc1 $f4, 8($t0)
lwc1 $f6, 12($t0)
# Print out the values of the summands
li $v0, 2
mov.s $f12, $f2
syscall
li $v0, 4
la $a0, string
syscall
li $v0, 2
mov.s $f12, $f4
syscall
li $v0, 4
la $a0, string
syscall
li $v0, 4
la $a0, string
syscall
# Do the actual addition
add.s $f12, $f2, $f6
add.s $f12, $f12, $f4
# Transfer the value from the floating point reg to the integer reg
swc1 $f12, 8($t0)
lw $s0, 8($t0)
# At this point, $f12 holds the sum, and $s0 holds the sum which can
# be read in hexadecimal
li $v0, 2
syscall
li $v0, 4
la $a0, string
syscall
# This jr crashes MARS
# jr $ra
我有这个
add.s $f12, $f2, $f6
add.s $f12, $f12, $f4
我尝试交换订单说
add.s $f12, $f4, $f6
add.s $f12, $f12, $f2
但结果是相同的
我查了维基百科的浮点数增加的例子并不相同,但总是来到1280.2457
http://en.wikipedia.org/wiki/Floating_point
他们发生了这种情况: a = 1234.567, b = 45.67834, c = 0.0004
(a + b) + c:
1234.567 (a)
+ 45.67834 (b)
____________
1280.24534 rounds to 1280.245
1280.245 (a + b)
+ 0.0004 (c)
____________
1280.2454 rounds to 1280.245 <--- (a + b) + c
a + (b + c):
45.67834 (b)
+ 0.0004 (c)
____________
45.67874
1234.567 (a)
+ 45.67874 (b + c)
____________
1280.24574 rounds to 1280.246 <--- a + (b + c)
对我来说没有任何意义,它只适用于我尝试的任何值
答案 0 :(得分:0)
nm,我明白了
a=0.00004
b=45.67840
c=1234.567