Question: Code using MIPS!! .data Size32: .word 3, 2 Size23: .word 2, 3 Matrix1: .word 1, 20, 68, 22, 55, 76 Matrix2: .word 34, 24, 47,

Code using MIPS!!

Code using MIPS!! .data Size32: .word 3, 2 Size23: .word 2, 3

.data

Size32:

.word 3, 2

Size23:

.word 2, 3

Matrix1:

.word 1, 20, 68, 22, 55, 76

Matrix2:

.word 34, 24, 47, 15, 44, 34

Matrix3:

.space 36

Answer3x3:

.word 334, 904, 727, 2642, 2600, 3944, 3010, 4664, 5169

Answer2x2:

.word 3966, 2636, 6677, 3937

LabelA:

.asciiz "Matrix A: "

LabelB:

.asciiz "Matrix B: "

LabelC:

.asciiz "Matrix C: "

Separator:

.asciiz "\t"

crlf:

.asciiz " "

.text

la $a0, Matrix1

la $a1, Size32

la $a2, Matrix2

la $a3, Matrix3

jal MatrixMult

la $a0, LabelA

addi $v0, $0, 4

syscall

la $a0, Matrix1

addi $a1, $0, 3

addi $a2, $0, 2

jal MatrixPrint

la $a0, LabelB

addi $v0, $0, 4

syscall

la $a0, Matrix2

addi $a1, $0, 2

addi $a2, $0, 3

jal MatrixPrint

la $a0, LabelC

addi $v0, $0, 4

syscall

la $a0, Matrix3

addi $a1, $0, 3

addi $a2, $0, 3

jal MatrixPrint

la $a0, Matrix1

la $a1, Size23

la $a2, Matrix2

la $a3, Matrix3

jal MatrixMult

la $a0, LabelA

addi $v0, $0, 4

syscall

la $a0, Matrix1

addi $a1, $0, 2

addi $a2, $0, 3

jal MatrixPrint

la $a0, LabelB

addi $v0, $0, 4

syscall

la $a0, Matrix2

addi $a1, $0, 3

addi $a2, $0, 2

jal MatrixPrint

la $a0, LabelC

addi $v0, $0, 4

syscall

la $a0, Matrix3

addi $a1, $0, 2

addi $a2, $0, 2

jal MatrixPrint

addi $v0, $0, 10

syscall

MatrixPrint:

# $a0 - Matrix

# $a1 - Rows

# $a2 - Columns

# $t0 - Manipulable address of Matrix

# $t1 - Row count

# $t2 - Column count

# $t3 - save address for $a0 (changed in syscalls)

addi $sp, $sp, -4

sw $ra, 0($sp)

addi $t0, $a0, 0

addi $t1, $0, 0

addi $t2, $0, 0

addi $t3, $a0, 0

PrintLoop:

lw $a0, 0($t0)

jal PrintValue

addi $t0, $t0, 4

addi $t2, $t2, 1

bne $t2, $a2, PrintLoop

addi $t2, $0, 0

addi $t1, $t1, 1

la $a0, crlf

addi $v0, $0, 4

syscall

bne $t1, $a1, PrintLoop

la $a0, crlf

addi $v0, $0, 4

syscall

addi $a0, $t3, 0

lw $ra, 0($sp)

addi $sp, $sp, 4

jr $ra

PrintValue:

# $a0 - value

addi $v0, $0, 1

syscall

la $a0, Separator

addi $v0, $0, 4

syscall

jr $ra

MatrixMult:

# $a0 - Matrix 1

# $a1 - Size of Matrix 1

# $a2 - Matrix 2

# $a3 - Matrix 3

# your code goes here

The arguments supplied to MatrixMult are the addresses of the three matrices plus the size of the first. The size of a matrix is expressed as two numbers, so the data in $a1 is the address of a two-word array which has the number of rows in the first word and the number of columns in the second.

The answer matrices are:

334 904 727 3966 2636

2642 2600 3944 and 6677 3937

3010 4664 5169

For this program, you will write a matrix multiply routine capable of multiplying non-square matrices. The size of matrices are expressed as row-column. So the matrix: a13 is a 2 x 3 matrix. If matrix a is as above and we are multiplying A * B = C, then the B matrix must be a 3 x 2 matrix. The result is always a square matrix with the number of rows and columns equal to the number of rows in the first matrix. The product of two matrices is based on the dot products of the rows of the first matrix with the columns of the second matrix. In the example A * B = C, C11 (a11*b11) + (a12*b21) + (a13*b31) or A row 1 B col 1 or Ar1.Bc1, Thus b1 b12 a13 a23 Ar1-Bc1 Ar2 Bc1 Ar1-Bc2 Ar2-Bc2 bs b32 Realize that the data in the program shows six elements in each array. The elements are stored in row- major order in memory. This is the case with most memory layouts. In order to interpret the six linear elements, we must know the rows and columns. For this reason, the number or rows and columns of the first matrix are passed to the matrix multiply routine. The dimensions of the second matrix can be inferred from the dimensions of first matrix. Here is the boilerplate code: For this program, you will write a matrix multiply routine capable of multiplying non-square matrices. The size of matrices are expressed as row-column. So the matrix: a13 is a 2 x 3 matrix. If matrix a is as above and we are multiplying A * B = C, then the B matrix must be a 3 x 2 matrix. The result is always a square matrix with the number of rows and columns equal to the number of rows in the first matrix. The product of two matrices is based on the dot products of the rows of the first matrix with the columns of the second matrix. In the example A * B = C, C11 (a11*b11) + (a12*b21) + (a13*b31) or A row 1 B col 1 or Ar1.Bc1, Thus b1 b12 a13 a23 Ar1-Bc1 Ar2 Bc1 Ar1-Bc2 Ar2-Bc2 bs b32 Realize that the data in the program shows six elements in each array. The elements are stored in row- major order in memory. This is the case with most memory layouts. In order to interpret the six linear elements, we must know the rows and columns. For this reason, the number or rows and columns of the first matrix are passed to the matrix multiply routine. The dimensions of the second matrix can be inferred from the dimensions of first matrix. Here is the boilerplate code

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!