-
-
Notifications
You must be signed in to change notification settings - Fork 65
Expand file tree
/
Copy pathldiv.src
More file actions
122 lines (97 loc) · 1.61 KB
/
Copy pathldiv.src
File metadata and controls
122 lines (97 loc) · 1.61 KB
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
.assume adl=1
.section .text
.global _ldiv
.type _ldiv, @function
; REMEMBER to keep ldivu.src, lremu.src, and ldiv.src in sync with this choice
.if 1
_ldiv:
pop hl
pop iy
pop de
pop bc
ld a, c
pop bc
ex (sp), hl
ex de, hl
ld d, a
xor a, e
push af
ld a, e
ld e, d
push de
bit 7, e
call __ldivs_lrems_common
call __ldivu_lremu_common
exx
ld e, a
pop af
call m, __lneg
ld (iy + 4), hl
ld (iy + 7), e
exx
pop af
call m, __lneg
ld (iy), hl
ld (iy + 3), e
ex (sp), hl
push de
push de
push de
push de
bit 2, c
jr z, .L.ei_skip
ei
.L.ei_skip:
jp (hl)
.extern __ldivu_lremu_common
.else
_ldiv:
pop hl ; return address
pop iy ; ldiv_t pointer
pop de ; [ 0:23] numerator
pop bc ; [24:31] numerator
ld a, c
pop bc ; [ 0:23] denominator
ex (sp), hl ; [24:31] denominator
ex de, hl
push ix ; preserve IX since __ldvrmu destroys it
ld d, a
xor a, e
push af ; quotient sign
ld a, e
ld e, d
push de ; remainder sign
bit 7, e
call __ldivs_lrems_common
push iy ; preserve IY since __ldvrmu destroys it
; E:UHL = numerator
; A:UBC = denominator
call __ldvrmu
; E:UIX = quotient
; A:UHL = remainder
pop iy ; restore IY = ldiv_t pointer
ld d, e ; preserve E
ld e, a
pop af ; remainder sign
; E:UHL = remainder
call m, __lneg
ld (iy + 4), hl
ld (iy + 7), e
pop af ; quotient sign
lea hl, ix + 0
pop ix ; restore IX
ld e, d ; restore E
; E:UHL = quotient
call m, __lneg
ld (iy), hl
ld (iy + 3), e
ex (sp), hl ; HL = return address
push de
push de
push de
push de
jp (hl)
.extern __ldvrmu
.endif
.extern __ldivs_lrems_common
.extern __lneg