Question: For this assignment, you will write a main routine in which two n x 1 vectors are defined in a similar manner to how numbers_to_use:

For this assignment, you will write a main routine in which two n x 1 vectors are defined in a similar manner to how numbers_to_use: is implemented in lab 0. (n must be greater or equal to 7 and some of the values must be negative numbers no values should be 0). Your main program will configure the stack pointer appropriately and pass the parameters to a function called dot_product. Do not use registers to pass the parameters to the dot product function and do not pass pointers to the arrays. You will use registers $v0 and $v1 to return values from the functions.

You will generate a function named dot_product which takes elements from each vector and after configuring the stack appropriately, passes two operands via the stack to a function called num_mult.

You will generate the function num_mult which takes two operands passed via the stack and multiplies them together. The function will then test the result to determine if the product can accurately be represented in 32 bits. If there is no overflow, then the num_mult will return the product in the $v0 register and a value of 0 in the $v1 register. If there is an overflow, then the num_mult procedure will return a value of 0 in the $v0 register and -1 in the $v1 register. (Remember, the product of a positive number and a negative number is negative and the product of two negative number is positive, so your overflow detection logic should take this into consideration.)

Your dot_product function will calculate a sum of the returned values from each call to num_mult and return the sum in $v0 and 0 in $v1. If any of the values returned from num_mult indicate an overflow, then the dot_product function will return a 0 in $v0 and -1 in $v1. In addition, your dot_product function should also check for an overflow in the running sum calculation process. In the event of an overflow in the running sum, the dot_product result will zero, as well.

Upon completion of the dot-product calculations, your main program should have a spin loop at the end so that you can use the debugger to verify that your program has correctly calculated the vector dot product by examining the contents of the $v0 register.

For this lab, you will be graded on how well you document your code. You will be well served to spend a little time generating pseudocode that shows the high level detail of what your code

is supposed to be doing. Spend some time generating the design before you actually start writing code. Include your pseudocode in your lab report.

Your code will be examined to verify that you strictly adhere to the MIPS register usage conventions. It is also mandatory that you use the stack to pass parameters to the called routines as specified above, as this is the one of the main objectives of this lab.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!