Advertisement
Zeda

BC_Div_DE (Speed Tweak, +8 bytes -461cc avg).

Jun 23rd, 2015
757
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;===============================================================
  2. BC_Div_DE:
  3. ;===============================================================
  4. ;Performs BC/DE
  5. ;Speed:   1150+6b cycles when DE<256 (1/256 of the time)
  6. ;         688+6b cycles when DE>=256 (255/256 of the time)
  7. ;         Avg = 716.88671875cc
  8. ;Size:    35 bytes
  9. ;Inputs:
  10. ;     BC is the numerator
  11. ;     DE is the denominator
  12. ;Outputs:
  13. ;     BC is the quotient
  14. ;     HL is the remainder
  15. ;     DE is not changed
  16. ;     A is 0
  17. ;     z flag is set
  18. ;     c flag is reset
  19. ;===============================================================
  20.     ld hl,0
  21.     ld a,b
  22.     ld b,16
  23.     inc d
  24.     dec d
  25.     jr z,loop
  26.     ld l,a
  27.     ld a,c
  28.     ld b,8
  29. loop:
  30.     rl c
  31.     rla
  32.     adc hl,hl
  33.     sbc hl,de
  34.     jr nc,$+3
  35.     add hl,de
  36.     djnz loop
  37.     rl c
  38.     rla
  39.     cpl
  40.     ld b,a
  41.     ld a,c
  42.     cpl
  43.     ld c,a
  44.     ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement