3o_3v

matrix dot

Mar 14th, 2022
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. %include "io.inc"
  2.  
  3. section .bss
  4.     A: resd 10000
  5.     B: resd 10000
  6.     C: resd 10000
  7.     n: resd 1
  8.     m: resd 1
  9.     k: resd 1
  10. section .text
  11. global CMAIN
  12. CMAIN:
  13.     mov ebp, esp; for correct debugging
  14.     push esi
  15.     push edi
  16.     xor esi, esi
  17.     xor edi, edi
  18.     GET_DEC 4, [n]
  19.     GET_DEC 4, [m]
  20.     GET_DEC 4, [k]
  21.    
  22.     mov eax, dword [n]
  23.     mov ebx, dword [m]
  24.     mul ebx
  25.     xor ebx, ebx
  26.     a1:
  27.         GET_DEC 4, [A+4*ebx]
  28.         inc ebx
  29.         cmp ebx, eax
  30.         jne a1
  31.        
  32.     mov eax, dword [m]
  33.     mov ebx, dword [k]
  34.     mul ebx
  35.     xor ebx, ebx
  36.     a2:
  37.         GET_DEC 4, [B+4*ebx]
  38.         inc ebx
  39.         cmp ebx, eax
  40.         jne a2
  41.    
  42.     xor eax, eax ;i 0..n-1
  43.     xor ebx, ebx ;s 0..m-1
  44.     xor ecx, ecx ;j 0..k-1
  45.     xor edx, edx ;здесь будем аккумулировать сумму
  46.     ;c[i][j] = sum(s=0..m-1) a[i][s]*b[s][j]
  47.     L1:
  48.         L2:
  49.             SUMM:
  50.                 mov esi, dword[m]
  51.                 imul esi, eax
  52.                 add esi, ebx
  53.                 mov esi, [A+4*esi]
  54.                 mov edi, dword[k]
  55.                 imul edi, ebx
  56.                 add edi, ecx
  57.                 mov edi, [B+4*edi]
  58.                 imul esi, edi
  59.                 add edx, esi
  60.                 ;
  61.                 inc ebx
  62.                 cmp ebx, dword[m]
  63.                 jne SUMM
  64.             mov esi, dword[k]
  65.             imul esi, eax
  66.             add esi, ecx
  67.             mov dword[C+4*esi], edx
  68.             xor edx, edx
  69.             xor ebx, ebx
  70.             inc ecx
  71.             cmp ecx, dword[k]
  72.             jne L2
  73.         xor ecx, ecx
  74.         inc eax
  75.         cmp eax, dword[n]
  76.         jne L1
  77.    
  78.     xor eax, eax ;i=0..n-1
  79.     xor ebx, ebx ;j=0..k-1
  80.     ;c[i][j] = c[i*k+j]
  81.     V1:
  82.         V2:
  83.             mov edx, dword[k]
  84.             imul edx, eax
  85.             add edx, ebx
  86.             PRINT_DEC 4, [C+4*edx]
  87.             PRINT_CHAR ' '
  88.             inc ebx
  89.             cmp ebx, dword[k]
  90.             jne V2
  91.         xor ebx, ebx
  92.         NEWLINE
  93.         inc eax
  94.         cmp eax, dword[n]
  95.         jne V1
  96.     pop edi
  97.     pop esi
  98.     xor eax, eax
  99.     ret
Advertisement
Add Comment
Please, Sign In to add comment