fill in the blank parts please MIPS Lab 10 Floatingpoint

fill in the blank parts, please. (MIPS)

###########################################################

# Lab 10 - Floating-point

# Description:

# In main, ask the user for an array length, and then allocate a dynamic array of

# double-precision floating-point values (each array element is 8 bytes) of the given length

# Then, store the base address and length of the array in static memory.

# call read_double_array to fill the array

# call print_double_array to print the array contents

# call get_sum_avg to get the sum and average

# print the sum and average

# ask the user for a maximum value

# call print_less_than to print all values less than the given maximum

# High level design:

# from main: ask for array length

# from main: allocate dynamic array of double-precision

# from main: store array length and array base address in static variable

# from main call: null <-- subprogram read_double_array(array base address, array length)

# from main call: null <-- print_double_array(array base address, array length)

# from main call: sum and average <-- get_sum_avg(array base address, array length)

# from main: ask the user for a maximum value

# from main call: null <-- print_less_than(array base address, array length, partition value)

###########################################################

# Register Usage

# $t0 Holds array base address (temporarily)

# $t1 Holds array length (temporarily)

# $t2

# $t3

# $t4

# $t5

# $t6

# $t7

# $t8

# $t9 temporary register

# $f4|$f5 Holds array sum (double-precision floating-point)

# $f6|$f7 Holds array average (double precision floating-point)

###########################################################

.data

array_size_prompt_p: .asciiz \"Enter an array size: \"

sum_p: .asciiz \"Array sum is: \"

average_p: .asciiz \"Array average is: \"

partition_p: .asciiz \"Enter a partition value: \"

nextline_p: .asciiz \"\ \" # \

# declare words to hold dynamic array base and array length

array_pointer_p: .word 0 # holds address dynamic array pointer (address)

array_size_p: .word 0 # hold size of dynamic array (value)

###########################################################

.text

main:

mainEnd:

li $v0, 10

syscall # Halt

###########################################################

# read_double_array subprogram

#

# Subprogram description:

# Reads double-precision floating-point numbers into an array,

# printing a prompt before reading each double

#

###########################################################

# Arguments IN and OUT of subprogram

# $sp+0 Holds array base address (IN)

# $sp+4 Holds array length (IN)

###########################################################

# Register Usage

# $t0 Holds array index address

# $t1 Holds array length/loop countdown

# $f0|$f1 Holds array entry

###########################################################

.data

read_double_array_prompt_p: .asciiz \"Enter a real number: \"

###########################################################

.text

read_double_array:

  

read_double_array_end:

jr $ra # jump back to the main

###########################################################

# print_double_array subprogram

#

# Subprogram description:

# Print array of double-precision floating-point numbers

#

###########################################################

# Arguments IN and OUT of subprogram

# $sp+0 Holds array base address (IN)

# $sp+4 Holds array length (IN)

###########################################################

# Register Usage

# $t0 Holds array index address

# $t1 Holds array length/loop countdown

# $f12|$f13 Holds array value

###########################################################

.data

print_double_array_prompt_p: .asciiz \"Array: \"

print_double_array_space_p: .asciiz \" \"

###########################################################

.text

print_double_array:

print_double_array_end:

jr $ra # jump back to the main

###########################################################

# get_sum_avg subprogram

#

# Subprogram description:

# Calculate sum and average of an array of doubles

# If the number of elements is 0, print an error and return 0.0 for both sum and average

#

# Remember, to calculate average we need to divide sum (:: double) / (:: integer)

# But there is no type promotion (or widening primitive conversion)in MIPS, which mean as a programmer we have to

# implicitly convert count to double before being able to sum by count.

#

###########################################################

# Arguments IN and OUT of subprogram

# $sp+0 Holds array base address (IN)

# $sp+4 Holds array length (IN)

# $sp+8 Holds array sum {double precision floating-point number} (OUT)

# $sp+16 Holds array average {double precision floating-point number} (OUT)

###########################################################

# Register Usage

# $t0 Holds array index address

# $t1 Holds array length/loop countdown

# $t2 Holds loop countdown

# $f4|$f5 Holds array Sum

# $f6|$f7 Holds array Average

# $f8|$f9 Holds array value/Count

###########################################################

.data

get_sum_avg_invalid_count_p: .asciiz \"Invalid count, cannot calculate average\ \"

###########################################################

.text

get_sum_avg:

# NOTE:

# complete this subprogram only after finishing and testing the code for: main, read_double_array and print_double_array

#

get_sum_avg_end:

  

jr $ra # jump back to the main

###########################################################

# print_less_than subprogram

#

# Subprogram description:

# Prints all values from the array which are less

# than the given maximum

#

###########################################################

# Arguments IN and OUT of subprogram

# $sp+0 Holds array base address (IN)

# $sp+4 Holds array length (IN)

# $sp+8 Holds maximum value {double precision floating-point number} (IN)

###########################################################

# Register Usage

# $t0 Holds array index address

# $t1 Holds array length/Loop countdown

# $f4|$f5 Holds partition value

# $f12|$f13 Holds array value (array element at any particular index)

###########################################################

.data

print_less_than_prompt_p: .asciiz \"Array values less than partition value are: \"

print_less_than_space_p: .asciiz \" \"

###########################################################

.text

print_less_than:

# NOTE:

# complete this subprogram only after finishing and testing the code for: main, read_double_array and print_double_array

#

  

print_less_than_end:

jr $ra # jump back to the main

###########################################################

Solution

#   Description:

#       In main, ask the user for an array length, and then allocate a dynamic array of

#       double-precision floating-point values (each array element is 8 bytes) of the given length

#       Then, store the base address and length of the array in static memory.

#       call read_double_array to fill the array

#       call print_double_array to print the array contents

#       call get_sum_avg to get the sum and average

#       print the sum and average

#       ask the user for a maximum value  

#       call print_less_than to print all values less than the given maximum

#   High level design:

#       from main: ask for array length

#       from main: allocate dynamic array of double-precision

#       from main: store array length and array base address in static variable

#       from main call: null <-- subprogram read_double_array(array base address, array length)

#       from main call: null <-- print_double_array(array base address, array length)

#       from main call: sum and average <-- get_sum_avg(array base address, array length)

#       from main: ask the user for a maximum value

#       from main call: null <-- print_less_than(array base address, array length, partition value)

###########################################################

#       Register Usage

#   $t0 Holds array base address (temporarily)

#   $t1 Holds array length (temporarily)

#   $t2

#   $t3

#   $t4

#   $t5

#   $t6

#   $t7

#   $t8

#   $t9 temporary register

#   $f4|$f5     Holds array sum (double-precision floating-point)

#   $f6|$f7     Holds array average (double precision floating-point)

###########################################################

        .data

array_size_prompt_p:    .asciiz \"Enter an array size: \"

sum_p:                  .asciiz \"Array sum is: \"

average_p:              .asciiz \"Array average is: \"

partition_p:            .asciiz \"Enter a partition value: \"

nextline_p:             .asciiz \"\ \"    # \

# declare words to hold dynamic array base and array length

array_pointer_p:        .word 0     # holds address dynamic array pointer (address)

array_size_p:           .word 0     # hold size of dynamic array (value)


        .text

main:
    System.out.println(\"Enter an array size: \");
   Scanner scanner = new Scanner(System.in);
   int length = scanner.nextInt();
   System.out.println(\"Enter The Base Address: \");
   int base_address = scanner.nextInt();
   read_double_array(base_address, length)

mainEnd:

    li $v0, 10

    syscall                 # Halt

#       read_double_array subprogram

#   Subprogram description:

#       Reads double-precision floating-point numbers into an array,

#       printing a prompt before reading each double

############################################################

#       Arguments IN and OUT of subprogram

#   $sp+0   Holds array base address (IN)

#   $sp+4   Holds array length (IN)

###########################################################

#       Register Usage

#   $t0         Holds array index address

#   $t1         Holds array length/loop countdown

#   $f0|$f1     Holds array entry

###########################################################

        .data

read_double_array_prompt_p:      .asciiz \"Enter a real number: \"

###########################################################

        .text

read_double_array(int base_address,int length)
int[] arrayNumber = new int[length];
System.out.println(\"Enter The Numbers Do You Want to add Array\");
Scanner scan = new Scanner(System.in);
     for(int i=0;i<length;i++){
        arrayNumber[i] = scan.nextInt();
}

  

read_double_array_end:

    jr $ra                  # jump back to the main

###########################################################

#   print_double_array subprogram
     
#     for(int i=0;i<length;i++){
        System.out.println(arrayNumber[i]+\" \");
}

#   Subprogram description:

#       Print array of double-precision floating-point numbers

#

###########################################################

#       Arguments IN and OUT of subprogram

#   $sp+0   Holds array base address (IN)

#   $sp+4   Holds array length (IN)

###########################################################

#       Register Usage

#   $t0         Holds array index address

#   $t1         Holds array length/loop countdown

#   $f12|$f13   Holds array value

###########################################################

        .data

print_double_array_prompt_p:   .asciiz     \"Array: \"

print_double_array_space_p:    .asciiz     \" \"    

###########################################################

        .text

print_double_array:

print_double_array_end:

    jr $ra                  # jump back to the main

###########################################################

#       get_sum_avg subprogram(int[] arrayNum)

#       int sum=0;
         double avg=0.0;
    for(int j=0;j<arrayNum.length;i++){
         sum = sum + arrayNum[i];
      }
   avg = sum/arrayNum.length;
   System.out.println(\"The Sum OF Array is== \"+sum+\" Average is=== \"+avg);
#   Subprogram description:

#       Calculate sum and average of an array of doubles

#       If the number of elements is 0, print an error and return 0.0 for both sum and average

#

#       Remember, to calculate average we need to divide sum (:: double) / (:: integer)

#       But there is no type promotion (or widening primitive conversion)in MIPS, which mean as a programmer we have to

#       implicitly convert count to double before being able to sum by count.

#

###########################################################

#       Arguments IN and OUT of subprogram

#   $sp+0   Holds array base address (IN)

#   $sp+4   Holds array length (IN)

#   $sp+8   Holds array sum {double precision floating-point number} (OUT)

#   $sp+16 Holds array average {double precision floating-point number} (OUT)

###########################################################

#       Register Usage

#   $t0         Holds array index address

#   $t1         Holds array length/loop countdown

#   $t2         Holds loop countdown

#   $f4|$f5     Holds array Sum

#   $f6|$f7     Holds array Average

#   $f8|$f9     Holds array value/Count

###########################################################

        .data

get_sum_avg_invalid_count_p:     .asciiz \"Invalid count, cannot calculate average\ \"

###########################################################

        .text

get_sum_avg:

# NOTE:

#   complete this subprogram only after finishing and testing the code for: main, read_double_array and print_double_array

#

get_sum_avg_end:

  

    jr $ra                  # jump back to the main

###########################################################

#       print_less_than subprogram

#

#   Subprogram description:

#       Prints all values from the array which are less

#       than the given maximum

#

###########################################################

#       Arguments IN and OUT of subprogram

#   $sp+0   Holds array base address (IN)

#   $sp+4   Holds array length (IN)

#   $sp+8   Holds maximum value {double precision floating-point number} (IN)

###########################################################

#       Register Usage

#   $t0         Holds array index address

#   $t1         Holds array length/Loop countdown

#   $f4|$f5     Holds partition value

#   $f12|$f13   Holds array value (array element at any particular index)

###########################################################

        .data

print_less_than_prompt_p:   .asciiz     \"Array values less than partition value are: \"    

print_less_than_space_p:    .asciiz     \" \"           

###########################################################

        .text

print_less_than:

# NOTE:

#   complete this subprogram only after finishing and testing the code for: main, read_double_array and print_double_array

#

  

print_less_than_end:

    jr $ra                  # jump back to the main

fill in the blank parts, please. (MIPS) ########################################################### # Lab 10 - Floating-point # Description: # In main, ask the
fill in the blank parts, please. (MIPS) ########################################################### # Lab 10 - Floating-point # Description: # In main, ask the
fill in the blank parts, please. (MIPS) ########################################################### # Lab 10 - Floating-point # Description: # In main, ask the
fill in the blank parts, please. (MIPS) ########################################################### # Lab 10 - Floating-point # Description: # In main, ask the
fill in the blank parts, please. (MIPS) ########################################################### # Lab 10 - Floating-point # Description: # In main, ask the
fill in the blank parts, please. (MIPS) ########################################################### # Lab 10 - Floating-point # Description: # In main, ask the
fill in the blank parts, please. (MIPS) ########################################################### # Lab 10 - Floating-point # Description: # In main, ask the
fill in the blank parts, please. (MIPS) ########################################################### # Lab 10 - Floating-point # Description: # In main, ask the
fill in the blank parts, please. (MIPS) ########################################################### # Lab 10 - Floating-point # Description: # In main, ask the
fill in the blank parts, please. (MIPS) ########################################################### # Lab 10 - Floating-point # Description: # In main, ask the
fill in the blank parts, please. (MIPS) ########################################################### # Lab 10 - Floating-point # Description: # In main, ask the

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site