Advertisement
Mihailo21

Asm3

Feb 11th, 2024
19
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. /*
  2. // .data
  3.  
  4. short N = 4; // Matrica je veličine 4x4
  5. short i = 2; // Vrsta za koju je potrebno izračunati SUMU
  6. short* p_result = 0x1B;
  7. short* p_done = 0x20;
  8.  
  9. short a[4][4] = {{0, 1, 2, 3}
  10. {4, 5, 6, 7}
  11. {8, 9, 10, 11} // Suma 2. vrste je 38
  12. {12, 13, 14, 15}};
  13.  
  14. */
  15. .data
  16. 4
  17. 2
  18. 0x1B
  19. 0x20
  20. 0, 1, 2, 3,
  21. 4, 5, 6, 7,
  22. 8, 9, 10, 11
  23. 12, 13, 14, 15
  24.  
  25. /*
  26. // .text
  27. short sum = 0;
  28. for(short j=0; j<N; j++)
  29. {
  30. sum += a[i][j]; // a[i + j*N]
  31. }
  32.  
  33. if(sum < 1)
  34. *p_result = sum;
  35. else
  36. *(p_result+1) = sum;
  37.  
  38. *p_done = 1;
  39. */
  40.  
  41. .text
  42. /*
  43. Recommended register list:
  44. R0 - N
  45. R1 - i
  46. R2 - j
  47. R3 - a[j + i*N]
  48. R4 - p_result
  49. R5 - p_done
  50. R6 - tmp
  51. R7 - sum
  52. */
  53.  
  54. begin:
  55. sub R7, R7, R7 // sum = 0;
  56. sub R2, R2, R2 // j = 0;
  57.  
  58. for_petlja:
  59. sub R6, R2, R0 // j - N
  60. jmps kraj_for_petlje // ukoliko nije ispunjeno j <= N
  61. inc R2, R2 // j++
  62. add R7, R7, R3 // sum += a[j + i*N]
  63. jmp for_petlja
  64.  
  65. kraj_for_petlje:
  66. sub R6, R6, R6
  67. sub R5, R5, R5
  68. inc R5, R5
  69. sub R6, R7, R5
  70. jmps kraj_if_naredbe // ukoliko nije ispunjeno sum < 1
  71. mov R4, R7 // *p_result = sum
  72. jmp for_petlja;
  73.  
  74. kraj_if_naredbe:
  75. sub R6, R6, R6
  76. shl R6, R4
  77. mov R4, R6 // *(p_result+1) = sum
  78. jmp for_petlja
  79.  
  80. end:
  81. jmp end
  82.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement