Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- AREA MatMul, CODE, READONLY
- IMPORT main
- EXPORT start
- start
- LDR R0, =matR
- LDR R1, =matA
- LDR R2, =matB
- ;LDR R3, =N
- ;LDR R3, [R3]
- LDR R3, =4 ; N
- LDR R4, =0 ; i
- LDR R5, =0 ; j
- LDR R6, =0 ; k
- LDR R7, =0 ; r(esult)
- LDR R8, =0 ; value A
- LDR R9, =0 ; value B
- LDR R10, =0 ; temporary index
- iFor
- CMP R4, R3 ; while (i < N)
- BEQ endIFor ; {
- LDR R5, =0 ; j =0
- jFor
- CMP R5, R3 ; while (j < N)
- BEQ endJFor ; {
- LDR R6, =0; ; k = 0
- LDR R7, =0; ; reset (r)esult
- kFor
- LDR R10, =0 ; clear temporary value
- CMP R6, R3 ; while (k < N)
- BEQ endKFor ; {
- ; value in a
- MUL R10, R4, R3 ; index = (row*row size)
- ADD R10, R10, R6 ; + column
- MUL R10, R3, R10
- ;LDR R8, [R1, R10, LSL #2] ; address = base address + offset
- LDR R8, [R1, R10] ; address = base address + offset
- ; value in b
- MUL R10, R6, R3 ; index = (row*row size)
- ADD R10, R10, R5 ; + column
- MUL R10, R3, R10
- ;LDR R9, [R2, R10, LSL #2] ; address = base address + offset
- LDR R9, [R2, R10] ; address = base address + offset
- MUL R11, R8, R9 ; mul = a*b
- ADD R7, R7, R11 ; r = r + mul
- ADD R6, R6, #1 ; k++
- B kFor ; }
- endKFor
- ; index in R
- MUL R10, R4, R3 ; index = (row*row size)
- ADD R10, R10, R5 ; + column
- MUL R10, R3, R10
- ;STR R7, [R0, R10, LSL #2] ; store result in (address = base address + offset)
- STR R7, [R0, R10] ; store result in (address = base address + offset)
- ADD R5, R5, #1 ; j++
- B jFor ; }
- endJFor
- ADD R4, R4, #1 ; i++
- B iFor ; }
- endIFor
- stop B stop
- AREA TestArray, DATA, READWRITE
- N EQU 4
- matA
- DCD 5,4,3,2
- DCD 3,4,3,4
- DCD 2,3,4,5
- DCD 4,3,4,3
- matB
- DCD 5,4,3,2
- DCD 3,4,3,4
- DCD 2,3,4,5
- DCD 4,3,4,3
- matR SPACE 64
- END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement