Question: Below is an example code. Only touch the matrix _ mul subroutine to write a code that multiplies two n * n matrices. . text
Below is an example code. Only touch the "matrixmul" subroutine to write a code that multiplies two nn matrices.
text
global main
set LEDBASE, x
set SSDBASE, xC
set CZERO, x
set MATRIXN
Rn
main:
BL initLED turn off all the LEDs.
BL disableseg turn it off.
BL initvar R has n You can use it as a global variable to get n
BL LED turn on the rightmost LED.
BL initmatrix
B matrixmul you should implement this subroutine.
maindone:
B checkanswer
checkanswerdone:
B matrixend
matrixmul: R ~ R R are available. Don't touch R R Place the results in the stack. See the slides.
B maindone
initLED:
LDR RLEDBASE
MOV R #
STR RR
BX LR
LED:
LDR RLEDBASE
MOV R #
STR RR
BX LR
LED: wrong
LDR RLEDBASE
MOV R #
STR RR
BX LR
LED: correct
LDR RLEDBASE
MOV R #
STR RR
BX LR
initvar:
LDR RCZERO
LDR RCZERO
LDR RCZERO
LDR RCZERO
LDR RCZERO
LDR RCZERO
LDR RCZERO
LDR RCZERO
LDR RCZERO
LDR RCZERO
LDR RCZERO
LDR RCZERO
LDR RMATRIXN
BX LR
disableseg:
LDR RSSDBASE
MOV R #x
STR RR
BX LR
initmatrix:
LDR RCZERO
LDR RCZERO
LDR RCZERO
MOV R #
MOV R #
MOV R #
PUSH R
PUSH R
PUSH R
MOV R #
MOV R #
MOV R #
PUSH R
PUSH R
PUSH R
MOV R #
MOV R #
MOV R #
PUSH R
PUSH R
PUSH R
MOV R #
MOV R #
MOV R #
PUSH R
PUSH R
PUSH R
MOV R #
MOV R #
MOV R #
PUSH R
PUSH R
PUSH R
MOV R #
MOV R #
MOV R #
PUSH R
PUSH R
PUSH R
BX LR
checkanswer:
LDR RSP #
CMP R #
BNE wronganswer
LDR RSP #
CMP R #
BNE wronganswer
LDR RSP #
CMP R #
BNE wronganswer
LDR RSP #
CMP R #
BNE wronganswer
LDR RSP #
CMP R #
BNE wronganswer
LDR RSP #
CMP R #
BNE wronganswer
LDR RSP #
CMP R #
BNE wronganswer
LDR RSP #
CMP R #
BNE wronganswer
LDR RSP
CMP R #
BNE wronganswer
B correctanswer
correctanswer:
BL LED
B checkanswerdone
wronganswer:
BL LED
B checkanswerdone
matrixend:
end
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
