148k views
0 votes
Using only the following instruction set:

add, sub, and, or, slt, lw, sw, beq, addi,and j.
please design a 10x10 multiplying matrix in mips

User HTN
by
8.5k points

1 Answer

5 votes

Final answer:

To design a 10x10 multiplying matrix in MIPS using the given instruction set, you can break it down into smaller steps. Load the matrices from memory, perform the multiplication, and store the result back in memory.

Step-by-step explanation:

To design a 10x10 multiplying matrix in MIPS using the given instruction set, you can accomplish this by breaking down the matrix multiplication algorithm into smaller steps. First, you need to load the matrices from memory using the 'lw' instruction, and then perform the multiplication using multiple 'add', 'sub', and 'slt' instructions. Finally, you can store the resulting matrix in memory using the 'sw' instruction.

Here is an example MIPS code snippet that demonstrates the process:

.data
matrix1: .word 1, 2, 3, 4, ... (10x10 matrix values)
matrix2: .word 1, 2, 3, 4, ... (10x10 matrix values)
result: .word 0, 0, 0, 0, ... (10x10 matrix values)

.text
main:
li $t0, 0
la $t1, matrix1
la $t2, matrix2
la $t3, result

multiply:
li $t4, 0
loop1:
li $t5, 0
li $t6, 0
loop2:
lw $t7, ($t1)
lw $t8, ($t2)
mult $t7, $t8
mflo $t9
add $t6, $t6, $t9
addiu $t1, $t1, 4
addiu $t2, $t2, 40
addi $t5, $t5, 1
bne $t5, 10, loop2

sw $t6, ($t3)
addiu $t1, $t1, -40
addiu $t2, $t2, 4
addiu $t3, $t3, 4
addi $t4, $t4, 1
bne $t4, 10, loop1

li $v0, 10
syscall

User Pexers
by
8.4k points