home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / SIMTEL / CPMUG / CPMUG008.ARK / DIVIDE1.LIB < prev    next >
Text File  |  1984-04-29  |  931b  |  41 lines

  1.  
  2. ;++++++++++++++++++++++++++++++++++++++++++++++
  3. ;
  4. ; UNSIGNED BINARY DIVIDE
  5. ;
  6. ; DIVIDE1.LIB  -  Version 0.1  -  14 SEP 77
  7. ;
  8. ; J.W. SHOOK, P.O. BOX 185, ROCKY POINT, NY 11778
  9. ;
  10. ;++++++++++++++++++++++++++++++++++++++++++++++
  11.  
  12. ; Divides 16 bit dividend by 8 bit
  13. ; divisor producing a 16 bit quotient
  14. ; and an 8 bit remainder.
  15.  
  16. ; CALL with:
  17. ;    HL = Dividend
  18. ;    C  = Divisor
  19.  
  20. ; RETURN with:
  21. ;    HL = Quotient
  22. ;    C  = Divisor
  23.     A  = Remainder
  24. ;    CARRY = Set on divide by zero
  25.  
  26.  
  27. DIVIDE:    XRA    A    ; Clear extension of dividend reg
  28.     CMP    C    ; Check if divisor = 0
  29.     STC        ; Mark divide error
  30.     RZ        ; Return on / by 0
  31.     MVI    B,16    ; Set loop counter
  32. DIVID1:    DAD    H    ; Shift dividend left into
  33.     RAL        ; dividend extension reg.
  34.     CMP    C    ; Extension >= divisor?
  35.     JC    DIVID2    ; Quotient bit = 0?
  36.     SUB    C    ; Subtract divisor from extension
  37.     INX    H    ; Set least bit of quotient
  38. DIVID2:    DCR    B    ; Test loop count
  39.     JNZ    DIVID1    ; Done?
  40.     RET
  41.