1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
; Copyright (C) 1999-2008 Zilog, Inc, All Rights Reserved
;-------------------------------------------------------------------------
; ldiv function
;
; ldiv_t ldiv(long numer, long denom);
;
;-------------------------------------------------------------------------
.def _ldiv
.ref __ldivs
.ref __lrems
.assume adl=1
_ldiv:
push bc
push af
push de
push hl
ld hl,27
add hl,sp
ld a,(hl)
dec hl
dec hl
dec hl
ld bc,(hl) ; aBC : denominator
dec hl
dec hl
dec hl
ld e,(hl)
dec hl
dec hl
dec hl
ld hl,(hl) ; eHL: Numerator
call __ldivs
push de
push hl ; eHL : quotient
ld hl,27
add hl,sp
ld e,(hl)
dec hl
dec hl
dec hl
ld hl,(hl)
call __lrems
ld a,e
ex de,hl ;aDE :remainder
ld hl,21
add hl,sp
ld hl,(hl)
push hl
ld bc, 7
add hl, bc
ld (hl),a
dec hl
dec hl
dec hl
ld (hl),de ; aDE : remainder
pop hl
pop bc
ld (hl),bc ; bc : 3 LSB of quotient
pop bc
push hl
inc hl
inc hl
inc hl
ld (hl),c ; c : MSB of quotient
pop hl
pop de
pop de
pop af
pop bc
ret
|