Question

MIPS Assembly

Vector (array) addition

Create, in the memory, the following two 2-integer arrays (vectors): Array(A), Array(B).

*****PLEASE USE MIPS FOR THIS PROGRAM ONLY*****

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Program Screenshot:

.data #declare the variables arrayA: word 2, 3 #create array A in the memory array B: word 4, 5 #create arrayB in the memory

finishLoop #printArrayC the sentence i$v0,4 la $a0,sentence syscall li $t0,0 #initailze $t0 with 0 #prints the value of array

Sample output:

Mars MessagesRun O The elements of Array C 6 program is finished running

Code to copy:

.data
   #declare the variables
   arrayA: .word 2, 3 #create array A in the memory
   arrayB: .word 4, 5 #create array B in the memory
   arrayC: .word 0, 0 #declare array C
   sentence: .asciiz "The elements of Array C:\n"
   newLine: .asciiz "\n"

.text
   addi $t0,$zero,0 #initailze $t0 with 0
   li $s0,0 #initailze $s0 with 0
   #finds the sum of arrayA and arrayB
   #and stores the result in arrayC
   findSum :
       lw $t1,arrayA($t0) #get the initial address of arrayA into $t1
       lw $t2,arrayB($t0)#get the initial address of arrayB into $t2
       add $s0,$t1,$t2 #find the sum of $t1 and $t2
       sw $s0,arrayC($t0) #store the sum value into arrayc
       beq $t0,4,finishLoop # if t0 is 4 than go to finishLoop
       add $t0,$t0,4 #increment $t0 by 4 to get next value of the array.
       j findSum #jump to findSum
   finishLoop :
       #printArrayC the sentence
       li $v0,4
       la $a0,sentence
       syscall
       li $t0,0 #initailze $t0 with 0
   #prints the value of arrayC
   printArrayC :
       #get the initial address of arrayC into $t1
       lw $t1,arrayC($t0)
       li $v0,1
       move $a0,$t1
       syscall
       beq $t0,4,endProgram # if t0 is 4 than go to endProgram
       #print a new line
       li $v0,4
       la $a0,newLine
       syscall  
       add $t0,$t0,4 #increment $t0 by 4 to get next value of the array.
       j printArrayC #jump to printArrayC again
  
   #ends the prgram
   endProgram :
       li $v0,10
       syscall

Add a comment
Know the answer?
Add Answer to:
MIPS Assembly Vector (array) addition Create, in the memory, the following two 2-integer arrays (vectors): Array(A),...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Write a mips program that defines two integer array that are pre-sorted and the same size...

    Write a mips program that defines two integer array that are pre-sorted and the same size (e.g., [3, 7, 9, 11, 15, 21] and [1, 4, 6, 14, 18, 19]) and a function merge that takes the two arrays (and their size) as inputs and populates a single array of twice the size of either input array that contains the elements of both arrays in ascending order. In the example arrays given, then output would be [1, 3, 4, 6,...

  • Simulation: Write a MIPS program which computes the vector dot product. Vector dot product involv...

    Simulation: Write a MIPS program which computes the vector dot product. Vector dot product involves calculations of two vectors. Let A and B be two vectors of length n. Their dot product is defined as: Dot Product-2.0 A(i): B(i) Where the result is stored in memory location DOTPROD. The first elements of each vector, A(0) and B(0), are stored at memory locations A_vec and B_vec, with the remaining elements in the following word locations Results: Put your MIPS code here...

  • Write a C++ console application that adds the corresponding elements of two integer arrays of size...

    Write a C++ console application that adds the corresponding elements of two integer arrays of size five. Prompt the user for the ten values and store the first five in the first array and the second five in the second array. Then create and call function matrixAdd that adds the two arrays and prints the five sums. Here is the function prototype: void matrixAdd(int firstArr[], int secondArr[]); [your program code here]*

  • Suppose we have two integer arrays with the same type, write an AL program to check...

    Suppose we have two integer arrays with the same type, write an AL program to check whether or not there are two integers, one from each array, with sum equal to zero. If there are such integers exist, print out all such combinations to the console window, otherise, print out "No integers in these two arrays, one from each array, with sum equal to zero." to the console window. December 3. 2018 For example, suppose we have the following two...

  • MIPS CODE required to write an assembly program to find the maximum of an array of integers by...

    required to write an assembly program to find the maximum of anarray of integers by doing the following:1. Prompt user to input array size n (n <= 10)2. Prompt user to input element values of array A one by one3. Display the result on the console.This program must at least include one function. The main program will read the valuesof the array (as user inputs the element values) and stores them in the memory (datasegments section) and at the end...

  • using mips for assembly language WPte a program that asks the user for 2 numbers. the program should then add the 2 numbers bit by bit, using boolean operators no arithmetic operations ex: add, ad...

    using mips for assembly language WPte a program that asks the user for 2 numbers. the program should then add the 2 numbers bit by bit, using boolean operators no arithmetic operations ex: add, addi, sub, mult, div or arrays are permitted in this project. forming a new variable (in a register) with the solution. That solution is to be output bit by bit using the function that was written in class do not use syscall with a value 10...

  • For the following C statement, what is the corresponding MIPS assembly code? Assume the arrays hold...

    For the following C statement, what is the corresponding MIPS assembly code? Assume the arrays hold 16-bit integer values, $ s0 is the base for array X, $ s1 is the base for array Y, and $ t0 and $ t1 are index variables i and j respectively. Comment code X [j] = Y [i + j];

  • C++ This week, you are to create two separate programs, first using a simple array and...

    C++ This week, you are to create two separate programs, first using a simple array and the second using a 2D-array (matrix). [Part 1] Write a program that accepts exactly ten (10) integer numbers from the user and stores them in an array. In a separate for-loop, the program then goes through the elements in the array to print back: (i) The sum of the 10 numbers, (ii) the minimum value from the 10 numbers, and (iii) the maximum value...

  • C programming Strictly - Write a program to sort an array of integers via arrays of...

    C programming Strictly - Write a program to sort an array of integers via arrays of pointers to those integers as shown in the figure. Problem 1 (68 points): Write a program to sort an array of integers via arrays of pointers to those integers as shown in the figure. The code should contain the following functions: 1)to randomly generate an array of integer numbers; 2) to allocate memory and build the arrays of pointers as shown in the figure...

  • Please and thank you 2) (5 pts) Arrays & Vectors: write a program which prompts the...

    Please and thank you 2) (5 pts) Arrays & Vectors: write a program which prompts the user to enter numbers (terminated with a non-numeric), reads them simultaneously into an array of doubles and into a vector of doubles, then prints A) the array elements in the original order B) the vector elements in reverse order C) the average of the vector elements D) the largest of the vector elements Example program output, user input shown underlined Enter a list of...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT