好吧只是为了测试我有这个代码
.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)
对我来说并没有发生,它只适用于我尝试的任何值