Advertisement
artur99

ASM suma elementelor din matrice unde i == aij sau j == aij

Jan 24th, 2018
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1.  
  2. int sumMatrix(int *, int, int) {
  3. _asm {
  4. mov eax, 0
  5. mov ebx, 0 //rand
  6. mov ecx, 0 //coloana
  7. mov edx, [ebp + 8]
  8. mov esi, [ebp + 16] //nr. coloane
  9.  
  10. _while:
  11. cmp ebx, [ebp + 12]
  12. je _endwhile
  13.  
  14. mov ecx, 0
  15. _while2:
  16. cmp ecx, esi
  17. je _endwhile2
  18. //mov edi, [edx + ebx*esi + ecx*4]
  19. mov edi, ebx
  20. imul edi, esi
  21. add edi, ecx
  22. shl edi, 2
  23. mov edi, [edx + edi]
  24.  
  25. cmp edi, ebx
  26. je _addit
  27. cmp edi, ecx
  28. je _addit
  29. jmp _skip
  30.  
  31. _addit:
  32. add eax, edi
  33. _skip:
  34. inc ecx
  35. jmp _while2
  36. _endwhile2:
  37.  
  38. inc ebx
  39. jmp _while
  40. _endwhile:
  41.  
  42. }
  43. }
  44.  
  45. int sumMatrix2(int *, int, int) {
  46. _asm {
  47. mov eax, 0
  48. mov ebx, 0 //rand
  49. mov ecx, 0 //coloana
  50. mov edx, [ebp + 8] //adresa completa
  51. mov esi, 0 //addr
  52. mov edi, [ebp + 12]
  53. imul edi, [ebp + 16]
  54. shl edi, 2
  55.  
  56.  
  57. _while:
  58. cmp esi, edi
  59. je _endwhile
  60. cmp esi, edi
  61. jne _skip
  62. mov ecx, 0
  63. inc ebx
  64. _skip:
  65.  
  66. cmp ebx, [edx + esi]
  67. je _addit
  68. cmp ecx, [edx + esi]
  69. je _addit
  70. jmp _skip2
  71.  
  72. _addit :
  73. add eax, [edx + esi]
  74. _skip2 :
  75.  
  76. inc ecx
  77. add esi, 4
  78. jmp _while
  79. _endwhile :
  80.  
  81. }
  82. }
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89. int main(){
  90. int M[][4] = {
  91. {5, 1, 7, 9},
  92. {10, 8, 2, 1},
  93. {2, 3, 11, 3}
  94. };
  95. cout << sumMatrix2(&M[0][0], 3, 4);
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement