Question

In: Computer Science

Assembly langugage , please do comment each line or step if possible . Question 2 of...

Assembly langugage , please do comment each line or step if possible .

Question 2 of 2. Element wise vector multiplication: [30 marks] Write an assembly language program that performs element wise multiplication of two arrays of size 4 and stores the resultant array back into memory.
For Arrays A = [Aw, Ax, Ay, Az] and B = [Bw, Bx, By, Bz], the resultant array C = [Aw*Bw, Ax*Bx, Ay*By, Az*Bz]
1. Reserve and initialize memory for both input arrays
2. Reserve memory for the resultant array in READWRITE section of memory
3. Load the arrays and perform the element wise multiplication operation.
4. Store the resultant array back into memory
Example test case:
FIRST array = [2, 4, -6, 8], SECOND array = [1, 2, 3, 7].
Your program should compute the element wise multiplication of both arrays and store it back to the resultant array.
RESULT array would be computed as [2*1, 4*2, -6*3, 8*7] = [2, 8, -18, 56] (integer), where:
1. The first elements from both arrays (2 and 1) are multiplied and the result (2) is stored in the first location of the RESULT array.
2. The second elements (4 and 2) would be multiplied and the result (8) is stored in the second location of the RESULT array.
3. The third elements (-6 and 3) are multiplied and the result (-18) is stored in the third location
4. Finally, the fourth elements (8 and 7) are multiplied and the result (56) is stored in the fourth location
Resultant array = [0x00000002, 0x00000008, 0xFFFFFFEE, 0x00000038]
Make sure your code works for any input number, not just the test cases. Your code will be tested
on other test cases not listed here.
Please properly comment your code before submission.

Solutions

Expert Solution

.data
   #Declaring and initializing A and B arrays
   A:   .word   2,4,-6,8
   B:   .word   1,2,3,7
   #Declaring array C to store 4 integer elements
   C:   .space   16
   prompt:   .asciiz   "The resultant array is:\n"
   space:   .asciiz   " "

.text
.globl main
main:
   #Loading addresses of A,B and C arrays into temporary registers
   la $t0,A
   la $t1,B
   la $t2,C
   li $t3,4       #Initializing the loop variables
  
   #Loading the elements of the array from memory
loop:   lw $t4,0($t0)
   lw $t5,0($t1)
   mul $t6,$t4,$t5       #Multiplying the elements of A and B arrays
   sw $t6,0($t2)       #Storing the result into C array in memory
  
   #Pointing the temporary registers to next element in array
   addi $t0,$t0,4
   addi $t1,$t1,4
   addi $t2,$t2,4
   addi $t3,$t3,-1
   bnez $t3,loop

   #Displaying the resultant array stored in memory
   li $v0,4
   la $a0,prompt
   syscall
  
   la $t2,C
   li $t3,4
  
   #Printing the elements in resultant array onto console
again:   li $v0,1
   lw $a0,0($t2)
   syscall
  
   li $v0,4
   la $a0,space
   syscall
  
   #Pointing the temporary registers to next element in array
   addi $t2,$t2,4
   addi $t3,$t3,-1
   bnez $t3,again


Related Solutions

Assembly language: please comment on every line of code explaining each part. include head comments describing...
Assembly language: please comment on every line of code explaining each part. include head comments describing what your program does. Assignment 3A - A program that adds and subtracts 32-bit numbers After installing the assembler on the computer, enter the following program, save it, assemble it and run it. Do not forget to add a comment with your name in it. You will hand in a listing (e.g., addsum.asm) that should include your name ________________________________________ TITLE Add and Subtract (AddSum.asm)...
Solve it step by step and please with clear handwritten. Be ready to follow the comment...
Solve it step by step and please with clear handwritten. Be ready to follow the comment Integrability Topic Question1. Let g : [0, 1] —> R be defined by if x=0, g(x)=1; if x=m/n (m and n are positive integer with no common factor), g(x)=1/n; if x doesn't belong to rational number, g(x)=0 Use the sequential criterion for continuity to prove that g is discontinuous at every rational number in[0,1] Question.2 g is continuous at any irrational point in[0,1]. Explain...
Solve it step by step and please with clear handwritten. Be ready to follow the comment...
Solve it step by step and please with clear handwritten. Be ready to follow the comment Integrability Topic Question1. Let g : [0, 1] —> R be defined by if x=0, g(x)=1; if x=m/n (m and n are positive integer with no common factor), g(x)=1/n; if x doesn't belong to rational number, g(x)=0 Use the sequential criterion for continuity to prove that g is discontinuous at every rational number in[0,1] Question.2 g is continuous at any irrational point in[0,1]. Explain...
Using MIPS (MARS) - Assembly Language Assignment ( PLEASE USE COMMENTS TO DESCRIBE EACH STEP )...
Using MIPS (MARS) - Assembly Language Assignment ( PLEASE USE COMMENTS TO DESCRIBE EACH STEP ) Take input of name, the input of hours worked, and input of hourly wage, and use input of hourly wage and hours worked to calculate total paycheck and print Name, and paycheck.
QUESTION 2 Consider the following four--?step assembly operation with quality problems. -The first resource has a...
QUESTION 2 Consider the following four--?step assembly operation with quality problems. -The first resource has a processing time of 7 minutes per unit and one employee doing the operation ? The second resource has a processing time of 4 minutes per unit.  It also has one employee doing the operation. However, this is a very delicate task and 0.79 of all products have to be scrapped after this step. ? Two workers are staffed for the third resource. No quality problems...
Java. If possible please put explanations for each line of code. Write a test program that...
Java. If possible please put explanations for each line of code. Write a test program that prompts the user to enter a series of integers and displays whether the series contains runLength consecutive same-valued elements. Your program’s main() must prompt the user to enter the input size - i.e., the number of values in the series, the number of consecutive same-valued elements to match, and the sequence of integer values to check. The return value indicates whether at least one...
PLEASE POST A COMMENT ON BEFORE AS SOON AS POSSIBLE It is important to consider how...
PLEASE POST A COMMENT ON BEFORE AS SOON AS POSSIBLE It is important to consider how tax rates affect the value of deferred tax assets. If the tax rate goes up, it works to the company’s favor because the assets’ values also go up, therefore providing a bigger cushion for a larger income. But if the tax rate drops, the tax asset value also declines. As head of the Accountant department the person in this role has a responsibility to...
Please apply AD-AS analysis to comment on the possible impact of a pandemic on the U.S....
Please apply AD-AS analysis to comment on the possible impact of a pandemic on the U.S. real GDP in both the short-run and long-run. Please state the shift(s) of AD-AS curves. A reference link (URL) to an article that supports your answer is required.   
please do these 2 problem step by step and how how you get z core SAT...
please do these 2 problem step by step and how how you get z core SAT scores are normally distributed with a mean of 1,500 and a standard deviation of 300. An administrator at a college is interested in estimating the average SAT score of first-year students. If the administrator would like to limit the margin of error of the 86% confidence interval to 15 points, how many students should the administrator sample? Make sure to give a whole number...
There's a 5 step process in risk management. What are they? Comment on them. Please no...
There's a 5 step process in risk management. What are they? Comment on them. Please no handwritten answers.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT