Answer to Question #223953 in Assembler for Ann

Question #223953

An array is defined as a collection of homogenous elements stored in contiguous memory locations. From this background, you are given eight values obtained from some experiment conducted by a researcher to establish the weights in grams of insects after feeding them:

 1.2, 1.4, 1.8, 1.7, 1.0, 1.2, 4.6 and 2.6. Write assembly program to accomplish the following tasks.

1.Calculate and display the total for the weights as recorded from the experiment (8 Marks)

2.Display the weight of second, second last and last weights as observed from the experiment. (7 Marks)


1
Expert's answer
2021-08-06T15:32:54-0400
# Description:
# Write a MIPS  program in MARS
##########################################################################
    .data

total:            .asciiz "The total for the weights: "
second:            .asciiz "\nSecond: "
secondANDlast:  .asciiz "\nSecond last and last weights: "

array:    .float 1.2, 1.4, 1.8, 1.7, 1.0, 1.2, 4.6, 2.6
size:     .word 8
sum:     .float 0.0

    .text
        .globl main
main:

    addi $t0, $zero, 0    # initialize index = 0 in $t0
    lw      $t1, size        
    la   $s0, array     # load the starting address of array into $t2
    lwc1 $f0, sum        # begining sum    
        
loop:
    lwc1  $f1, 0($s0)            # Read array[index] from array    
    add.s $f0, $f0, $f1         # sum
    add $s0, $s0, 4
    add $t1, $t1, -1
    bne  $t1, $zero, loop    
 
    li $v0,4            # print string
    la $a0,total         # "The total for the weights: "
    syscall                       

    li $v0,2             # print  float
    mov.s $f12,$f0         # sum
    syscall    
    
    li $v0,4            # print string
    la $a0,second         # "second: "
    syscall

    la   $s0, array     # load the starting address of array into $t2    
    lwc1  $f12, 4($s0)    # Read array[2-1] from array    
    li $v0,2            # print  
    syscall        
    
    li $v0,4             # print string
    la $a0,secondANDlast         # "Second last and last weights: : "
    syscall

    la   $s0, array     # load the starting address of array into $t2    
    lwc1  $f12, 24($s0)    # Read array[size-2] from array    
    li $v0,2            # print  
    syscall    

    li $v0,11             # print char
    li $a0,' '         
    syscall

    la   $s0, array     # load the starting address of array into $t2    
    lwc1  $f12, 28($s0)            # Read array[size-1] from array    
    li $v0,2                  # print  
    syscall        

    li $v0, 10          # finished .. stop .. return
    syscall             # make the syscall
        

   
 





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