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.
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 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
Binary Search. Write a MIPS assembly program to perform a binary search on A[10], which is an array of 10 positive integers.
Binary Search. Write a MIPS assembly program to perform a binary search on A[10], which is an array of 10 positive integers. Your program should have a main routine that does the following:(a) Prompt the user to enter all the 10 integers in the array.(b) Prompt the user to enter the number to be searched.(c) Reads the integer values and makes sure it is a positive integer.(d) Prints the index of the integer. If the input is not available in...
Assembly Language Coding Using MARS (MIPS) 1)Write a program that prints your name in a Triangle....
Assembly Language Coding Using MARS (MIPS) 1)Write a program that prints your name in a Triangle. (NAME = John Doe) 2)Write a Program that intializes X to 10, Y to 20 and Z to -50, adds X and Y and Z and prints the following the value of each variable, for example value of x is 10 as well as the result of the addition.
Using MARS write a MIPS assembly language program to prompt the user to input two 32-bit...
Using MARS write a MIPS assembly language program to prompt the user to input two 32-bit integers X and Y (X and Y can be prompted separately or at the same time), get them from the user then store them in memory locations labeled X and Y respectively. The program then loads X and Y from the main memory to registers, calculates the sum of them (i.e. X + Y) and store the sum into a memory location labeled S....
Using the C Programming language, write a program that sums an array of 50 elements. Next,...
Using the C Programming language, write a program that sums an array of 50 elements. Next, optimize the code using loop unrolling. Loop unrolling is a program transformation that reduces the number of iterations for a loop by increasing the number of elements computed on each iteration. Generate a graph of performance improvement. Tip: Figure 5.17 in the textbook provides an example of a graph depicting performance improvements associated with loop unrolling. Marking:- Optimize the code for an array of...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT