#FPMath.asm #Examples of floating point mathematics .data x: .double 18.2 y: .double 34.6 small: .double 0.000000000000001 xLTy: .asciiz "abs(x-y) is less than small (x == y)\n" xGTEy: .asciiz "abs(x-y) is greater than or equal to small (x != y)\n" newLine: .asciiz "\n" .text main: #load double values l.d $f2, x l.d $f4, y l.d $f18, small #perform floating point mathematics ops add.d $f6, $f2, $f4 sub.d $f8, $f2, $f4 div.d $f10, $f2, $f4 mul.d $f14, $f2, $f4 #copy one of the results to $f12 mov.d $f12, $f14 #print contents of $f12 and $f13 li $v0, 3 syscall li $v0, 4 la $a0, newLine syscall #move zero into a floating point register mtc1 $zero, $f1 cvt.d.w $f16, $f1 #print contents of $f16 mov.d $f12, $f16 li $v0, 3 syscall li $v0, 4 la $a0, newLine syscall #move an integer value into a floating point register li $t1, -78 mtc1 $t1, $f1 cvt.d.w $f16, $f1 #print contents of $f16 mov.d $f12, $f16 li $v0, 3 syscall li $v0, 4 la $a0, newLine syscall #print the truth results of x == y #need abs(x - y) < 0.000000000000001 abs.d $f16, $f8 # $f8 contains x - y c.lt.d $f8, $f18 #set condition flag zero if abs(x - y) < small value bc1f else if: #if abs(x-y) < 0.000000000000001 li $v0, 4 la $a0, xLTy syscall #beq $zero, $zero, endif works as well b endif else: li $v0, 4 la $a0, xGTEy syscall endif: li $v0, 10 #end program syscall