I'm new to MIPS. How to write a program that prompts the user for a temperature in Celsius and then display the result in Fahrenheit.
Have to use ineteger to float conversion.
//initialize the variables
.data
inputcel: .asciiz "Celcius "
outputfahren: .asciiz "Fahrenheit: "
value1: .float 32.0
value2: .float 5.0
value3: .float 9.0
//read input value to v0 register through accumulator
.text
li $v0, 4
la $a0, inputcel
syscall
li $v0, 6
syscall
//move the values for the calculation to registers
l.s $f1, value1
l.s $f2, value2
l.s $f3, value3
//do the calculations
mul.s $f0, $f0, $f3
div.s $f0, $f0, $f2
add $f0, $f0, $f1
//store the output to v0 register using accumulator
li $v0, 4
la $a0, outputfahren
syscall
li $v0, 2
mov.s $f12, $f0
syscall
//print the value of fahrenheit
li $v0, 10
syscall
This code will convert the temperature in celcius to fahrenheit in floating points.
Get Answers For Free
Most questions answered within 1 hours.