campo-sirio/gfm/dmby1.asm
alex ba237a9d91 Patch level : no patch
Files correlati     :
Ricompilazione Demo : [ ]
Commento            :
Aggiunti i sorgenti per Greenleaf Math Library (gfm.dll)


git-svn-id: svn://10.65.10.50/trunk@10079 c028cbd2-c16b-5b4b-a496-9718f37d4682
2002-02-26 12:19:02 +00:00

102 lines
3.0 KiB
NASM
Executable File

; int _DivUnsArrByUns(a, c, n)
;
; ARGUMENT
; unsigned a[] n-word number to divide
; unsigned c number of divide by
; int n number of digits
;
; DESCRIPTION
; Divides n-digit number c by b, storing result in c.
; The (positive) remainder is calculated and returned.
;
; SIDE EFFECTS
; None.
;
; RETURNS
; Remainder.
;
; AUTHOR
; Jared Levy 7/9/89
; Copyright (C) 1989-90 Greenleaf Software Inc. All Rights Reserved.
;
; MODIFICATIONS
;
;
;
include model.h
include prologue.h
include gm.equ
pseg dmby1
cproc _DivUnsArrByUns,,_dmby1
; load parameters
if _LDATA
push es
les di, parm1_ ; get pointer to source & destination
mov cx, parm3_ ; get number to divide by
mov bx, parm4_ ; get number of digits
else
mov di, parm1_ ; get pointer to source & destination
mov ax, ds
mov es, ax
mov cx, parm2_ ; get number to divide by
mov bx, parm3_ ; get number of digits
endif
call near ptr dmby1a
if _LDATA
pop es
endif
cproce
; the computation routine is separate so it may be called from assembly
dmby1a:
dec bx ; digits go from 0 to n-1
sal bx, 1 ; want bytes rather than words
;/* skip initial zeroes */
; for(;(q>0)&&(c[q-1]==0);q--);
;
; if (q == 0)
; return(0);
; q--; /* q will be used for subscript */
zeroloop:
mov ax, word ptr es:[di+bx] ; get digit
cmp ax, 0 ; is digit zero?
jne nonzero ; if non-zero, begin divide
dec bx ; next word
dec bx
cmp bx, 0 ; last digit?
jge zeroloop ; if not, process next digit
xor ax, ax ; otherwise, remainder 0
jmp short exit1 ; && division through (0/c=0)
; bl = (unsigned long) b;
; while (q>=0) {
; k = (unsigned long *) &r[q];
; cl = *k / bl;
; c[q] = (unsigned) cl;
; r[q] = (unsigned) (*k - cl * bl);
; q--;
; }
nonzero:
xor dx,dx ; high word zero in first divide
divloop:
div cx ; divide digit
mov word ptr es:[di+bx], ax ; store quotient digit
cmp bx, 0 ; last digit?
je exit2 ; if so, division complete
dec bx ; next digit
dec bx
mov ax, word ptr es:[di+bx] ; get digit
jmp short divloop ; process digit
exit2:
mov ax, dx ; return remainder
exit1:
ret
endps
end