# conversion between int and float # with a few computations in float .data num: .word 5 twofl: .float 2 intmsg: .asciiz "\nThe number is: " posmsg: .asciiz "\n$f5 is positive" negmsg: .asciiz "\n$f5 is negative" .globl main .text main: lui $t0, 0x1001 # $t0: base addr of data segment lw $t1, 0($t0) # $t1 = 5 li $v0, 4 # print msg la $a0, intmsg syscall li $v0, 1 # print $t1, which contains 5 move $a0, $t1 syscall # convert to float, do some computation & print results mtc1 $t1, $f4 # $f4 = $t1 (copies, doesn't convert) cvt.s.w $f5, $f4 # $f5 = (float) $f4 l.s $f6, 4($t0) # $f6 = 2 add.s $f5, $f5, $f6 # $f5 += 2 li $v0, 4 # print msg la $a0, intmsg syscall li $v0, 2 # print $f5 mov.s $f12, $f5 syscall sub.s $f7, $f7, $f7 # $f7 = 0 c.lt.s $f7, $f5 # 0 < $f5 ? ($f5 > 0 ?) bc1t pos # if true, goto pos li $v0, 4 # print negative msg la $a0, negmsg syscall b next pos: li $v0, 4 # print positive msg la $a0, posmsg syscall next: div.s $f5, $f5, $f6 # $f5 = $f5 / 2 li $v0, 4 # print msg la $a0, intmsg syscall li $v0, 2 # print $f5 mov.s $f12, $f5 syscall # convert to int & print cvt.w.s $f5, $f5 # $f5 = (int) $f5 mfc1 $t2, $f5 # $t2 = $f5 (copies, doesn't convert) li $v0, 4 # print msg la $a0, intmsg syscall li $v0, 1 # print $t2 move $a0, $t2 syscall li $v0, 10 # terminate execution and syscall # return control to system