矩阵乘法与ARM?

时间:2018-09-27 22:37:10

标签: arm

enter image description here

我目前正在尝试找出如何在ARM中编写矩阵乘法的代码。我已经完成并理解了将在下面粘贴的“ C = AB”情况,但是无法弄清楚如何合并上图中的“ C = BA”情况。我已经研究了几个小时,无法弄清楚该怎么做。

.text
.global _start
_start:

@-- Code for initiation of needed loop

MOV r0 , #0                 @-- Using r0 for "i" indexing
MOV r8 , #0                 @-- Using a seperate index for arrays compared to above
LDR r2 , =I                 @-- Getting address for I here
LDR r1 , [r2]               @-- Getting the value of I here
MOV r2 , #0                 @-- Using r2 for "f" indexing
LDR r3 , =a                 @-- Loading r3 with the base of "a" in .data 
LDR r5 , =b                 @-- Loading r5 with the base of "b" in .data
LDR r7 , =c                 @-- Loading r7 with the base of "c" in .data

@-- Loop body which was initiated above

loop:
LDR r4 , [r3 , r8]          @-- Getting a[i] here
LDR r6 , [r5 , r8]          @-- Getting b[i] here
MUL r9 , r4 , r6            @-- Multiplying a[i] * b[i] from above LDR's
ADD r2 , r2 , r9            @-- Add the above in our running sum
STR r2 , [r7]               @-- Store that result in memory for use
ADD r8 , r8 , #4            @-- Adding word offset to our index to prep for add next
ADD r0 , r0 , #1            @-- Adding 1 to i here
CMP r0 , r1                 @-- Determining if we should exit
BLT loop                    @ "if i < I , continue"
MLA r0 , r1 , r2 , r3
SWI 0x11

.data                       @-- Data Section

I: .word 4                      @-- Variable 
a: .word 1 , 2 , 3 , 4          @-- This is Array A
b: .word 9 , 8 , 7 , 6          @-- This is Array B
c: .word 0

.end

0 个答案:

没有答案