Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

hi can i get help with this in assembly language Write an assembly program that

ID: 3588428 • Letter: H

Question

hi can i get help with this in assembly language

Write an assembly program that asks for the number of integers to be read. It then dynamically allocates an array of that size. It will stop reading integers when the array is full. After all the integers are read and validated, the program displays the entries in reverse order, the sum of the entries, and the average of the entries to 4 decimal places using only MIPS Integer commands. There will be at least 4 subprograms.

The first subprogram ‘allocate_array’ will ask the user for the number of integers to be read and dynamically declares an array to hold them. It receives no arguments IN and has two arguments OUT, the base address of the dynamically declared array and it size. Do not forget to validate array size (array size should be greater than zero).

The second subprogram ‘read_values’ which receives two arguments IN, the array base address and its size. Also, it makes sure that each entered number is non-negative and divisible by 2 and 3. It returns (OUT) the sum of valid numbers read in the appropriate registers.

The third subprogram ‘print_backwards’ receives the base address of the array and its size as arguments IN. It has no arguments OUT. It outputs the array in reverse order one number per line at a time.

Hint: Ex: Your array length = 6. Element type = Word / Integer.

#element0

#element1

#element2

#element3

#element4

#element5

You need to print the last element first. So, at the beginning of your printing backwards iteration, at least one of your register should hold the address of theArrow_Marked location of your array.

The fourth subprogram ‘print_average’ which receives as arguments IN the ‘total’ and ‘count’ and has no arguments OUT. It outputs the average of the numbers read to 4 decimal places using only integer commands.

Hint: Take just a pencil and paper. Now try to divide 7 / 3 by hand till 4th decimal point (X. XXXX). How are you obtaining the values after the decimal point? Replicate that same step by step operation in MIPS to get the values after decimal point.

In main, you will call all 4 subprograms and declare and use static variables to hold the base address of the array, count of element, and the sum of values of the elements.

#element0

#element1

#element2

#element3

#element4

#element5

Explanation / Answer

.text #calculates sum of digits recursively SumDigits: sub $sp, $sp, 12 #alloocate 12B on stack sw $ra 0($sp) #save return address sw $a0, 4($sp) #save argument beq $a0, $0, exit_sumdigits #when there is no more digits return 0 rem $t0, $a0, 10 #get last digit sw $t0, 8($sp) #save it on stack div $a0, $a0, 10 #divide argument by 10 jal SumDigits #repeat procedure lw $t0, 8($sp) #read digit from stack add $v0, $v0, $t0 #add digit to previous result lw $ra, 0($sp) #load return address addi $sp, $sp, 12 #free stack jr $ra #return exit_sumdigits: li $v0, 0 #there are no more digits, return 0 lw $ra, 0($sp) #load return address addi $sp, $sp, 12 #free stack jr $ra #return main: li $a0, 75080 #load number in $a0 jal SumDigits #call SumDigits move $a0, $v0 #set a0 = result of SumDigits li $v0, 1 #set $v0 for print int system call syscall li $v0, 10 #set $v0 for exit system call syscall .data