Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Develop a MIPS assembly program named VectorMult.asm that reads in one or more vectors of a specified number of dimensions. Each element of a vector

Develop a MIPS assembly program named VectorMult.asm that reads in one or more vectors of a specified number of dimensions. Each element of a vector is a 32-bit integer word. The vectors are read and stored in main memory. The indexes of any two vectors can be entered and the program prints the element-wise multiplication of the vectors. For example, if the vectors (1, 2, 3) and (4, 5, 6) are read in, multiplying vector 0 and vector 1 results in the program printing (4, 10, 18).

Further details appear below. We strongly suggest you implement and thoroughly test each part before proceeding to the next part.

Part 1: Initial input.
Your program should start by reading two integers. The first integer which we'll call N, specifies the total number of vectors that will be read in. If N is not a positive integer, the program should immediately terminate (without reading another integer). The second integer which we'll call D, specifies the dimensionality of each vector (i.e. how many numbers each vector stores). If D is not a positive integer, the program should terminate.

You will need to store the vectors in the .data segment of your program as they are read in. Your program should support a total of 1000 words of vector data (4 bytes per dimension of each vector). So this could store 100 vectors with 10-dimensions, or 200 vectors with 5-dimensions, etc. If the first two integers would imply an input size greater than one thousand, your program should immediately terminate without reading any further data.

Part 2: Reading vectors.
In the next phase, your program needs to read in the vector data into the .data segment. Your program can expect to receive exactly the required number of integers to populate the N vectors where each vector has D dimensions. Each element of a vector is an integer word.

How you layout your memory is up to you. But a sensible approach would be to have a label at the start of your data segment. After this label you would store the D words that represents the first vector's data. Immediately after this would appear the D words for the second vector, and so on.

Part 3: Multiplying vectors.
In the final phase, the program first reads an integer specifying the 0-based index of a vector. If this first index read in is out of range, the program should terminate. The program then reads in a second index. If the second index read in is out of range, the program should terminate. Note that both indexes could be the same.

If both indexes are valid, the program then prints out the element-wise multiplication of the two vectors. That is, you should multiply together the first element of both vectors, the second element of both vectors, etc. The output should be D integers. The integers are separated by a space. After the D integers, the program should print a line feed.

You can assume that no multiplication will result in a number greater than a 32-bit signed integer can handle (i.e. we won't be testing your program with vectors with large values).

Here are some example runs. Lines starting with # are comments we added to explain each example, they should not be input or output by your program.

### Test 1: number of vectors not valid
0  

-- program is finished running --  

### Test 2: number of dimensions not valid
2
-1

-- program is finished running --  

### Test 3: exceeded maximum of 1000 words
101
10

-- program is finished running --  

### Test 4: two vectors with positive values
### vector 0: (1, 2, 3)
### vector 1: (4, 5, 6)
2
3
1
2
3
4
5
6
0
1
4 10 18
1
0
4 10 18
0
0
1 4 9
1
1
16 25 36
-1

-- program is finished running --
   
### Test 5: three vectors with positive and negative values
### vector 0: (-5, 11, 13, -33)
### vector 1: (0, -1, 0, 1)
### vector 2: (8, 12, 99, -40)
3
4
-5
11
13
-33
0
-1
0
1
8
12
99
-40
0
1
0 -11 0 -33
0
2
-40 132 1287 1320
1
2
0 -12 0 -40
2
2
64 144 9801 1600
2
3

-- program is finished running --
How do I print a line feed?

    li      $v0, 11      # syscall 11 prints character in $a0
    addi    $a0, $0, 10  # ASCII code 10 is a line feed
    syscall
How do I print a space?

 li      $v0, 11      # syscall 11 prints character in $a0
    addi    $a0, $0, 32  # ASCII code 32 is a space
    syscall
Assume that there is no .data

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Cost Management A Strategic Emphasis

Authors: Edward Blocher, David Stout, Paul Juras, Gary Cokins

6th Edition

78025532, 978-0077523732, 77523733, 978-0078025532

More Books

Students also viewed these Algorithms questions

Question

What factors contribute to distortions in memory?

Answered: 1 week ago