Advertisement
myersjo

MatMul

Feb 8th, 2016
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
ARM 1.84 KB | None | 0 0
  1.     AREA    MatMul, CODE, READONLY
  2.     IMPORT  main
  3.     EXPORT  start
  4.  
  5. start
  6.     LDR R0, =matR
  7.     LDR R1, =matA
  8.     LDR R2, =matB
  9.     ;LDR    R3, =N
  10.     ;LDR R3, [R3]
  11.     LDR R3, =4              ; N
  12.    
  13.     LDR R4, =0              ; i
  14.     LDR R5, =0              ; j
  15.     LDR R6, =0              ; k
  16.    
  17.     LDR R7, =0              ; r(esult)
  18.     LDR R8, =0              ; value A
  19.     LDR R9, =0              ; value B
  20.     LDR R10, =0             ; temporary index
  21.        
  22. iFor
  23.     CMP R4, R3              ; while (i < N)
  24.     BEQ endIFor             ; {
  25.     LDR R5, =0              ;   j =0
  26.  
  27. jFor
  28.     CMP R5, R3              ;   while (j < N)
  29.     BEQ endJFor             ;   {
  30.     LDR R6, =0;             ;       k = 0
  31.     LDR R7, =0;             ;       reset (r)esult
  32. kFor
  33.     LDR R10, =0             ;       clear temporary value
  34.     CMP R6, R3              ;       while (k < N)
  35.     BEQ endKFor             ;       {
  36.    
  37.     ; value in a
  38.     MUL R10, R4, R3         ;           index = (row*row size)
  39.     ADD R10, R10, R6        ;                    +  column
  40.     MUL R10, R3, R10
  41.     ;LDR R8, [R1, R10, LSL #2] ;            address = base address + offset
  42.     LDR R8, [R1, R10] ;         address = base address + offset
  43.     ; value in b
  44.     MUL R10, R6, R3         ;           index = (row*row size)
  45.     ADD R10, R10, R5        ;                    +  column
  46.     MUL R10, R3, R10
  47.     ;LDR R9, [R2, R10, LSL #2] ;            address = base address + offset
  48.     LDR R9, [R2, R10] ;         address = base address + offset
  49.    
  50.     MUL R11, R8, R9         ;           mul = a*b
  51.     ADD R7, R7, R11         ;           r = r + mul
  52.     ADD R6, R6, #1          ;           k++
  53.     B kFor                  ;       }
  54.    
  55. endKFor
  56.     ; index in R
  57.     MUL R10, R4, R3         ;           index = (row*row size)
  58.     ADD R10, R10, R5        ;                    +  column
  59.     MUL R10, R3, R10
  60.     ;STR R7, [R0, R10, LSL #2] ;            store result in (address = base address + offset)
  61.     STR R7, [R0, R10] ;         store result in (address = base address + offset)
  62.     ADD R5, R5, #1          ;           j++
  63.     B jFor                  ;   }
  64.    
  65. endJFor
  66.     ADD R4, R4, #1          ;   i++
  67.     B iFor                  ; }
  68.    
  69. endIFor
  70.  
  71. stop    B   stop
  72.  
  73.  
  74.     AREA    TestArray, DATA, READWRITE
  75.  
  76. N   EQU 4
  77.  
  78. matA   
  79.     DCD 5,4,3,2
  80.     DCD 3,4,3,4
  81.     DCD 2,3,4,5
  82.     DCD 4,3,4,3
  83.  
  84. matB
  85.     DCD 5,4,3,2
  86.     DCD 3,4,3,4
  87.     DCD 2,3,4,5
  88.     DCD 4,3,4,3
  89.  
  90. matR    SPACE   64
  91.  
  92.     END
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement