h24394
s 00103/00000/00000
d D 1.1 83/03/24 15:09:05 lib 1 0
c date and time created 83/03/24 15:09:05 by lib
e
u
4
U
t
T
I 1
;     INTEGER FUNCTION DIVID (DIVDND, DIVIS, REMAIN)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;                                                                      ;
;          THIS MATERIAL IS CONFIDENTIAL AND IS FURNISHED UNDER        ;
;          A WRITTEN LICENSE AGREEMENT.  IT MAY NOT BE USED,           ;
;          COPIED OR DISCLOSED TO OTHERS EXCEPT IN ACCORDANCE          ;
;          WITH THE TERMS OF THAT AGREEMENT.                           ;
;                                                                      ;
;          COPYRIGHT (C) 1982 GRAPHIC SOFTWARE SYSTEMS INC.            ;
;          ALL RIGHTS RESERVED.                                        ;
;                                                                      ;
;     FUNCTION: UNSIGNED 16-BIT DIVISION.  DIVIDE UNSIGNED 16-BIT      ;
;               DIVIDEND BY UNSIGNED 16-BIT DIVISOR TO PRODUCE         ;
;               16-BIT QUOTIENT AND 16-BIT REMAINDER                   ;
;                                                                      ;
;     INPUT PARAMETERS:                                                ;
;            DIVDND     - 16-BIT DIVIDNED                              ;
;            DIVIS      - 16-BIT DIVISOR                               ;
;                                                                      ;
;     OUTPUT PARAMETERS:                                               ;
;            DIVID = DIVDND / DIVIS                                    ;
;            REMAIN - 16-BIT REMAINDER                                 ;
;                                                                      ;
;     ROUTINES CALLED:                                                 ;
;            NONE                                                      ;
;                                                                      ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
	.8080
divid:  entry   divid
	push    b               ; save address of remainder
	mov	c,m		; get dividend in bc
	inx	h
	mov	b,m		
	xchg			; get divisor in de
	mov	e,m
	inx	h
	mov	d,m		
	lxi     h,0             ; zero out high order bits of dividend
 
; Assume 32 bit unsigned integer in HLBC is dividend
;  16 bit unsigned DE is divisor
 
        mvi     a,16            ;Loop count
	sta	count		;Save count
 
; Carry H L B C rotated left by one bit.
 
shift:
	ana	a		;Clear carry
        mov     a,c             ;Shift developing quotient
        ral
        mov     c,a
        mov     a,b
        ral
        mov     b,a
 
        mov     a,l             ;Shift dividend
        ral
        mov     l,a
        mov     a,h
        ral
        mov     h,a
 
sub:	shld	temp		;save dividend
	mov     a,l             ;Get dividend
        sub     e               ;Subtract divisor
        mov     l,a             ;Back to dividend
        mov     a,h             ;High half
        sbb     d               ; of both
        mov     h,a
 
	jc	restore		;dividend >= divisor? - No
	
	inx	b		;yes - increment quotient
	jmp	test
 
restore:
	lhld	temp
 
test:
	lda	count		;Get loop count
        dcr     a               ;Decrement loop count
        sta	count		;Save loop count
        jz      done            ;Jump when 16 bits done
 
        jmp     shift           ;Go shift in quotient bit
 
; Quotient is in BC. Remainder is in HL.  Return remainder in proper
; place and move quotient to HL for Fortran function return

done:
	xchg                    ;Move remainder to DE
	pop     h               ;Get address of remainder
	mov	m,e             ;Return low order byte of remainder
	inx	h
	mov	m,d		;Return high order byte of remainder
	mov	h,b		;Return function result
	mov	l,c
	ret
count:  ds   	1
temp:   ds	2
	end
 
E 1
