Question

In: Computer Science

Write a procedure to calculate Average of numbers(integers) using Arrays. Send base address of array in...

Write a procedure to calculate Average of numbers(integers) using Arrays. Send base address of array in register $a1 and Array length in register $a2 to the procedure and return Average in register $v0 to main program.

Solutions

Expert Solution

Below code is tested on MIPS64 gcc 5.4 version . Please run below given code on this compiler and if not then make necessary changes to run on your platform. Thanks

.LC0:

.word 20

.word 3

.word 5

.word 4

.word 2

main:

daddiu $sp,$sp,-64

sd $31,56($sp)

sd $fp,48($sp)

sd $28,40($sp)

move $fp,$sp

lui $28,%hi(%neg(%gp_rel(main)))

daddu $28,$28,$25

daddiu $28,$28,%lo(%neg(%gp_rel(main)))

ld $2,%got_page(.LC0)($28)

daddiu $3,$2,%got_ofst(.LC0)

ldl $4,%got_ofst(.LC0)($2)

ldr $4,7($3)

daddiu $3,$2,%got_ofst(.LC0)

ldl $5,8($3)

ldr $5,15($3)

move $3,$5

sd $4,8($fp)

sd $3,16($fp)

daddiu $2,$2,%got_ofst(.LC0)

lw $2,16($2)

sw $2,24($fp)

sw $0,0($fp)

sw $0,4($fp)

.L3:

lw $2,4($fp)

slt $2,$2,5

beq $2,$0,.L2

nop

lw $2,4($fp)

dsll $2,$2,2

daddu $2,$fp,$2

lw $2,8($2)

lw $3,0($fp)

addu $2,$3,$2

sw $2,0($fp)

lw $2,4($fp)

addiu $2,$2,1

sw $2,4($fp)

b .L3

nop

.L2:

lw $5,0($fp)

move $4,$5

move $3,$4

dsll $2,$3,1

move $3,$2

dsll $2,$3,2

dsubu $2,$2,$3

dsll $3,$2,4

daddu $2,$2,$3

dsll $3,$2,8

daddu $2,$2,$3

dsll $3,$2,16

daddu $2,$2,$3

daddu $2,$2,$4

dsrl $2,$2,32

sll $2,$2,0

sra $3,$2,1

sra $2,$5,31

subu $2,$3,$2

sw $2,0($fp)

lw $2,0($fp)

move $5,$2

ld $2,%got_page(.LC1)($28)

daddiu $4,$2,%got_ofst(.LC1)

ld $2,%call16(printf)($28)

move $25,$2

1: jalr $25

nop

move $2,$0

move $sp,$fp

ld $31,56($sp)

ld $fp,48($sp)

ld $28,40($sp)

daddiu $sp,$sp,64

j $31

nop


Related Solutions

. As input you are given two arrays: an array of numbers ? and an array...
. As input you are given two arrays: an array of numbers ? and an array ? of queries where each query is a target number. The array ? is unsorted and may contain duplicates. Your goal is, for each query ? in the array ?, count the number of pairs in the array ? that sums up to ?; that is, the number of distinct pairs of indices [?, ?], with ? < ?, such that ?[?] + ?[?]...
A local instructor wants you to write a c++ program using arrays to calculate the average...
A local instructor wants you to write a c++ program using arrays to calculate the average score made on exams by her students. For simplicity, she always has only 12 students in each course she teaches. She teaches multiple subjects so she would like to enter the name of the exam. She wants the program to also determine the highest and lowest scores and the number of students who passed and failed the exam. A score of 60 or above...
Write a procedure that accepts a byte string(base address in $a0, length in $ a1) and...
Write a procedure that accepts a byte string(base address in $a0, length in $ a1) and returns its XOR checksum, defined as the exclusive-OR of all its bytes, in $v0. (by MiniMIPS)
Write a procedure to reverse an array. Assume staring address has been passed in ESI, the...
Write a procedure to reverse an array. Assume staring address has been passed in ESI, the number of units in ECX, the unit size in EBX
Exercises on Arrays –using C++programming 1. You want an array with the numbers 100 – 105....
Exercises on Arrays –using C++programming 1. You want an array with the numbers 100 – 105. In the boxes below, fill in what your array should have. Fill in the index of each element below it. Array Index Open up your editor and write the following program: Declare an array that has the numbers 100 to 105. (How many elements are there in the array?) Print the array. Save your file and test it. Compare your results with your table...
USING MatLab (Arrays) Set ASIZE to 5. Write a program that creates an array of ASIZE...
USING MatLab (Arrays) Set ASIZE to 5. Write a program that creates an array of ASIZE numeric elements. Prompt the User for ASIZE numbers and store them in the array. After storing the values, calculate the sum of all the values in the array and display the sum. Modify the program you wrote for Problem 5 such that it calculates the product of all the values instead of the sum. Modify the program you wrote in Problem 6 such that...
IN JAVA PLEASE Given an unsorted array numbers of integers with duplicate values. Sort the array...
IN JAVA PLEASE Given an unsorted array numbers of integers with duplicate values. Sort the array and remove the duplicates in-place such that each element appears only once in the input array and returns the new length. Do not allocate extra space for another array, you must do this by modifying the input array in-place with O(1) extra memory. Find the time complexity of your removeDuplicates() method in Big-O notation and write that in a comment line on the top...
What's the memory address for the following elements arrays given: Base Address: 1000, Dimensions: 10 rows,...
What's the memory address for the following elements arrays given: Base Address: 1000, Dimensions: 10 rows, 5 columns, 4 byte elements. Elements: 0,0; 9,4; 2,2; 4,1; Base Address: 500, Dimensions: 10 rows, 15 columns, 4 byte elements. Elements: 0,0; 9,14; 2,2; 4,11; Base Address: 800, Dimensions: 4 rows, 5 columns, 2 byte elements. Elements: 0,0; 3,4; 2,2; 3,4;
Problem 1: Unsorted arrays Given an array of integers that is unsorted, implement the following functions:...
Problem 1: Unsorted arrays Given an array of integers that is unsorted, implement the following functions: • myAdd ( ): add an integer d to the array; return 0 if the operation is successful; return a negative number otherwise. • search ( ): given an integer d, if d is found in the array, return the index of the cell containing d. Return a negative number otherwise (e.g., d is not found in the array). • myRemove ( ): Step...
In c++ Array expander Write a function that accepts an int array and the arrays size...
In c++ Array expander Write a function that accepts an int array and the arrays size as arguments. The function should create a new array that is twice the size of the argument array. The function should create a new array that is twice the size of the argument array. The function should copy the contents of the argument array to the new array and initialize the unused elements of the second array with 0. The function should return a...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT