Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

MIPS convert temperature C to F and vice versa. I need help to covert the F to C

ID: 3798776 • Letter: M

Question

MIPS convert temperature C to F and vice versa. I need help to covert the F to C. This is my code.

# Temperature Conversion C -> F

.text

main:

# Get the temp in C from user
   li   $v0, 4       # Load 4=print_string into $v0
   la   $a0, prompt   # Load address of prompt into $a0
   syscall           # Output the prompt
   li   $v0, 6       # Load 6=read_float into $v0
   syscall           # $f0 contains float


# Conversion from C to F: F = 32 + C*180/100

   l.s   $f1, c1       # conversion factor 1
   l.s   $f2, c2       # conversion factor 2
   mul.s   $f3, $f0, $f2   # C*180/100
   add.s   $f3, $f3, $f1   # F = 32 + C*180/100
   mov.s   $f12, $f3   # Copy $f3 to $f12
   li   $v0, 2       # Load 2=print_float into $v0
   syscall           # print value in $f12

   li   $v0, 4       # Load 4=print_string into $v0
   la   $a0, newline   # Load address of newline into $a0
   syscall           # Output the newline


# See if it cold
   l.s   $f1, c3       # $f1 = constant 0.0
   c.lt.s   $f3, $f1   # compare temp and 0
   bc1f   endif       # brach if temp is negative
   li   $v0, 4       # Load 4=print_string into $v0
   la   $a0, cold   # Load address of string into $a0
   syscall           # Output the string
endif:


# Exit Gracefully
   li   $v0, 10
   syscall


.data
   .align 0
n:
   .word 10
c1:   .float 32   # conversion factor 1
c2:   .float 1.8   # conversion factor 2
c3:   .float 0.0   # cutoff for "cold" temperature
prompt:
   .asciiz "Enter the temperature in Celsius: "
cold:
   .asciiz "Brr. That is C-O-L-D!!! "
newline:
   .asciiz " "
  

Explanation / Answer

Please find updations below:

ONE

# Temperature Conversion F -> C

TWO

# Conversion from F to C: C=(F-32)*5/9

Gist:

addi $f0, $f0, -32

mul $f0, $f0, 5

div $f0, $f0, 9

//store result accrdingly:

Three

.asciiz "Enter the temperature in Farenheit: "