repo.or.cz
/
urasm.git
/
blob
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
log
|
graphiclog1
|
graphiclog2
|
commit
|
commitdiff
|
tree
|
refs
|
edit
|
fork
blame
|
history
|
raw
|
HEAD
urasmlib: cosmetix
[urasm.git]
/
libs
/
muldiv_slow.inc
blob
a62a621be45bdea747a680691ca4194e46cce63b
1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;; unsigned multiply
3
;; IN:
4
;; HL: num0
5
;; DE: num1
6
;; OUT:
7
;; HL: high part
8
;; DE: low part
9
;; BC: dead
10
;; AF: dead
11
UMul1616_32:
12
ld b,h
13
ld a,l
14
call .mulsub
15
push hl
16
ld h,a
17
ld a,b
18
ld b,h
19
call .mulsub
20
pop de
21
ld c,d
22
add hl,bc
23
adc a,0
24
ld d,l
25
ld l,h
26
ld h,a
27
ret
28
29
.mulsub:
30
ld hl,0
31
ld c,8
32
.next:
33
add hl,hl
34
rla
35
jr nc,.skip
36
add hl,de
37
adc a,0
38
.skip:
39
dec c
40
jr nz,.next
41
ret
42
43
44
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
45
;; unsigned division
46
;; IN:
47
;; HL: high part
48
;; DE: low part
49
;; BC: divisor
50
;; OUT:
51
;; DE: res
52
;; HL: mod
53
;; BC: dead
54
;; AF: dead
55
UDiv3216_16:
56
ld a,l
57
sub a,c
58
ld a,h
59
sbc a,b
60
jr c,.noerror
61
; error
62
ld hl,0
63
ld de,hl
64
ret
65
.noerror:
66
ld a,16
67
.loop:
68
add hl,hl
69
rla
70
ex de,hl
71
add hl,hl
72
jr nc,.nodo0
73
inc de
74
and a,a
75
.nodo0:
76
ex de,hl
77
rra
78
push af
79
jr nc,.nodo1
80
and a,l
81
sbc hl,bc
82
jr .next
83
.nodo1:
84
and a,a
85
sbc hl,bc
86
jr nc,.next
87
add hl,bc
88
dec de
89
.next:
90
inc de
91
pop af
92
dec a
93
jr nz,.loop
94
ret