Please fix this code to calculate the result of multiplication of two 4x4 matrices:  .data x: .double 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 y: .double 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 z: .double 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 .text .globl main main:     # Prompt user to enter values for y and z matrices     la $a0, msg1     li $v0, 4     syscall          # Input values for y     la $t0, y

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Please fix this code to calculate the result of multiplication of two 4x4 matrices: 

.data
x: .double 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
y: .double 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
z: .double 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

.text
.globl main
main:
    # Prompt user to enter values for y and z matrices
    la $a0, msg1
    li $v0, 4
    syscall
    
    # Input values for y
    la $t0, y
    li $t1, 16
    li $v0, 7
    
yloop:
    beq $t1, $zero, zloop
    
    syscall
    sdc1 $f0, ($t0)
    addi $t0, $t0, 8
    addi $t1, $t1, -1
    j yloop

    # Input values for z
zloop:
    la $t0, z
    li $t1, 16
    li $v0, 7
    
zinner:
    beq $t1, $zero, multiply
    
    syscall
    sdc1 $f0, ($t0)
    addi $t0, $t0, 8
    addi $t1, $t1, -1
    j zinner
    
    # Multiply y and z matrices and store the result in x
multiply:
    la $t0, y
    la $t1, z
    la $t2, x
    
    # Loop over rows of x
    li $t3, 0
rows:
    beq $t3, 4, print
    
    # Loop over columns of x
    li $t4, 0
cols:
    beq $t4, 4, nextrow
    
    # Initialize sum to 0
    li $t5, 0
    mtc1 $zero, $f4
    
    # Loop over common dimension of y and z
common:
    beq $t5, 4, addsum
    
    # Load y[i][k] and z[k][j]
    lwc1 $f0, ($t0)
    lwc1 $f2, ($t1)
    
    # Multiply y[i][k] and z[k][j] and add to sum
    mul.s $f0, $f0, $f2
    add.s $f4, $f4, $f0
    
    # Move to next element in y and z
    addi $t0, $t0, 8
    addi $t1, $t1, 32
    addi $t5, $t5, 1
    j common
    
    # Add sum to x[i][j]
addsum:
    sdc1 $f4, ($t2)
    addi $t2, $t2, 8
    addi $t4, $t4, 1
    j cols
    
    # Move to next row of x
nextrow:
    addi $t3, $t3, 1
    j rows
    
    # Print values of x
print:

la $a0, msg2
li $v0, 4
syscall
la $t0, x
li $t1, 16
li $v0, 3
printloop:
beq $t1, $zero, exit
lwc1 $f12, ($t0)
syscall
addi $t0, $t0, 8
addi $t1, $t1, -1
j printloop

# Exit program
exit:
li $v0, 10
syscall

.data
msg1: .asciiz "Enter 16 values for y and z matrices: \n"
msg2: .asciiz "Resulting x matrix: \n"

Expert Solution
steps

Step by step

Solved in 3 steps

Blurred answer
Knowledge Booster
Array
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education