Advertisement
Zeda

BC_Div_DE (Speed Optimized 456cc avg, 144 bytes)

Jun 23rd, 2015
779
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;+92 bytes, -110cc
  2. ;===============================================================
  3. BC_Div_DE:
  4. ;===============================================================
  5. ;Performs BC/DE
  6. ;Speed:   674+6b+a cycles when DE<256 (1/256 of the time)
  7. ;         431+6b cycles when DE>=256 (255/256 of the time)
  8. ;         Avg = 455.96484375cc
  9. ;Size:    144 bytes
  10. ;Inputs:
  11. ;     BC is the numerator
  12. ;     DE is the denominator
  13. ;Outputs:
  14. ;     BC is the quotient
  15. ;     HL is the remainder
  16. ;     DE is not changed
  17. ;     A is 0
  18. ;     z flag is set
  19. ;     c flag is reset
  20. ;===============================================================
  21.     ld hl,0
  22.     ld a,b
  23.     inc d
  24.     dec d
  25.     jr z,upper
  26.     ld l,a
  27.     ld a,c
  28.     ld b,h
  29. lower:
  30. ;-110cc
  31.     rla \ adc hl,hl \ sbc hl,de \ jr nc,$+3 \ add hl,de
  32.     rla \ adc hl,hl \ sbc hl,de \ jr nc,$+3 \ add hl,de
  33.     rla \ adc hl,hl \ sbc hl,de \ jr nc,$+3 \ add hl,de
  34.     rla \ adc hl,hl \ sbc hl,de \ jr nc,$+3 \ add hl,de
  35.     rla \ adc hl,hl \ sbc hl,de \ jr nc,$+3 \ add hl,de
  36.     rla \ adc hl,hl \ sbc hl,de \ jr nc,$+3 \ add hl,de
  37.     rla \ adc hl,hl \ sbc hl,de \ jr nc,$+3 \ add hl,de
  38.     rla \ adc hl,hl \ sbc hl,de \ jr nc,$+3 \ add hl,de
  39.     rla
  40.     cpl
  41.     ld c,a
  42.     ret
  43. upper:
  44. ;-106
  45.     ld a,h
  46. loop_upper:
  47.     rl c \ rla \ sub e \ jr nc,$+3 \ add a,e
  48.     rl c \ rla \ sub e \ jr nc,$+3 \ add a,e
  49.     rl c \ rla \ sub e \ jr nc,$+3 \ add a,e
  50.     rl c \ rla \ sub e \ jr nc,$+3 \ add a,e
  51.     rl c \ rla \ sub e \ jr nc,$+3 \ add a,e
  52.     rl c \ rla \ sub e \ jr nc,$+3 \ add a,e
  53.     rl c \ rla \ sub e \ jr nc,$+3 \ add a,e
  54.     rl c \ rla \ sub e \ jr nc,$+3 \ add a,e
  55.     ld l,a
  56.     ld a,c
  57.     rla
  58.     cpl
  59.     ld b,a
  60.     jp lower
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement