Answer to Question #290151 in Assembler for Zagar

Question #290151

The recorded temperatures in London during a period of 15 days was 18 degrees Celsius, 25 degrees Celsius,34 degrees Celsius,22 degrees Celsius,2 degrees Celsius, 43 degrees Celsius,30 degrees Celsius,20 degrees Celsius,08 degrees Celsius, 28 degrees Celsius, 24 degrees Celsius, 27 degrees Celsius, 40 degrees Celsius,29 degrees Celsius and 03 degrees Celsius. Write a program using MIPS to calculate the average temperature of the country during the month of December.


1
Expert's answer
2022-01-24T08:04:08-0500
# MIPS assembly
# MARS
    .data
temperatures:     .word     18, 25, 34, 22, 2, 43, 30, 20, 8
                .word    28, 24, 27, 40, 29, 3
days:            .word    15
float15:     .float 15.0

msgAnswer:    .asciiz "\nAVG: "
msgEnd:     .asciiz "\n...Finish"
  .text
.globl main

main:
# Loop through the array to calculate sum
    la $t0, temperatures     # array starting address
    li $t1, 0         # loop index, i=0
    lw $t2, days     # days
    li $t3, 0         # initialize sum=0
    
sumLoop:
    lw $t4, ($t0)         # get temperatures[i]
    add $t3, $t3, $t4     # sum = sum + temperatures[i]
    add $t1, $t1, 1     # i = i+1
    add $t0, $t0, 4     # update temperatures address
    blt $t1, $t2, sumLoop # if i<days, continue

# Calculate average
    mtc1 $t3, $f0            # copy $t0 to $f0
    cvt.s.w  $f2, $f0        # convert int $f0 to float $f2
     lwc1 $f0, float15            # $f0 = 15.0
    div.s $f12, $f2, $f0

    li $v0,4            # print string
    la $a0,msgAnswer    # "\nAVG: "
    syscall                # make the syscall print string
    
    li    $v0,2            # Print float
    syscall                # make the syscall print int    

finish:    
    li $v0,4            # print string
    la $a0,msgEnd        # "Finish"
    syscall                # make the syscall    
    
    
 
# Done, terminate program.
    li $v0, 10 # terminate
    syscall # system call

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS