home *** CD-ROM | disk | FTP | other *** search
-
- ;++++++++++++++++++++++++++++++++++++++++++++++
- ;
- ; UNSIGNED BINARY DIVIDE
- ;
- ; DIVIDE1.LIB - Version 0.1 - 14 SEP 77
- ;
- ; J.W. SHOOK, P.O. BOX 185, ROCKY POINT, NY 11778
- ;
- ;++++++++++++++++++++++++++++++++++++++++++++++
-
- ; Divides 16 bit dividend by 8 bit
- ; divisor producing a 16 bit quotient
- ; and an 8 bit remainder.
-
- ; CALL with:
- ; HL = Dividend
- ; C = Divisor
-
- ; RETURN with:
- ; HL = Quotient
- ; C = Divisor
- A = Remainder
- ; CARRY = Set on divide by zero
-
-
- DIVIDE: XRA A ; Clear extension of dividend reg
- CMP C ; Check if divisor = 0
- STC ; Mark divide error
- RZ ; Return on / by 0
- MVI B,16 ; Set loop counter
- DIVID1: DAD H ; Shift dividend left into
- RAL ; dividend extension reg.
- CMP C ; Extension >= divisor?
- JC DIVID2 ; Quotient bit = 0?
- SUB C ; Subtract divisor from extension
- INX H ; Set least bit of quotient
- DIVID2: DCR B ; Test loop count
- JNZ DIVID1 ; Done?
- RET
-