Advertisement
Zeda

DE_Div_BC (Unsigned)

Jul 4th, 2013
545
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;===============================================================
  2. DE_Div_BC:
  3. ;===============================================================
  4. ;Performs DE/BC
  5. ;Speed:   1365-2b cycles (b is the number of bits set in the result)
  6. ;Size:    25 bytes
  7. ;Inputs:
  8. ;     HL is the numerator
  9. ;     BC is the denominator
  10. ;Outputs:
  11. ;     DE is the quotient
  12. ;     HL is the remainder
  13. ;     BC is not changed
  14. ;     A is 0
  15. ;     z flag is set
  16. ;===============================================================
  17.      ld a,16
  18.      ld hl,0
  19.      jp $+6       ;change to jr $+5 to save a byte at the cost of 2 extra cycles
  20. DivLoop1:
  21.      add hl,bc
  22.      dec a
  23.      ret z
  24.      sla e
  25.      rl d
  26.      adc hl,hl
  27.      sbc hl,bc
  28.      jr nc,DivLoop1
  29.      inc e
  30.      jp DivLoop1+1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement