nodeus

square root

Aug 3rd, 2012
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Square root routine
  2.  
  3. This is a faster square root routine than the one that was previously here, test results say that it’s 26% faster. It is written by Ricardo Bittencourt, so many thanks to him :).
  4.  
  5. ;
  6. ;Square root of 16-bit value
  7. ;In:  HL = value
  8. ;Out:  D = result (rounded down)
  9. ;
  10. Sqr16:    ld de,#0040
  11.     ld a,l
  12.     ld l,h
  13.     ld h,d
  14.     or a
  15.     ld b,8
  16. Sqr16_Loop:
  17.     sbc hl,de
  18.     jr nc,Sqr16_Skip
  19.     add hl,de
  20. Sqr16_Skip:
  21.     ccf
  22.     rl d
  23.     add a,a
  24.     adc hl,hl
  25.     add a,a
  26.     adc hl,hl
  27.     djnz Sqr16_Loop
  28.     ret
Advertisement
Add Comment
Please, Sign In to add comment