I am trying to print the max of two floating point numbers, and then the max of two double percision floating point numbers. I keep getting this output:
The larger number is 1.10000002 The larger number is 5.2676887711382507e-315
I should be getting:
The larger number is 1.10000000 The larger number is 1.10000000
# maxFloat.s
.data
msg: .asciiz "The larger number is "
newline: .asciiz "\n"
num1: .float 1.00000001
num2: .float 1.0
num3: .double 1.00000001
num4: .double 1.0
.text
.globl main
main:
la $a0, num1 # storing num1's address
la $a2, num2 # storing num1's address
jal maxFloat # jumps to maxFloat function
li $v0, 4 # syscall 4 (print msg)
la $a0, msg # argument: string
syscall # print the string
li $v0, 2 # syscall 4 (print float)
# argument: $f12 (float)
syscall # print the string
li $v0, 4 # syscall 4 (print new line)
la $a0, newline # argument: string
syscall # print the string
# Now do the same thing for doubles #
la $a0, num3 # storing num1's address
la $a2, num4 # storing num1's address
jal maxDouble # jumps to maxFloat function
li $v0, 4 # syscall 4 (print msg)
la $a0, msg # argument: string
syscall # print the string
li $v0, 3 # syscall 2 (print double)
# argument: $f12 (double)
syscall # print the string
li $v0, 4 # syscall 4 (print new line)
la $a0, newline # argument: string
syscall # print the string
li $v0, 10 # syscall 10 (exit)
syscall
maxFloat:
l.s $f0, ($a0) # load num1
l.s $f2, ($a2) # load num2
mov.s $f12, $f2 # default to retuning num2
c.lt.s $f0, $f2 #if num1 is less than num2 then do nothing
bc1t skipF
mov.s $f12, $f0 #if num1 is greater then return num1
skipF:
jr $ra # retrun to caller
maxDouble:
l.d $f0, ($a0) # load num3
l.d $f2, ($a2) # load num4
mov.d $f12, $f2 # default to retuning num2
c.lt.d $f0, $f2 #if num1 is less than num2 then do nothing
bc1t skipD
mov.d $f12, $f0 #if num1 is greater then return num1
skipD:
jr $ra # retrun to caller
I tried to use a varitety of MIPS comamnds but cannot get it to print the right number. Also when I input 1.00000001 as the largest number 1.00000000 comes out.