|
|
1.1 root 1: ////////
2: /
3: / Intel 8086 C runtime.
4: / SMALL model.
5: /
6: ////////
7:
8: .globl vldiv
9: .globl vrdiv
10:
11: ////////
12: /
13: / unsigned long
14: / vrdiv(a, b);
15: / unsigned long a;
16: / unsigned long b;
17: /
18: / unsigned long
19: / vldiv(a, p);
20: / unsigned long a;
21: / unsigned long *p;
22: /
23: / these two routines perform 32 bit unsigned divide.
24: / they are called by the compiler when a user program performs an
25: / unsigned long division, and are called by the library routines
26: / that perform long division.
27: /
28: ////////
29:
30: alow = 8
31: ahigh = 10
32: blow = 0
33: bhigh = 2
34:
35: vldiv: mov ax,bx / save bx.
36: mov bx,sp / point bx at
37: mov bx,6(bx) / the operand and
38: jmp L0 / go to common end.
39:
40: vrdiv: mov ax,bx / save bx.
41: mov bx,sp / point bx at
42: lea bx,6(bx) / the operand.
43:
44: L0: push si / standard
45: push di / c
46: push bp / function
47: mov bp,sp / linkage.
48:
49: push ax / save saved bx.
50: mov dx,ahigh(bp) / pick up
51: mov ax,alow(bp) / dividend.
52: sub si,si / clear out the
53: sub di,di / the upper half of the mq.
54:
55: mov cx,$32 / step count.
56:
57: L1: shl ax,$1 / shift
58: rcl dx,$1 / one
59: rcl di,$1 / bit
60: rcl si,$1 / left.
61:
62: cmp si,bhigh(bx) / does it go in ??
63: jb L3 / nope.
64: ja L2 / yes.
65: cmp di,blow(bx) / maybe ??
66: jb L3 / nope.
67:
68: L2: sub di,blow(bx) / subtract the
69: sbb si,bhigh(bx) / divisor and poke a 1 bit
70: inc ax / into the quotient.
71:
72: L3: loop L1 / do this 32 times.
73:
74: pop bx / restore saved bx.
75: mov sp,bp / standard
76: pop bp / c
77: pop di / function
78: pop si / linkage.
79: ret / done.
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.