Advertisement
Zeda

SqrtL

Jul 1st, 2013
492
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. SqrtL:
  2. ;Inputs:
  3. ;      L is the value to find the square root of
  4. ;Outputs:
  5. ;      C is the result
  6. ;      B,L are 0
  7. ;     DE is not changed
  8. ;      H is how far away it is from the next smallest perfect square
  9. ;      z flag set if it was a perfect square
  10. ;Destroyed:
  11. ;      A
  12.      ld bc,400h       ; 10    10
  13.      ld h,c           ; 4      4
  14. sqrt8Loop:            ;
  15.      add hl,hl        ;11     44
  16.      add hl,hl        ;11     44
  17.      rl c             ; 8     32
  18.      ld a,c           ; 4     16
  19.      rla              ; 4     16
  20.      sub a,h          ; 4     16
  21.      jr nc,$+5        ;12|19  48+7x
  22.        inc c
  23.        cpl
  24.        ld h,a
  25.      djnz sqrt8Loop   ;13|8   47
  26.      ret              ;10     10
  27. ;287+7x
  28. ;19 bytes
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement