Compelete the following MIPS code with the instructions provided. (Each number i
ID: 3704496 • Letter: C
Question
Compelete the following MIPS code with the instructions provided. (Each number in the matrix is represented in signed 2’s complement form. )
Part 1: add the two matrices and store the result in memory starting at address given in s2. The matrices are of the size 3 X 2 each. The two matrices are stored starting at two memory locations whose addresses are given in two registers, s0 and s1.
Part 2: For two matrices that are stored at starting addresses given by s3 and s4 respectively, with M1 of size M X N and M2 of size N X P. Multiply M1 and M2 and stroe the result in memeory starting at address given in s5.
Use XPSIM to run the MIPS code and Do not use commands such as Li, La, Mov or any other pseudo instructions, dont modified anything except "Solution" part of the code. Detail of comments and explaintaions would be greatly appreciated.
//-------code below------//
.globl main
.globl initialize
.globl Solution
.data
matrix1: .word 4, 3, 2, 7, 8, 1
matrix2: .word 3, 7, 2, 8, 9, 0
matrix_A:.word 0, 0, 0, 0, 0, 0 #Store result of Part 1 here
matrix3: .word 4, 3, 2, 7, 8, 1, 4, 2, 8, 4, 2, 1
matrix4: .word 3, 7, 2, 8, 9, 0, 4, 3, 2, 7, 8, 1
matrix_M:.word 0, 0, 0, 0, 0, 0, 0, 0, 0 #Store result of Part 2 here
# Guide to interpret matrix
# Matrix 1 is a 3x2 matrix, so with the given values it would look like this
# | 4 3 |
# | 2 7 |
# | 8 1 |
.text
DO NOT CHANGE $s0 - $s5
main:
jal initialize
or $0,$0,$0 #NOP
j studentCode
or $0,$0,$0
initialize:
lui $at, 0x1000
ori $s0, $at, 0
ori $s1, $at, 24
ori $s2, $at, 48
ori $s3, $at, 72
ori $s4, $at, 120
ori $s5, $at, 168
jr $ra
or $0,$0,$0 #NOP
//--------------dont modified anything else-----//
Solution:
print_Results: #Prints 2 lines of results, Line 1 is result addition
lui $at, 0x1000 # Line 2 is result of multiplication
or $0,$0,$0 #NOP
ori $s2, $at, 48 #All register values are reset here so do not worry if you changed them
ori $s5, $at, 168
addi $t0,$0,','
sw $t0,204($at)
or $0,$0,$0 #NOP
addi $t0,$0,10
sw $t0,208($at)
or $0,$0,$0 #NOP
addi $t0,$0,6
result_1:
beq $t0,$0,result_1_end
or $0,$0,$0 #NOP
lw $a0,0($s2)
or $0,$0,$0 #NOP
addi $v0,$0,1
syscall
ori $a0, $at, 204
addi $v0,$0,4
syscall
addi $t0,$t0,-1
addi $s2,$s2,4
j result_1
or $0,$0,$0 #NOP
result_1_end:
ori $a0, $at, 208
addi $v0,$0,4
syscall
addi $t0,$0,9
result_2:
beq $t0,$0,result_2_end
or $0,$0,$0 #NOP
lw $a0,0($s5)
or $0,$0,$0 #NOP
addi $v0,$0,1
syscall
ori $a0, $at, 204
addi $v0,$0,4
syscall
addi $t0,$t0,-1
addi $s5,$s5,4
j result_2
or $0,$0,$0 #NOP
result_2_end:
print_Results_End:
Explanation / Answer
# 'matrix1'
# 4,3
# 2,7
# 8,1
# 'matrix 2'
# 3,7
# 2,8
# 9,0
.data
matrix1: word 4,3,2,7,8,1
matrix2: word 3,7,2,8,9,0
matrix_A: word 0,0,0,0,0,0 # store result of Part 1 here
matrix3: word 4,3,2,7,8,1,4,2,8,4,2,1
matrix4: word 3,7,2,8,9,0,4,3,2,7,8,1
matrix_M: word 0,0,0,0,0,0,0,0,0 # store result of Part 2 here
endl: .asciiz " "
tab: .asciiz " "
.text
main:
jal initialize
or $0,$0,$0
j studentCode
initialize:
lui $at ,0*1000
ori $s0,$at,0
ori $s1,$at,24
ori $s2,$at,48
ori $s3,$at,72
ori $s4,$at,120
ori $s5,$at, 168
jr $ra
or $0,$0,$0
syscall
print_Results:
lui $at, 0*1000
or $0,$0,$0
ori $s2,$at ,48
them
ori $s5,$at,168
addi $t0,$0;;
sw $t0,204(Sat)
or $0,$0,$0
addi $t0,$0,10
sw $t0,204(Sat)
or $0,$0,$0
addi $t0,$0,10
sw $t0,208(Sat)
or $0,$0,$0
addi $t0,$0,6
result_1:
beq $t0,$0,result_1_end
or $0,$0,$0
lw $a0,0($s2)
or $0,$0,$0
addi $v0,$0,1
syscall
ori $a0,$at,204
addi $v0,S0,4
syscall
addi $t0,$t0,-1
addi $s2,$s2,4
j result_1
or $0,$0,$0
result_1_end;
ori $a0,$at,208
addi $v0,$0,4
syscall
addi $t0,$0,9
result_2:
beq $t0,$0,result_2_end
or $0,$0,$0
lw $a0,0($s5)
or $0,$0,$0
addi $v0,$0,1
syscall
ori $a0 $at 204
addi $v0,$0,4
syscall
addi $t0,$t0,-1
addi $s2,$s2,4
j result_1
or $0,$0,$0
result_1_end:
ori $a0,$at,208
addi $vo,$0,4
syscall
addi $t0,$0,9
result -2;
beq $t0,$0,result_2_end
or $0,$0,$0
lw $a0,0($s5)
or $0,$0,$0
addi $v0,$0,4
syscall
addi $t0,$t0,-1 #add
addi $t0,$t0,-1 #add
addi $s5,$s5,4 # add
j result_2
or $0,$0,$0
result_2_end:
print_Results_End:
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.