Advertisement
Mihailo21

Asm2

Feb 11th, 2024
26
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.24 KB | None | 0 0
  1. /*
  2. // .data
  3.  
  4. short N = 10; // N = 10
  5. short* p_result = 0x30; // adresa novog niza
  6. short* p_done = 0x50; // adresa za kraj programa
  7.  
  8. short a[10] = {5, 3, 8, 12, 5, 4, -1, 0, 16, 4};
  9. */
  10.  
  11. .data
  12. 10
  13. 0x30
  14. 0x50
  15. 5, 3, 8, 12, 5, 4, -1, 0, 16, 4
  16.  
  17. /*
  18. // .text
  19. for(short i=0; i<N; i++)
  20. {
  21. if(a[i] > 3) and a[i]%2 == 0)
  22. *p_result = a[i];
  23. p_result++;
  24. }
  25.  
  26. *p_done = 1;
  27. */
  28.  
  29. .text
  30. /*
  31. Recommended register list:
  32. R0 - N
  33. R1 - p_result
  34. R2 - p_done
  35. R3 - a[i]
  36. R4 - a[i] koji zadovoljava uslove
  37. R5 - i
  38. R6 - tmp
  39. R7 - tmp
  40. */
  41.  
  42. begin:
  43. ld R0,R0 //R0=N
  44. inc R1,R1
  45. ld R1,R1 //R1= 0x30
  46. inc R7,R7
  47. inc R7,R7
  48. ld R2,R7 //R2=0X50
  49. inc R6,R6
  50. inc R6,R6
  51. inc R6,R6 //R6=3
  52. petlja:
  53. sub R7,R0,R5
  54. jmpz krajpetlje
  55. ld R3,R6
  56. sub R7,R7,R7 //praznjenje
  57. inc R7,R7 //R7=1 i to je maska
  58. and R7,R3,R7 //paran broj vraca 0 a neparan vraca 1
  59. jmpnz naredna
  60. sub R7,R7,R7 //praznjenje
  61. inc R7,R7
  62. inc R7,R7
  63. inc R7,R7 //R7=3
  64. sub R7,R7,R3
  65. jmps dodaj
  66. inc R6,R6
  67. inc R5,R5
  68. jmp petlja
  69. naredna:
  70. inc R6,R6
  71. inc R5,R5
  72. jmp petlja
  73. dodaj:
  74. st R3,R1
  75. inc R6,R6
  76. inc R5,R5
  77. jmp petlja
  78. krajpetlje:
  79. sub R7,R7,R7
  80. inc R7,R7
  81. st R7,R2
  82.  
  83. end:
  84. jmp end
  85.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement