Advertisement
Zeda

Div_HL_C.z80

Oct 27th, 2020 (edited)
2,416
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. HL_Div_C:
  2. ;Inputs:
  3. ;     HL is the numerator
  4. ;     C is the denominator
  5. ;Outputs:
  6. ;     HL is quotient
  7. ;     A is the remainder
  8. ;     B is 0
  9. ;     C is unchanged
  10. ;
  11. ;8+466+{-5+9{0,4+{0,3}}, 261+16{0,3}}
  12. ;min: 469
  13. ;max: 783
  14. ;avg: 626.375
  15.  
  16.   bit 7,c
  17.   jr nz,HL_Div_C_ge_128
  18. HL_Div_C_lt_128:
  19. ;720+16{0,3}
  20. ;min: 720
  21. ;max: 768
  22. ;avg: 744
  23.   xor a
  24.   ld b,16
  25. HL_Div_C_loop:
  26.   add hl,hl
  27.   rla
  28.   cp c
  29.   jr c,$+4
  30.     inc l
  31.     sub c
  32.   djnz HL_Div_C_loop
  33.   ret
  34.  
  35.      
  36. HL_Div_C_ge_128:
  37. ;449+9{0,4+{0,3}}
  38. ;min: 449
  39. ;max: 512
  40. ;avg: 473.75
  41.   ld a,h
  42.   ld h,l
  43.   ld l,0
  44.   ld b,9
  45.   jr $+6
  46. HL_Div_C_ge_128_loop:
  47.   add hl,hl
  48.   rla
  49.   jr c,$+5
  50.   cp c
  51.   jr c,$+4
  52.     inc l
  53.     sub c
  54.   djnz HL_Div_C_ge_128_loop
  55.   ret
  56.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement