Advertisement
icatalin

LAB 08 CN probleme

Apr 18th, 2019
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.62 KB | None | 0 0
  1. #suma elementelor de pe diagonala
  2.  
  3. .data
  4. matrice: .word 1, 2, 3, 4
  5. .word 5, 6, 7, 8
  6. .word 9, 10, 11, 12
  7. .word 13, 14, 15, 16
  8.  
  9. dimensiuneArray: .word 4
  10. suma: .word 0
  11.  
  12. lungimeWord = 4 #valoare constanta - un word are 4 octeti
  13.  
  14. .text
  15. .globl main
  16.  
  17. main:
  18.  
  19. la $a0, matrice #incarca adresa de inceput a matricii
  20. lw $a1, dimensiuneArray #stocheaza dimensiunea matricii
  21.  
  22. #cheama functia
  23. jal sumaDiagonala
  24.  
  25. #afiseaza rezultatul
  26. move $a0, $t0
  27. li $v0, 1
  28. syscall
  29.  
  30. #exit
  31. li $v0, 10
  32. syscall
  33.  
  34. .end main
  35.  
  36. .globl sumaDiagonala
  37.  
  38. sumaDiagonala:
  39. #valori initiale pentru suma si indice bucla
  40. li $t0, 0
  41. li $t1, 0
  42. bucla: #pentru calcularea sunet
  43. mul $t2, $t1, $a1 # indice rand * dimensiune rand
  44. add $t2, $t2, $t1 #+ indice coloaana
  45.  
  46. mul $t2, $t2, lungimeWord #multiplica valoarea obtinuta anterior cu dimensiunea unui word
  47. add $t3, $a0, $t2 #aduna valoarea la adresa de inceput
  48.  
  49. lw $t4, ($t3) # incarca valoarea din str indicata de adresa nou obtinuta
  50.  
  51. add $t0, $t0, $t4 #aduna elemntul la valoarea curenta a sunet
  52.  
  53. add $t1, $t1, 1 #incrementeaza indice
  54. blt $t1, $a1, bucla #continua bucla
  55.  
  56. jr $ra
  57.  
  58. .end sumaDiagonala
  59.  
  60.  
  61.  
  62.  
  63. #calcularea functiei x*y
  64. .data
  65.  
  66. x: .word 3
  67. y: .word 2
  68.  
  69. .text
  70. .globl main
  71.  
  72. main:
  73.  
  74. lw $a0, x #incarca x si y
  75. lw $a1, y
  76.  
  77. jal power #jump and link catre functia (eticheta) power
  78.  
  79. #afiseaza valoarea calculata
  80. move $a0, $t1
  81. li $v0, 1
  82. syscall
  83.  
  84. #exit
  85. li $v0, 10
  86. syscall
  87. .end main
  88.  
  89. #functia care calculeaza x*y
  90. .globl power
  91.  
  92. power:
  93. #valori de start pentru bucla
  94. li $t1, 1
  95. li $t0, 0
  96.  
  97. bucla:
  98. mul $t1, $t1, $a0
  99. add $t0, $t0, 1
  100. blt $t0, $a1, bucla
  101.  
  102. jr $ra
  103.  
  104. .end power
  105.  
  106.  
  107. .text
  108. .globl main
  109.  
  110. main:
  111. subu $sp, $sp, 4
  112. sw $ra, 0($sp)
  113. move $s0, $zero
  114. move $s1, $zero
  115.  
  116. loop:
  117. mul $t0, $s0, $s0
  118. addu $s1, $s1, $t0
  119. addu $s0, $s0, 1
  120. ble $s0, 4, loop
  121.  
  122. li $v0, 4
  123. la $a0, str
  124. syscall
  125.  
  126. li $v0, 1
  127. move $a0, $s1
  128. syscall
  129.  
  130. li $v0, 4
  131. la $a0, newline
  132. syscall
  133.  
  134. lw $ra, 0($sp)
  135. addu $sp, $sp, 4
  136. jr $ra
  137.  
  138. .data
  139. str:
  140.  
  141. .asciiz "\n Suma valorilor i^2 cu t = 1 .. 4 este "
  142.  
  143. newline:
  144. .asciiz "\n"
  145.  
  146.  
  147.  
  148.  
  149. .data
  150.  
  151. sir: .word 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
  152. lungime: .word 10
  153. nl: .asciiz "\n"
  154. space: .asciiz " "
  155.  
  156. .text
  157. .globl main
  158.  
  159. main:
  160. la $t0, sir
  161. li $t1, 0
  162. lw $t2, lungime
  163.  
  164. citire:
  165. lw $a0, ($t0)
  166. li $v0, 1
  167. syscall
  168.  
  169. li $v0, 4
  170. la $a0, space
  171. syscall
  172.  
  173. add $t1, 1
  174. add $t0, $t0, 4
  175. blt $t1, $t2, pop
  176.  
  177. la $t0, sir
  178. li $t1, 0
  179.  
  180. push:
  181. lw $t4, ($t0)
  182. subu $sp, $sp, 4
  183. sw $t4, ($sp)
  184.  
  185. add $t1, $t1, 1
  186. add $t0, $t0, 4
  187. blt $t1, $t2, push
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement