Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Returns asteroid closest to bot
- find_ast:
- # t0 Asteroid map and iterator i
- # t1 Bot X
- # t2 Bot Y
- # t3 Iterator i
- # t4 Min Distance^2
- # t5 Length of Asteroid array
- # t6 Asteroid X
- # t7 Asteroid Y
- # t8, t9 Distance^2 and other temp vals
- la $t0, asteroid_map
- sw $t0, ASTEROID_MAP
- lw $t1, BOT_X # Bot x
- lw $t2, BOT_Y # Bot y
- lw $t5, 0($t0) # Length of Asteroid array
- li $t3, 1
- li $t4, 90000 # Condition: Min Distance^2
- find_loop:
- bge $t3, $t5, end_for
- mul $t6, $t3, 4
- add $t6, $t0, $t6
- lw $t6, 0($t6) # Asteroid[i]
- and $t7, $t6, 0xffff # Asteroid y
- srl $t6, $t6, 16 # Asteroid x
- # Following statements and t4 need to be changed to change condition
- # Current condition: Asteroid with min distance^2
- sub $t8, $t6, $t1
- mul $t8, $t8, $t8
- sub $t9, $t7 $t2
- mul $t9, $t9, $t9
- add $t8, $t8, $t9
- # You might also have to change the bge condition based on what
- # you are looking for
- bge $t8, $t4, skip_ast
- move $v0, $t6 # Curr Best Asteroid y
- move $v1, $t7 # Curr Best Asteroid x
- move $t4, $t8 # Distance^2
- skip_ast:
- add $t3, $t3, 1
- j find_loop
- end_for:
- j endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement