# MIPS Help. Fahrenheit to Celsius

trouty323
Code:
# Fahrenheit to Celsius

.data	# following are data
prompt: .asciiz "\nPlease input degrees in fahrenheit: "	# prompt user for input
result: .asciiz "\nDegrees in celsius is: "			# display degrees in celsius
bye: .asciiz "\nProgram terminated"				# display when program terminates

.globl main

.text	# following are instructions
main:	# exection begins

li $v0, 4 # system call to print string la$a0, prompt	# put prompt address into register a0
syscall

li $v0, 5 # system call to read integer syscall addi$t0, $v0, -32 mul$t0, $t0, 5 div$t0, $t0, 9 la$a0, result
li $v0, 4 syscall move$a0, $t0 li$v0, 2
syscall

End:

la $a0, bye li$v0, 4
syscall

li $v0, 10 syscall No matter what I type in, I am getting a result of 0. Can anyone locate what I am doing wrong? ## Answers and Replies JaredJames I don't know this language, but looking at your calcs, they use the variable t0 but you finish calling v0. So it looks like you've got: t0 = v0 - 32 t0 = t0 / 5 t0 = t0 * 9 and then you call v0 at the end instead of t0. Science Advisor Assuming all those syscalls act like a DOS interrupt, I agree with jared in that you are passing the wrong value from the wrong register. caffenta I don't know MIPS either, but a quick http://courses.missouristate.edu/KenVollmar/Mars/Help/SyscallHelp.html" [Broken] showed that a syscall with$v0=2 is "print float" with the value in $f12, but you seem to be working with integers. syscall$v0=1 seems to be for integers with the value in $a0. Code: move$a0, $t0 li$v0, 2     [i]<--- Should be 1 instead of 2?[/i]
syscall

Last edited by a moderator:
JaredJames
Either way, after all the calculations are done with t0, it's not used again. Only v0 and a0.

So the value for t0 - the conversion - is missed out completely.

caffenta
Did you scroll down a bit in the code section of the OP? The instruction "move $a0,$t0" moves the value from register $t0 to$a0, which is used by the syscall routine (or whatever syscall is). I don't know if the previous syscall overwrites the value in $t0 or not. JaredJames Did you scroll down a bit in the code section of the OP? The instruction "move$a0, $t0" moves the value from register$t0 to $a0, which is used by the syscall routine (or whatever syscall is). Yes, but the 'result' function is used before that. The result is called using a0 and v0. Then after that a0 is made t0. trouty323 Thanks for all of the suggestions everybody. Luckily, I was able to get help from a close friend. Thanks again. JaredJames Thanks for all of the suggestions everybody. Luckily, I was able to get help from a close friend. Thanks again. And the solution was? (I don't know the language so am somewhat curious.) caffenta result is the string "Degrees in celsius is:" From what I can tell, the program does this: 1) Prints "Please input degrees in fahrenheit:" 2) Waits for user to enter an integer, stores value in$v0
3) Calculates $t0=($v0-32)*5/9
4) Prints "Degrees in celsius is:"
5) Prints value in $t0 (maybe the bug since the wrong value is stored in$v0)
6) Prints "Program terminated"

caffenta
And the solution was? (I don't know the language so am somewhat curious.)

I'm also curious. Don't leave us hanging, trouty323...

Last edited:
JaredJames
result is the string "Degrees in celsius is:"

From what I can tell, the program does this:

1) Prints "Please input degrees in fahrenheit:"
2) Waits for user to enter an integer, stores value in $v0 3) Calculates$t0=($v0-32)*5/9 4) Prints "Degrees in celsius is:" 5) Prints value in$t0 (maybe the bug since the wrong value is stored in \$v0)
6) Prints "Program terminated"

Ah I see, I was looking at it printing 4 and 5 together.

Still curious why you wouldn't print t0 directly though.

Mentor
trouty323,
When you're writing assembly code it is especially crucial to add comments indicating what you're doing. Each block of statements should be commented, especially the block where you're calculating the Celsius temp and the blocks where you're doing input or output.