SX Microcontroller Math Method

24 BIT DIVISION

From: Tony Nixon


;       ------------------------------------------
; SUBROUTINE - 24 BIT DIVISION
; numerator:        nratorH  nratorM  nratorL
; denominator:      denomH   denomM   denomL
;
; result:           nratorH  nratorM  nratorL
; remainder:        remainH  remainM  remainL
;
; 54 instructions about 974 cycles
divizn	mov	W, #24
	mov	BCount, W
	mov	W, nratorH
	mov	shiftH, W
	mov	W, nratorM
	mov	shiftM, W
	mov	W, nratorL
	mov	shiftL, W
	clr	nratorH
	clr	nratorM
	clr	nratorL
	;
	clr	remainH
	clr	remainM
	clr	remainL
dloop	clrb	C
	rl	shiftL
	rl	shiftM
	rl	shiftH
	rl	remainL
	rl	remainM
	rl	remainH
	mov	W, denomH
	mov	W, remainH-w
	sb	Z
	jmp	nochk
	;
	mov	W, denomM
	mov	W, remainM-w
	sb	Z
	jmp	nochk
	;
	mov	W, denomL
	mov	W, remainL-w
nochk	sb	C
	jmp	nogo
	;
	mov	W, denomL
	sub	remainL, W
	sb	C
	dec	remainM
	mov	W, remainM
	xor	W, #$ff
	snb	Z
	dec	remainH
	mov	W, denomM
	sub	remainM, W
	sb	C
	dec	remainH
	mov	W, denomH
	sub	remainH, W
	setb	C
nogo	rl	nratorL
	rl	nratorM
	rl	nratorH
	decsz	BCount
	jmp	dloop
	;
	ret