MIPS/SPIM programming The problem below emphasizes programming a simple loop, wh
ID: 3703519 • Letter: M
Question
MIPS/SPIM programming
The problem below emphasizes programming a simple loop, which also requires system calls to simulate input/output, register to register and memory reference instructions.
You are to write a program that does the following:
.The program will take inputs from you via the keyboard using syscall 5. A prompt to request the temperature should say “Temperature query” with acceptable input range and a condition for program termination.
To terminate the program, input a 1 and the program should print “Program terminated” and stop.
.The temperatures you will input are in Fahrenheit between 100 °F and 400 °F. If outside the range, print the message “Out of range. Try again” and restart the query again.
.The computer program must be able to sense five ranges. Your computer program must convert the input temperature to Centigrade and adjust the process temperature by adjusting the heater voltage.
The computer should print to the console the appropriate feedback response after each input and query for temperature again.
The feedback response is:
If input is =<235 °F, the console should show the temperature in Centigrade and the message: Severely under temperature <112C - abort process.
236-285 °F, the console should show the temperature in Centigrade and the message: Under temperature <=140C and >112C - increase heat by 5%.
286-316 °F, the console should show the temperature in Centigrade and the message: OK >140C and <=157C - maintain heater voltage.
317-336 °F, the console should show the temperature in Centigrade and the message: Over temperature >157C and <=168C - decrease heater voltage 5%.
> 336 °F, the console should show the temperature in Centigrade and the message: Severely over temperature >168C - abort process.
.In order to slow down the process and let the computer “think” a while, include a timer that counts down from 0x 25000 or other number to 0 after each input. The countdown cycle should provide a delay of about 1 second before the next query.
A validation input/output checklist follows (xxx means actual temperature input after it is converted to degrees C)
Input (T in Fahrenheit) Output
------------------------------ --------------
Query for temperature with limits and termination condition
<100 or >400 Out of range- Try again.
<=235 xxx degrees C Severely under temperature <=112C - abort proces
316 (286-316) xxx degrees C OK> 140C and <=157C - maintan heater voltage
336 (317-336) xxx degrees C over temperature >157C and <=168C" - decreases heater voltage 5%
>336 xxx degrees C severely over temperature >168C- abort process
1 Program terminated
Explanation / Answer
ScreenShot
------------------------------------------------------------------------------------------------------------
Program
#variable declaration
.data
temperature: .asciiz " Enter the temperature in Fahrenheit:"
termination: .asciiz "Program terminated"
errorMsg: .asciiz "Out of range- Try again."
first: .asciiz " degrees C Severely under temperature <=112C - abort proces"
second: .asciiz " degrees C Under temperature <=140C and >112C - increase heat by 5%."
third: .asciiz " degrees C OK >140C and <=157C - maintain heater voltage."
fourth: .asciiz " degrees C Over temperature >157C and <=168C - decrease heater voltage 5%."
fifth: .asciiz " degrees C Severely over temperature >168C - abort process."
fp1: .double 1.8
#main program
text:
.globl main
main:
loop:
#prompt user for input
la $a0,temperature
li $v0,4
syscall
#read the input
li $v0,5
syscall
#if the input is 1 then terminate the program
beq $v0,1,terminate
#temperature comparison loop
#<100 and >400
blt $v0,100,error
bgt $v0,400,error
#<=235
ble $v0,235,tempFirst
# >=236 and <=285
bge $v0,236,tempSecond
ble $v0,285,tempSecond
# >=286 and <=316
bge $v0,286,tempThird
ble $v0,316,tempThird
# >=317 and <=336
bge $v0,317,tempFourth
ble $v0,336,tempFourth
#>336
bgt $v0,336,tempFifth
#>336 calculation
tempFifth:
l.s $f0,fp1
sub $v0,$v0,32
mtc1 $v0, $f12
cvt.s.w $f12, $f12
div.s $f12,$f12,$f0
li $v0,2
syscall
la $a0,fifth
li $v0,4
syscall
j loop
#within 317-336 calculation
tempFourth:
l.s $f0,fp1
sub $v0,$v0,32
mtc1 $v0, $f12
cvt.s.w $f12, $f12
div.s $f12,$f12,$f0
li $v0,2
syscall
la $a0,fourth
li $v0,4
syscall
j loop
#within 286-316 calculation
tempThird:
l.s $f0,fp1
sub $v0,$v0,32
mtc1 $v0, $f12
cvt.s.w $f12, $f12
div.s $f12,$f12,$f0
li $v0,2
syscall
la $a0,third
li $v0,4
syscall
j loop
#within 236-285 calculation
tempSecond:
l.s $f0,fp1
sub $v0,$v0,32
mtc1 $v0, $f12
cvt.s.w $f12, $f12
div.s $f12,$f12,$f0
li $v0,2
syscall
la $a0,second
li $v0,4
syscall
j loop
#<=235 calculation
tempFirst:
l.s $f0,fp1
sub $v0,$v0,32
mtc1 $v0, $f12
cvt.s.w $f12, $f12
div.s $f12,$f12,$f0
li $v0,2
syscall
la $a0,first
li $v0,4
syscall
j loop
#error message
error:
la $a0,errorMsg
li $v0,4
syscall
j loop
#terminate the program
terminate:
la $a0,termination
li $v0,4
syscall
#program exit
li $v0,10
syscall
.end
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.