Don't like ads? PRO users don't see any ads ;-)
Guest

RoundHL_Div_C

By: Zeda on Jan 4th, 2012  |  syntax: Z80 Assembler  |  size: 0.56 KB  |  hits: 91  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. RoundHL_Div_C:
  2. ;Inputs:
  3. ;     HL is the numerator
  4. ;     C is the denominator
  5. ;Outputs:
  6. ;     A is twice the remainder of the unrounded value
  7. ;     B is 0
  8. ;     C is not changed
  9. ;     DE is not changed
  10. ;     HL is the rounded quotient
  11. ;     c flag set means no rounding was performed
  12. ;            reset means the value was rounded
  13. ;
  14.        ld b,16
  15.        xor a
  16.          add hl,hl
  17.          rla
  18.          cp c
  19.          jr c,$+4
  20.            inc l
  21.            sub c
  22.          djnz $-7
  23.        add a,a
  24.        cp c
  25.        jr c,$+3
  26.          inc hl
  27.        ret