MIPS Assembly
Matrix–vector multiplication Perform the following matrix–vector
multiplication.
*****PLEASE ANSWER ALL QUESTIONS AND USE ONLY MIPS
ASSEMBLY PROGRAMMING*****
*****IF ANYTHING OTHER THAN MIPS ASSEMBLY LANGUAGE IS
USED I WILL REPORT YOUR ANSWER AND THUMB DOWN*****
Tony SparkEnlightened
CODE: (Explanation in Comments)

#MIPS assembly code to multiply two matrices
.data
m: .word 1, 2, 3, 4 #store contents of m array
v: .word 5, 6 #store contents of v array
r: .space 8 #reserve space for output array
msg: .asciiz “The contents of resultant vector are:n”
#prompt message
NL: .asciiz “n” #newline
.text
.globl main
main:
la $a0,m #load addresss of m into $a0 i.e., $a0 is a
pointer to m
la $a1,v #load addresss of v into $a1 i.e., $a1 is a
pointer to v
la $a2,r #load addresss of r into $a2 i.e., $a2 is a
pointer to r
#logic for matrix multiplication for first row
lw $t3,0($a0) #load m[0][0]
lw $t4,0($a1) #load v[0][0]
mul $t1,$t3,$t4 #m[0][0]*v[0][0]
lw $t3,4($a0) #load m[0][1]
lw $t4,4($a1) #load v[1][0]
mul $t2,$t3,$t4 #m[0][1]*v[1][0]
add $t1,$t1,$t2 #r[0][0] = m[0][0]*v[0][0] +
m[0][1]*v[1][0]
sw $t1,0($a2) #store in output matrix
lw $t3,8($a0) #load m[1][0]
lw $t4,0($a1) #load v[0][0]
mul $t1,$t3,$t4 #m[1][0]*v[0][0]
lw $t3,12($a0) #load m[1][1]
lw $t4,4($a1) #load v[1][0]
mul $t2,$t3,$t4 #m[1][1]*v[1][0]
add $t1,$t1,$t2 #r[1][0] = m[0][0]*v[0][0] +
m[0][1]*v[1][0]
sw $t1,4($a2) #store in output matrix
#print output
li $v0,4 # 4 is used to print strings
la $a0,msg #print message
syscall
li $v0,1 # 1 is used to print integers
lw $a0,r #print 1st element
syscall
li $v0,4
la $a0,NL #print new line
syscall
li $v0,1
lw $a0,r+4 #print 2nd element
syscall
li $v0,10 # 10 is used to end the program
syscall
OUTPUT:
The contents of resultant vector are: 17 39 program is finished running