Write a SPIM assembly language program convert.s. The program will do the follow
ID: 3680233 • Letter: W
Question
Write a SPIM assembly language program convert.s.
The program will do the following:
Prompt the user to enter a letter indicating Celsius or Fahrenheit
C or c indicates that temperature entered is in Celsius.
F or f indicates that temperature entered is in Fahrenheit.
If the letter entered is not C, c, F, or f, print out error message "Wrong Letter!".
Prompt the user to enter an integer indicating the temperature matching the letter just entered.
Convert the temperature to its counter part.
Explanation / Answer
convert Celsius to Fahrenheit
## temp.a ask user for temperature in Celsius,
## convert to Fahrenheit, print the result.
##
## v0 - reads in celsius
## t0 - holds Fahrenheit result
## a0 - points to output strings
##
#################################################
# text segment #
#################################################
.text
.globl __start
__start:
la $a0,prompt # print prompt on terminal
li $v0,4
syscall
li $v0,5 # syscall 5 reads an integer
syscall
# We use here two pseudo-instructions - mul and div
mul $t0,$v0,9 # to convert,multiply by 9,
div $t0,$t0,5 # divide by 5,then
add $t0,$t0,32 # add 32
la $a0,ans1 # print string before result
li $v0,4
syscall
move $a0,$t0 # print result
li $v0,1
syscall
la $a0,endl # system call to print
li $v0,4 # out a newline
syscall
li $v0,10
syscall # au revoir...
#################################################
# data segment #
#################################################
.data
prompt: .asciiz "Enter temperature (Celsius): "
ans1: .asciiz "The temperature in Fahrenheit is "
endl: .asciiz " "
____________
# Fahrenheit to Celsius .data # following are data prompt: .asciiz " Please input degrees in fahrenheit: " # prompt user for input result: .asciiz " Degrees in celsius is: " # display degrees in celsius bye: .asciiz " Program 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
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.