Lab5 (1)
Lab5 (1)
Autumn 2022
Lab-5 (Matrix Multiplication)
This assignment is a take-home assignment and is to be done on the Ripes simulator, in groups
of maximum two students (you may submit alone if you prefer so). In the next lab assignment
(Lab-6), you will execute the same code on the RED-V board in the lab and experience the
execution speedup compared to a simulator.
We are given two 2-D matrices and we need to multiply them to generate a product matrix.
Consider that each of the matrix elements is a 32-bit integer. The dimensions of the matrices
are also provided, as shown in the data section. Write a RISC-V program to multiply the two
matrices. Your program must do the following:
1. First match the dimensions of the matrices to identify whether they can be multiplied.
Else, indicate an error by writing to a memory location and exit the program.
2. If the dimensions are compatible, then perform the multiplication and write the sum
matrix.
Assume that the matrix elements are signed integers and the result will never overflow the
register width.
Following is how the data section is organized (blue are inputs, and red are generated from
program):
.data
L1: .word 0 #This location indicates the error of the result. It is 0 if no error else 1.
.word D1x D1y #x and y dimensions of MATRIX-1
.word <VALUES OF THE MATRIX-1 are present here consecutively, in a row-major order>
.word D2x D2y #x and y dimensions of MATRIX-2
.word <VALUES OF THE MATRIX-2 are present here consecutively, in a row-major order>
.word D3x D3y #values to be written by the program
.word <VALUES OF THE MATRIX-3 (product matrix) should be written by the program here
consecutively, in a row-major order>
main:
la x3, L1
<YOUR CODE STARTS FROM HERE>
Submission instructions:
Submit the assembly code as a file named ROLLNUM1_ROLLNUM2.s (e.g.,
CSYYBTECHXXXXX_CSYYBTECHZZZZZ.S) in the google classroom. Also mention the names
of the team members in comments in the assembly code file. Only one student of the group
should submit the assignment.