Assembly Language Sample Program
Write a program using assembly language to convert temperature in Celsius to Fahrenheit and
print the results.
List of registers:
v0 - reads in Celsius temperature from the keyboard
t0 - holds Fahrenheit result
a0 - points to output strings
Please use the following steps as a guideline:
1. print prompt "Enter Temperature (Celsius): " on terminal
2. reads an integer
3. to convert, multiply by 9
4. then divide by 5, and
5. add 32 to complete the conversion
6. print string "The temperature in Fahrenheit is " before result
7. print result
8. system call to print out a new line "\n"
end program
Source Code:
# v0 - reads in Celsius temperature from the keyboard
# t0 - holds Fahrenheit result
# a0 - points to output strings
.data
newline: .asciiz "\n"
promptInput: .asciiz " Enter temperature (Celcius) :"
promptOutput: .asciiz " The temperature in Fahrenheit is "
.text
main:
# 1. Get the temperature (celcius) from user, put into $t0.
la $a0 ,promptInput # load the message
li $v0, 4 # Print the message
syscall # make the syscall
li $v0, 5 # load syscall read_int into $v0.
syscall # make the syscall.
move $t0, $v0 # move the number read into $t0.
# 2. Multiply by 9, put into $t0.
mul $t0, $t0, 9 # t0 = t0 * 9
# 3. Divide by 5, put into $t0.
div $t0, $t0, 5 # t0 = $t0/5
# 4. Add 32, put into $t0.
addi $t0, $t0, 32 # t0 = t0 +32
# 5. Now print out the result
la $a0 ,promptOutput # load the output message
li $v0, 4 # Print the message
syscall # make the syscall
move $a0,$t0 # We put the result in a0
li $v0, 1 # Integer print system call
syscall # make the syscall
# 6. Now print out the newline
la $a0, newline # Load the string address
li $v0, 4 # String print syscall
syscall # make the syscall
# 7. Now exit
li $v0, 10 # Exit syscall
syscall # make the syscall
Print Screen: