Advertisement
Zeda

BC_Div_DE (Size+Speed Optimized).

Jun 23rd, 2015
902
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:   1130+6b cycles
  6. ;Size:    27 bytes
  7. ;Inputs:
  8. ;     BC is the numerator
  9. ;     DE is the denominator
  10. ;Outputs:
  11. ;     BC is the quotient
  12. ;     HL is the remainder
  13. ;     DE is not changed
  14. ;     A is 0
  15. ;     z flag is set
  16. ;     c flag is reset
  17. ;===============================================================
  18.     ld a,b
  19.     ld hl,0
  20.     ld b,16
  21. loop:
  22.     rl c
  23.     rla
  24.     adc hl,hl
  25.     sbc hl,de
  26.     jr nc,$+3
  27.     add hl,de
  28.     djnz loop
  29.     rl c
  30.     rla
  31.     cpl
  32.     ld b,a
  33.     ld a,c
  34.     cpl
  35.     ld c,a
  36.     ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement