Question

In: Computer Science

Using MIPS assembly language In this program, you should define an array of 10 elements in...

Using MIPS assembly language

In this program, you should define an array of 10 elements in your data segment with these values:

? = {11, 12,−10, 13, 9, 12, 14, 15,−20, 0}

a. Write a function which finds the maximum value of this array.

b. Write another function which calculates the summation of this array.

c. Call these functions in your main program, and print the outputs of these functions to the user i. “The maximum is 15” ii. “The summation is 56”

d. What is the address that has been used by the simulator for this array?

Solutions

Expert Solution

ANSWER :

data
# Initialization of array
theArray: .word 11, 12, -10, 13, 9, 12, 14, 15, -20, 0

# intialization of phrases to console
phrase: .asciiz "The maximum is "
phrase2: .asciiz "\nThe summation is "

.text
main:
li $a2, 9 # a2 = 9 = array length
  
la $t0, theArray # put address of array into $t0
  
# Print address of array
# li $v0, 1 # load appropriate system call code into register $v0;
# move $a0, $t0 # move integer to be printed into $a0: $a0 = $t0
# syscall

# Print out phrase for FindMaxValue output
li $v0, 4 # print_string $a0 = string
la $a0, phrase # Print to console
syscall # call operating system to perform print operation
  
#Call FindMaxValue
li $t1, 0 # t1 = 0: index i
li $a1, 0 # a1 = 0 = maxVal
j FindMaxValue # jump to FindMaxValue

Exit:
# Print maxVal
li $v0, 1 # load appropriate system call code into register $v0;
move $a0, $a1 # move integer to be printed into $a0: $a0 = $t6
syscall
  
# Print out phrase for Summation output
li $v0, 4 # print_string $a0 = string
la $a0, phrase2 # Print to console
syscall # call operating system to perform print operation
  
# Call Summation
li $t1, 0 # t1 restore back to 0
li $a1, 0 # a1 = 0 = sumVal
j Summation

THANK YOU


Related Solutions

Use MIPS assembly language program to swap two of the integers in an integer array. The...
Use MIPS assembly language program to swap two of the integers in an integer array. The program should include the Swap function to swap the integers and the main function to call the Swap function. The main function should: • Pass the starting address of the array in $a0. • Pass the indices of the two elements to swap in $a1 and $a2. • Preserve (i.e. push onto the stack) any T registers that it uses. • Call the Swap...
MIPS Assembly LanguageWrite a MIPS assembly language program that asks the user toinput an...
MIPS Assembly LanguageWrite a MIPS assembly language program that asks the user to input an integer and then prints out a string that shows how that integer should be encoded using 16 bits. Your program should handle both positive and negative valued inputs. Your program should also print out an error message if the given input cannot be expressed as a 16 bit signed integer.As an example, if the input is 12, your program should output “0000000000001100”. If the input...
Write an assembly language program to define an array of 5 double words initialized to 33,44,25,72,23,11...
Write an assembly language program to define an array of 5 double words initialized to 33,44,25,72,23,11 (all decimal). Add the first three numbers together and subtract the last two numbers from the sum. Store the sum in EAX register. Display the sum by using Irvine32 library procedures or by dumping registers to the display and taking a screenshot.
Written in MIPS assembly language If given an array which is sorted in ascending order, as...
Written in MIPS assembly language If given an array which is sorted in ascending order, as well as its length and a target value. You are asked to find the index of this target value in the array using binary search algorithm. Here is an example: array 1, 4, 6, 8, 10, 12 length 6 target 8 2 In this case, the returned result should be assigned to be 3, as array[3] is equal to target. (Note: The target will...
write a mips program to find the number of elements of the array that are divisible...
write a mips program to find the number of elements of the array that are divisible by 3.
In MIPS Assembly Language in Mars, define a method 1 to check if a number is...
In MIPS Assembly Language in Mars, define a method 1 to check if a number is divisible by 4. Then, define a method 2 to generate a random number, call method 1, and return result(number, yes/no) to main. Lastly, have the main method call method 2, and display the results.
write mips assembly mips assembly (x+a) (bx^2+cx+d) using the pesedo- code with loop ,program should claclute...
write mips assembly mips assembly (x+a) (bx^2+cx+d) using the pesedo- code with loop ,program should claclute six T[i] and display aproper message about roots .the the program should store all T[i] as memory array a = [1, 1, 1, 1, 1, 1]; b = [1, 2, 4, 8, 16, 32]; c = [-6, -4, -2, 2, 4, 6]; d = [-1, -3, -5, -7, -9, -11]; for (i=0 ; i<=6; i++) { T[i] =-4 *b [i] * d[i] +c[i] *...
Write a program in MIPS assembly language to perform the calculation of the following equation and...
Write a program in MIPS assembly language to perform the calculation of the following equation and save the result accordingly:    f = 5x + 3y + z Assumptions: - Registers can be used to represent variables x, y, z, and f - Initialize x, y, and z to values of your choice. f can be initialized to zero. - Use comments to specify your register usage and explain your logic
Write a MIPS assembly language program to find the addition of two arrays
Write a MIPS assembly language program to find the addition of two arrays
Write a MIPS assembly program that calculates the sum of all the elements in the following...
Write a MIPS assembly program that calculates the sum of all the elements in the following array: int array[10]={12,21,3,40,15,6,17,8,29,10}
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT