Question: I am having trouble understanding this lab. It would be helpful if you could show the C++ logic as well. You will be using C++
I am having trouble understanding this lab. It would be helpful if you could show the C++ logic as well.




You will be using C++ ABI for MIPS to create two functions that solve different problems. The structures used in this program are: struct Values { char operation; short left; short right; int result; }; struct Matrix3 { int mat[9]; }; struct Vector3 { int vec[3]; }; The gofunc Function The gofunc function has the following C++ prototype: int gofunc(Values values[], int num_values); This function will take an array of Values structures and perform the operation given in the field "operation to every Value structure's left right and store the result in the result field. You will be doing this for num_values number of elements. This is why the structure is NOT constant. It will be modified in place. Finally, when this function is done, it will return the number of valid operations that were successfully performed. The following operations must be supported: '&' T result = left & right result = left right result = left ^ right result = -left "^ The MatMul Function The matmul function has the following prototype: void matmul(Vector3 &result, const Matrix3 &mat, const Vector3 &vec); This function will perform matrix multiplication on mat x vec and store the resulting vector into result. If you don't remember, matrix multiplication is performed as follows. m11 m12 m 13 V1 m21 m22 m23 X V2 = mii X v1 + m 12 X V2 + m 13 X V3 m21 X v1 + m22 X V2 + m23 X 03 Lm31 X v1 + m32 X V2 + m 33 X 03. Lm31 m32 33 L03 To receive credit for this function, you must use loops. Take a look at the formula above and notice the parallelism there, such as v1 being present for all first column values (m11, m21, and m31). The matrix in the structure is formatted in row-major, meaning that m[0] = m11, m[1] = m12, and m[2] = m13 and so forth. Testing As always, I recommend you write your logic in C++, then translate. If you ask for help with the TAs (or me), we may ask you to show us your logic. Do not change the prototypes and do not change the structures. Notice that there is no "int main". You can create one to test your code, but we will only be testing your product function. Notice that these are pure functions, so you will only need the text section. Restrictions and Hints 1. You must use the proper registers for your functions' parameters and return types. 2. Do not prompt the user for anything inside of these functions. All of the data will be passed into your function from main. 3. You are permitted to use the stack for local variables or to preserve saved registers, and global variables are not permitted. 4. You may use pseudo-instructions for this lab as long as you know how it operates. 6. You can create a main to test your functions, however do not submit it or anything to support it. We only want gofunc and matmul in one assembly source file. You will be using C++ ABI for MIPS to create two functions that solve different problems. The structures used in this program are: struct Values { char operation; short left; short right; int result; }; struct Matrix3 { int mat[9]; }; struct Vector3 { int vec[3]; }; The gofunc Function The gofunc function has the following C++ prototype: int gofunc(Values values[], int num_values); This function will take an array of Values structures and perform the operation given in the field "operation to every Value structure's left right and store the result in the result field. You will be doing this for num_values number of elements. This is why the structure is NOT constant. It will be modified in place. Finally, when this function is done, it will return the number of valid operations that were successfully performed. The following operations must be supported: '&' T result = left & right result = left right result = left ^ right result = -left "^ The MatMul Function The matmul function has the following prototype: void matmul(Vector3 &result, const Matrix3 &mat, const Vector3 &vec); This function will perform matrix multiplication on mat x vec and store the resulting vector into result. If you don't remember, matrix multiplication is performed as follows. m11 m12 m 13 V1 m21 m22 m23 X V2 = mii X v1 + m 12 X V2 + m 13 X V3 m21 X v1 + m22 X V2 + m23 X 03 Lm31 X v1 + m32 X V2 + m 33 X 03. Lm31 m32 33 L03 To receive credit for this function, you must use loops. Take a look at the formula above and notice the parallelism there, such as v1 being present for all first column values (m11, m21, and m31). The matrix in the structure is formatted in row-major, meaning that m[0] = m11, m[1] = m12, and m[2] = m13 and so forth. Testing As always, I recommend you write your logic in C++, then translate. If you ask for help with the TAs (or me), we may ask you to show us your logic. Do not change the prototypes and do not change the structures. Notice that there is no "int main". You can create one to test your code, but we will only be testing your product function. Notice that these are pure functions, so you will only need the text section. Restrictions and Hints 1. You must use the proper registers for your functions' parameters and return types. 2. Do not prompt the user for anything inside of these functions. All of the data will be passed into your function from main. 3. You are permitted to use the stack for local variables or to preserve saved registers, and global variables are not permitted. 4. You may use pseudo-instructions for this lab as long as you know how it operates. 6. You can create a main to test your functions, however do not submit it or anything to support it. We only want gofunc and matmul in one assembly source file