Advertisement
Guest User

Untitled

a guest
Apr 24th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. # Returns asteroid closest to bot
  2. find_ast:
  3. # t0 Asteroid map and iterator i
  4. # t1 Bot X
  5. # t2 Bot Y
  6. # t3 Iterator i
  7. # t4 Min Distance^2
  8. # t5 Length of Asteroid array
  9. # t6 Asteroid X
  10. # t7 Asteroid Y
  11. # t8, t9 Distance^2 and other temp vals
  12.  
  13. la $t0, asteroid_map
  14. sw $t0, ASTEROID_MAP
  15.  
  16. lw $t1, BOT_X # Bot x
  17. lw $t2, BOT_Y # Bot y
  18.  
  19. lw $t5, 0($t0) # Length of Asteroid array
  20.  
  21. li $t3, 1
  22. li $t4, 90000 # Condition: Min Distance^2
  23.  
  24. find_loop:
  25. bge $t3, $t5, end_for
  26. mul $t6, $t3, 4
  27. add $t6, $t0, $t6
  28. lw $t6, 0($t6) # Asteroid[i]
  29. and $t7, $t6, 0xffff # Asteroid y
  30. srl $t6, $t6, 16 # Asteroid x
  31.  
  32. # Following statements and t4 need to be changed to change condition
  33. # Current condition: Asteroid with min distance^2
  34. sub $t8, $t6, $t1
  35. mul $t8, $t8, $t8
  36. sub $t9, $t7 $t2
  37. mul $t9, $t9, $t9
  38. add $t8, $t8, $t9
  39.  
  40. # You might also have to change the bge condition based on what
  41. # you are looking for
  42. bge $t8, $t4, skip_ast
  43. move $v0, $t6 # Curr Best Asteroid y
  44. move $v1, $t7 # Curr Best Asteroid x
  45. move $t4, $t8 # Distance^2
  46. skip_ast:
  47. add $t3, $t3, 1
  48. j find_loop
  49. end_for:
  50. j endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement