## LSU EE 4720 Computer Architecture Spring 2014
#
#  Simple example of MIPS floating-point instructions.

        .text

###############################################################################
#
# Compute f + i, where f is single-precision FP and i is an integer.
#

splusi:
        ## Register Usage
        #
        # CALL VALUES:
        #  $f0: Value f, single precision.
        #  $a0: Value i, integer.
        #
        # RETURN:
        #  $f30: Return f+i as single precision fp.
        #
        # Note:
        #  Can use $f16-$f31 as temporaries.

        mtc1 $a0, $f17          # Move integer value to a fp register ..
        cvt.s.w $f16, $f17      # .. and convert it to fp.
        jr $ra
        add.s $f30, $f0, $f16   # Perform the add.


###############################################################################
#
 ##  Test Code
#
#  This code calls the splusi string routine multiple times using
#  data appearing below.
#

        .data
msg:
        .asciiz "The value of %/f10/7.4f + %/s1/d = %/f12/7.4f\n"
values:
        .float 1.234
        .float -5.678
        .word 0   # This is correct, but is it good style?

        .text
        .globl __start
__start:
        la $s2, values
        mtc1 $0, $f8             # Put a zero in FP register $f8
MLOOP:
        addi $a0, $0, 2          # Integer argument to splusi
        jal splusi
        lwc1 $f0, 0($s2)         # Load FP argument to splusi
        cvt.d.s $f10, $f0        # Convert values to double, for printing.
        cvt.d.s $f12, $f30       # Convert values to double, for printing.
        addi $s1, $a0, 0         # Move integer argument out of the way ..
        la $a0, msg              # .. because $a0 is needed for the msg.
        addi $v0, $0, 11         # The printf system call number.
        syscall                  # Call printf ..
        c.eq.s $f0, $f8          # Check whether at end of table.
        bc1f MLOOP
        addi $s2, $s2, 4         # Advance to next element in table.
        li $v0, 10               # The exit system call.
        syscall
        nop