Capnsockless
Capnsockless

Reputation: 17

Summing up two floats always returns 0.0 in MIPS

I'm writing my very first program in assembly, I just have to sum up 2.5 and 2.5 Here's my code

.data
    #2.5+2.5=5.0
    myNumber1: .float 2.5
    myNumber2: .float 2.5
.text
    lwc1 $f1, myNumber1
    lwc1 $f2, myNumber2
    
    add.s $f3, $f1, $f2
    
    li $v0, 3
    syscall

For some reason it always returns 0.0 in the output, but in the memory it seems to sum and store the value in $f3 correctly. What am I missing here?

Upvotes: 0

Views: 147

Answers (1)

idmean
idmean

Reputation: 14895

According to this page the syscall to print a float is 2 not 3. Also, you must have the float to print in register $f12.

Accordingly, this should work:

add.s $f12, $f1, $f2

li $v0, 2
syscall

Upvotes: 3

Related Questions