Advertisement
Zeda

HL_Div_BC

Jan 4th, 2012
398
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;===============================================================
  2. HL_Div_BC:
  3. ;===============================================================
  4. ;Performs HL/BC
  5. ;Speed:   1494 cycles
  6. ;Size:    23 bytes
  7. ;Inputs:
  8. ;     HL is the numerator
  9. ;     BC is the denominator
  10. ;Outputs:
  11. ;     HL is the quotient
  12. ;     DE is the remainder
  13. ;     BC is not changed
  14. ;     A is 0
  15. ;     z flag is set
  16. ;     c flag is reset
  17. ;===============================================================
  18.        ld a,16
  19.        ld de,0
  20. Div_Loop_1:
  21.          add hl,hl
  22.          ex de,hl
  23.          adc hl,hl
  24.          or a
  25.          sbc hl,bc
  26.          jr c,$+5
  27.            inc e
  28.            jr $+3
  29.          add hl,bc
  30.          ex de,hl
  31.          dec a
  32.          jr nz,Div_Loop_1
  33.        ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement