Assmbly Language # Description: # This program reads series of temperature value
ID: 3788635 • Letter: A
Question
Assmbly Language
# Description:
# This program reads series of temperature values greater than -40 (exclusive,
# so -40 is invalid temperature) and less than 140 (inclusive, so 140 is a valid
# temperature) and will stop reading when -1 is entered. if invalid temperature
# is entered then program prints an error message and rejects the number. in
# the end print the sum and count and also save the sum and count into static
# integer variables: sum_p and count_p
#
# *** temperature should be in range (-40, 140] and stop reading on -1
#
# Sample run:
# Enter a value greater than -40 and less than or equal to 140 (-1 to stop): -40
# Invalid entry
# Enter a value greater than -40 and less than or equal to 140 (-1 to stop): 140
# Enter a value greater than -40 and less than or equal to 140 (-1 to stop): 5
# Enter a value greater than -40 and less than or equal to 140 (-1 to stop): -1
# Sum: 145
# Count: 2
#
###########################################################
# Register Usage
# $t0 Holds the sum
# $t1 Holds the count
# $t2 Holds value -1
# $t3 Holds value -40
# $t4 Holds value 140
###########################################################
.data
prompt_p: .asciiz "Enter a value greater than -40 and less than or equal to 140 (-1 to stop): "
sum_p: .asciiz "Sum: "
count_p: .asciiz "Count: "
invalid_p: .asciiz "Invalid entry "
nextline_p: .asciiz " " #
sum_var_p: .word 0 # initialize static variable sum_p to zero
count_var_p: .word 0 # initialize static variable count_p to zero
###########################################################
.text
main:
mainEnd:
li $v0, 10
syscall # Halt
###########################################################
Explanation / Answer
.data
prompt_p: .asciiz "Enter a value greater than -40 and less than or equal to 140 (-1 to stop): "
sum_p: .asciiz "Sum: "
count_p: .asciiz "Count: "
invalid_p: .asciiz "Invalid entry "
nextline_p: .asciiz " " #
sum_var_p: .word 0 # initialize static variable sum_p to zero
count_var_p: .word 0 # initialize static variable count_p to zero
.text
main:
la $s0,promp_p
la $s1,count_p
$t2: .int -1
$t3: .int -40
$t4: .int 140
beq $s0,$t2,NOP
ble $s0,$t4,l1
l1: bne $s0,$t3,l2
l2: addi $t0,$t0,$s0
add $s1,1
bal invalid_p
mainEnd:
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.