robertina
robertina

Reputation: 64

product of floating point numbers

I have to multiply and print two double precision floating point numbers, my code is the following:

li $v0, 7       # $v0 =7    
syscall         # run read_double
jal p4          # run println

mfc1 $v0, $f4       # $v0 = $f4

li.d $f2, 4.3934567
mul.d $f0, $f4, $f2
mov.d $f12, $f0     # $f12 = $f6


li $v0, 3       #  $v0 =3
syscall         # run print_double
jal p4          # run println
jr $ra

Anyone knows why this code returns always 0?

Upvotes: 0

Views: 130

Answers (1)

Michael
Michael

Reputation: 58427

As I mentioned in my comment, system call 7 returns the result in floating-point register $f0. So your code could be simplifed to:

li $v0, 7       # $v0 =7    
syscall         # run read_double

li.d $f2, 4.3934567
mul.d $f12, $f0, $f2   # multiply user input by $f2. put the result in $f12
                       # for easy printing.

Upvotes: 1

Related Questions