Advertisement
Zeda

BC_Div_DE_round

Mar 25th, 2015
670
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;===============================================================
  2. BC_Div_DE_round:
  3. ;===============================================================
  4. ;Performs BC/DE, rounded
  5. ;Speed:   1226+10a+6b cycles, 1320cc worst case
  6. ;Size:    32 bytes
  7. ;Inputs:
  8. ;     BC is the numerator
  9. ;     DE is the denominator
  10. ;Outputs:
  11. ;     BC is the quotient
  12. ;     DE is divided by 2 (truncated)
  13. ;     A reflects the low bits of the quotient
  14. ;Destroys: HL
  15. ;===============================================================
  16.     ld a,b
  17.     ld hl,0
  18.     ld b,16
  19.  
  20.     rl c
  21.     rla
  22.     adc hl,hl
  23.     sbc hl,de
  24.     jr nc,$+3
  25.     add hl,de
  26.     ccf
  27.     djnz $-11
  28.     rl c
  29.     rla
  30.     ld b,a
  31.     srl d
  32.     rr e
  33.     sbc hl,de
  34.     ret c
  35.     inc bc
  36.     ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement