Advertisement
juneba

desenhaElipse.asm

May 2nd, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.84 KB | None | 0 0
  1. .data
  2.  
  3. width: .word 320
  4. height: .word 240
  5.  
  6. .text
  7. #algoritmo que desenha a elipse
  8. #ordem dos argumentos
  9. # a0 = xcentro, a1 = ycentro, a2 = largura, a3=altura
  10. main:
  11. li $a0,150
  12. li $a1,150
  13. li $a2,25
  14. li $a3,25
  15. li $t0,0x0c # adiciona a cor.
  16. addi $sp,$sp,-4
  17. sw $t0,0($sp)
  18.  
  19. jal elipse
  20.  
  21. li $v0,10
  22. syscall
  23.  
  24.  
  25. elipse:
  26.  
  27. lw $t9 , 0($sp) # carregando parâmetro da cor.
  28. addi $sp,$sp,4
  29.  
  30.  
  31. addi $sp,$sp,-36
  32. sw $ra,0($sp)
  33. sw $s0,4($sp)
  34. sw $s1,8($sp)
  35. sw $s2,12($sp)
  36. sw $s3,16($sp)
  37. sw $s4,20($sp)
  38. sw $s5,24($sp)
  39. sw $s6,28($sp)
  40. sw $s7,32($sp)
  41.  
  42. move $s0,$a0 # s0 = xcentro
  43. move $s1,$a1# s1 = ycentro
  44. move $s2,$a2 #s2 = largura da elipse
  45. move $s3,$a3 #s3 = altura elipse
  46. move $a2,$t9 # carrega parametro da cor.
  47.  
  48. mul $s4,$s2,$s2 # largura²
  49. mul $s5,$s3,$s3 # altura²
  50.  
  51. addi $t7,$zero,4
  52. mul $s6,$s4,$t7 # largura² * 4
  53. mul $s7,$s5,$t7 # altura² * 4
  54.  
  55. add $t0,$zero,$zero # reservando pro x
  56. add $t1, $zero, $s3 # y = altura
  57. add $t2,$zero,$zero # reservando pro sigma
  58.  
  59. addi $t7,$zero,2
  60. addi $t4, $zero,1 # 1
  61. mul $t5,$s3,$t7 # 2* altura
  62. sub $t4,$t4,$t5 # ( 1 - 2* altura)
  63. mul $t4, $t4, $s4 # largura² * ( 1 - 2* altura)
  64. mul $t5,$s5,$t7 # altura² * 2
  65. add $t2, $t5, $t4 #sigma = 2*altu2+larg2*(1-2*altura);
  66.  
  67. #parar o FOR QUANDO altu2*x <= larg2*y;
  68. for:
  69. mul $t4,$s5,$t0 # altura ² * x
  70. mul $t5,$s4,$t1 #largura2 *y
  71. bgt $t4,$t5,fimPrimeiroFor
  72.  
  73. addi $sp,$sp,-12
  74. sw $t0,0($sp)
  75. sw $t1,4($sp)
  76. sw $t2,8($sp)
  77. add $a0,$s0,$t0 #xc + x
  78. add $a1,$s1,$t1 #yc + y
  79. jal ponto
  80. lw $t0,0($sp)
  81. lw $t1,4($sp)
  82. lw $t2,8($sp)
  83. addi $sp,$sp,12
  84.  
  85. addi $sp,$sp,-12
  86. sw $t0,0($sp)
  87. sw $t1,4($sp)
  88. sw $t2,8($sp)
  89. sub $a0,$s0,$t0 #xc - x
  90. add $a1,$s1,$t1 #yc + y
  91. jal ponto
  92. lw $t0,0($sp)
  93. lw $t1,4($sp)
  94. lw $t2,8($sp)
  95. addi $sp,$sp,12
  96.  
  97. addi $sp,$sp,-12
  98. sw $t0,0($sp)
  99. sw $t1,4($sp)
  100. sw $t2,8($sp)
  101. add $a0,$s0,$t0 #xc + x
  102. sub $a1,$s1,$t1 #yc - y
  103. jal ponto
  104. lw $t0,0($sp)
  105. lw $t1,4($sp)
  106. lw $t2,8($sp)
  107. addi $sp,$sp,12
  108.  
  109. addi $sp,$sp,-12
  110. sw $t0,0($sp)
  111. sw $t1,4($sp)
  112. sw $t2,8($sp)
  113. sub $a0,$s0,$t0 #xc - x
  114. sub $a1,$s1,$t1 #yc - y
  115. jal ponto
  116. lw $t0,0($sp)
  117. lw $t1,4($sp)
  118. lw $t2,8($sp)
  119. addi $sp,$sp,12
  120.  
  121. blt $t2,$zero,else
  122. addi $t5,$zero,1
  123. sub $t5,$t5,$t1 # t5 = 1 -y
  124. mul $t5,$t5, $s6 # larg4* (1-y)
  125. add $t2,$t2,$t5 # sigma += larg4* (1-y)
  126. addi $t1,$t1,-1
  127. j pulaElse
  128. else:
  129. addi $t7,$zero,4
  130. mul $t5,$t0,$t7 # x * 4
  131. addi $t5,$t5,6
  132. mul $t5,$t5,$s5 # altura² * (4*x) + 6
  133. add $t2,$t2,$t5
  134. pulaElse:
  135. addi $t0,$t0,1
  136. j for
  137. fimPrimeiroFor:
  138.  
  139. add $t0,$zero,$s2 # x = largura
  140. add $t1,$zero,$zero # y = 0
  141. addi $t4,$zero,1
  142. sll $t5,$s2,1 #largura * 2
  143. sub $t5,$t4,$t5 # 1 - (largura * 2)
  144. mul $t5,$t5,$s5 # altura² * 1 - (largura * 2)
  145. sll $t4,$s4,1 # largura²*2
  146. add $t2,$t4,$t5 # sigma = 2*larg2+altu2*(1-2*largura)
  147.  
  148. for2:
  149. mul $t4,$s4,$t1 # larg² * y
  150. mul $t5,$s5,$t0 # altura ² * x
  151. bgt $t4,$t5, fimElipse
  152.  
  153. addi $sp,$sp,-12
  154. sw $t0,0($sp)
  155. sw $t1,4($sp)
  156. sw $t2,8($sp)
  157. add $a0,$s0,$t0 #xc + x
  158. add $a1,$s1,$t1 #yc + y
  159. jal ponto
  160. lw $t0,0($sp)
  161. lw $t1,4($sp)
  162. lw $t2,8($sp)
  163. addi $sp,$sp,12
  164.  
  165. addi $sp,$sp,-12
  166. sw $t0,0($sp)
  167. sw $t1,4($sp)
  168. sw $t2,8($sp)
  169. sub $a0,$s0,$t0 #xc - x
  170. add $a1,$s1,$t1 #yc + y
  171. jal ponto
  172. lw $t0,0($sp)
  173. lw $t1,4($sp)
  174. lw $t2,8($sp)
  175. addi $sp,$sp,12
  176.  
  177. addi $sp,$sp,-12
  178. sw $t0,0($sp)
  179. sw $t1,4($sp)
  180. sw $t2,8($sp)
  181. add $a0,$s0,$t0 #xc + x
  182. sub $a1,$s1,$t1 #yc - y
  183. jal ponto
  184. lw $t0,0($sp)
  185. lw $t1,4($sp)
  186. lw $t2,8($sp)
  187. addi $sp,$sp,12
  188.  
  189. addi $sp,$sp,-12
  190. sw $t0,0($sp)
  191. sw $t1,4($sp)
  192. sw $t2,8($sp)
  193. sub $a0,$s0,$t0 #xc - x
  194. sub $a1,$s1,$t1 #yc - y
  195. jal ponto
  196. lw $t0,0($sp)
  197. lw $t1,4($sp)
  198. lw $t2,8($sp)
  199. addi $sp,$sp,12
  200.  
  201. blt $t2,$zero,else2
  202. addi $t5,$zero,1
  203. sub $t5,$t5,$t0 # t5 = 1 -x
  204. mul $t5,$t5, $s7 # altura4* (1-x)
  205. add $t2,$t2,$t5 # sigma += altura4* (1-x)
  206. addi $t0,$t0,-1
  207. j pulaElse2
  208. else2:
  209. addi $t7,$zero,4
  210. mul $t5,$t1,$t7 # y * 4
  211. addi $t5,$t5,6
  212. mul $t5,$t5,$s4 # altura² * (4*x) + 6
  213. add $t2,$t2,$t5
  214. pulaElse2:
  215. addi $t1,$t1,1
  216. j for2
  217.  
  218. ###
  219. fimElipse:
  220. lw $ra,0($sp)
  221. sw $s0,4($sp)
  222. lw $s1,8($sp)
  223. lw $s2,12($sp)
  224. lw $s3,16($sp)
  225. lw $s4,20($sp)
  226. lw $s5,24($sp)
  227. lw $s6,28($sp)
  228. lw $s7,32($sp)
  229.  
  230. addi $sp,$sp,36
  231. jr $ra
  232.  
  233.  
  234. ponto:
  235. lw $t0, width #largura em t0
  236. lw $t1, height #altura em t1
  237.  
  238. slti $t2,$a0,0 #se x < 0 sai da função
  239. bne $t2, $zero, saida_ponto
  240.  
  241. slti $t2,$a1,0 #se y < 0 sai da função
  242. bne $t2,$zero, saida_ponto
  243.  
  244. slt $t2, $a0, $t0 # se x >= width : sai da função
  245. beq $t2, $zero, saida_ponto
  246.  
  247. slt $t2,$a1,$t1 #se y>= weight : sai da função
  248. beq $t2,$zero, saida_ponto
  249.  
  250. mul $t0,$a1,$t0 #faz y * 320 e coloca em t0
  251. add $t0,$t0,$a0 #faz y * 320 + x e coloca em t0
  252.  
  253. addi $t0, $t0, 0xFF000000 # faz 0xFF000000 + y *320 + x e coloca em t0
  254. sb $a2 , 0($t0) #desenha o ponto de cor a2(byte:= BBGGGRR) na tela (a0,a1:=x,y)
  255. saida_ponto:
  256. jr $ra
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement