In: Computer Science
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?
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