Assigment due December 6 PLease follow all directions.Thanks! You can only use t
ID: 3572993 • Letter: A
Question
Assigment due December 6 PLease follow all directions.Thanks!
You can only use the MIPS instructions discussed in class up to lecture on Thursday, December 1, 2016. They are: add, addi, addu, addiu, sub, subi, subu, mult, mfhi, mflo, div, and, or, nor, xor, sll, srl, beq, bne, j, lw, li, la, sw, move, syscall.
Write a MIPS assembly language program which uses an array of integers with 10 elements. The program prompts the user to input an integer to store in each element of the array. After the program reads in the 10 integers, it loads the integer from each element and prints it out on a separate line. In addition to printing each integer, the program will compute the sum of the 10 integers in the array. The program prints the sum on the line after printing the last integer of the array.
Program input:
For example, if the name of the array is A and the program prompts the user to input the integer for element 1 (A[1]) then the program would print the following prompt:
Enter an integer to store in element 1 of array A:
Program output:
For example, if the name of the array is A and element 1 (A[1]) stores 32 then the program would print the following output:
Element 1 of array A contains: 32.
For example, if the name of the array is A and the sum of the 10 elements of A is 314 then the program would print the following output:
The sum of the 10 elements of array A is: 314.
Explanation / Answer
I have written a simple assembly program for finding the sum of the array. The language used in mips. Here we load the values from the array and use a loop using branch instructions to loop through the entire array to get the sum of the content in the array.
li $s0, 0
li $a0, 0
li $t0, 0
arraysum:
bge $s0, 10, end_arraysum # compare if we have got the sum of 10 elements from the array.
lw $t1,array($t0) # Ge the number from array
addu $a0, $a0, $t1 # compute the updated sum
addi $t0,$t0,4 # Increment the address by 4 to get the next number
addi $s0,$s0,1 # counter for couting the number of elements in array. Incrementing here by 1.
j arraysum
end_arraysum:
li $v0,1
syscall # Print the value of the sum