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 "matrix_mul" subroutine to write a code that multiplies two n*n matrices.
.text
.global main
.set LED_BASE, 0x41210000
.set SSD_BASE, 0x43C10000
.set C_ZERO, 0x00000000
.set MATRIX_N,3
// R12(n)
main:
BL init_LED // turn off all the LEDs.
BL disable_7seg // turn it off.
BL init_var // R12 has n. You can use it as a global variable to get n.
BL LED_0001// turn on the rightmost LED.
BL init_matrix
B matrix_mul // you should implement this subroutine.
main_done:
B check_answer
check_answer_done:
B matrix_end
matrix_mul: // R0 ~ R11, R14 are available. Don't touch R12, R15. Place the results in the stack. See the slides.
B main_done
init_LED:
LDR R0,=LED_BASE
MOV R1, #0
STR R1,[R0]
BX LR
LED_0001:
LDR R0,=LED_BASE
MOV R1, #1
STR R1,[R0]
BX LR
LED_1001: // wrong
LDR R0,=LED_BASE
MOV R1, #9
STR R1,[R0]
BX LR
LED_1111: // correct
LDR R0,=LED_BASE
MOV R1, #15
STR R1,[R0]
BX LR
init_var:
LDR R0,=C_ZERO
LDR R1,=C_ZERO
LDR R2,=C_ZERO
LDR R3,=C_ZERO
LDR R4,=C_ZERO
LDR R5,=C_ZERO
LDR R6,=C_ZERO
LDR R7,=C_ZERO
LDR R8,=C_ZERO
LDR R9,=C_ZERO
LDR R10,=C_ZERO
LDR R11,=C_ZERO
LDR R12,=MATRIX_N
BX LR
disable_7seg:
LDR R0,=SSD_BASE
MOV R1, #0x00
STR R1,[R0]
BX LR
init_matrix:
LDR R0,=C_ZERO
LDR R1,=C_ZERO
LDR R2,=C_ZERO
MOV R0, #2
MOV R1, #3
MOV R2, #4
PUSH {R0}
PUSH {R1}
PUSH {R2}
MOV R0, #5
MOV R1, #6
MOV R2, #7
PUSH {R0}
PUSH {R1}
PUSH {R2}
MOV R0, #1
MOV R1, #3
MOV R2, #5
PUSH {R0}
PUSH {R1}
PUSH {R2}
MOV R0, #4
MOV R1, #6
MOV R2, #8
PUSH {R0}
PUSH {R1}
PUSH {R2}
MOV R0, #2
MOV R1, #3
MOV R2, #7
PUSH {R0}
PUSH {R1}
PUSH {R2}
MOV R0, #2
MOV R1, #7
MOV R2, #5
PUSH {R0}
PUSH {R1}
PUSH {R2}
BX LR
check_answer:
LDR R0,[SP, #32]
CMP R0, #22
BNE wrong_answer
LDR R0,[SP, #28]
CMP R0, #49
BNE wrong_answer
LDR R0,[SP, #24]
CMP R0, #57
BNE wrong_answer
LDR R0,[SP, #20]
CMP R0, #46
BNE wrong_answer
LDR R0,[SP, #16]
CMP R0, #97
BNE wrong_answer
LDR R0,[SP, #12]
CMP R0, #117
BNE wrong_answer
LDR R0,[SP, #8]
CMP R0, #20
BNE wrong_answer
LDR R0,[SP, #4]
CMP R0, #50
BNE wrong_answer
LDR R0,[SP]
CMP R0, #54
BNE wrong_answer
B correct_answer
correct_answer:
BL LED_1111
B check_answer_done
wrong_answer:
BL LED_1001
B check_answer_done
matrix_end:
.end

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!