Advertisement
wolfboyft

sm83 asm backwardly iterate over all pairs of particles for an n-body sim

Sep 9th, 2023
1,592
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. AccelerateBodies:
  2.     ; Accelerate bodies
  3.     ld a, [wNumParticles]
  4.     cp 2
  5.     ret c ; Not enough bodies (need at least 2)
  6.     ; For b backwards from len - 1 inclusive to 1 inclusive
  7.     ld b, a
  8.     dec b
  9. .outerLoop
  10.     ; For c backwards from i - 1 inclusive to 0 inclusive
  11.     ld c, b
  12.     dec c
  13. .innerLoop
  14.     ; b: first particle's index, c: second particle's index
  15.    
  16.     ; Get and apply forces
  17.  
  18.     ; Has c finished counting down?
  19.     dec c
  20.     ld a, c
  21.     cp -1 ; Check for underflow
  22.     jr nz, .innerLoop
  23.     ; Has b finished counting down?
  24.     dec b
  25.     jr nz, .outerLoop
  26.     ret
  27.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement