View difference between Paste ID: wmpEstKv and YdqDPv9p
SHOW: | | - or go back to the newest paste.
1-
;+17 bytes -150.5cc
1+
;+92 bytes, -110cc
2
;===============================================================
3
BC_Div_DE:
4
;===============================================================
5
;Performs BC/DE
6-
;Speed:   890+6b+a cycles when DE<256 (1/256 of the time)
6+
;Speed:   674+6b+a cycles when DE<256 (1/256 of the time)
7-
;         541+6b cycles when DE>=256 (255/256 of the time)
7+
;         431+6b cycles when DE>=256 (255/256 of the time)
8-
;         Avg = 566.37890625cc
8+
;         Avg = 455.96484375cc
9-
;Size:    52 bytes
9+
;Size:    144 bytes
10
;Inputs:
11
;     BC is the numerator
12
;     DE is the denominator
13
;Outputs:
14
;     BC is the quotient
15
;     HL is the remainder
16
;     DE is not changed
17
;     A is 0
18
;     z flag is set
19
;     c flag is reset
20
;===============================================================
21
    ld hl,0
22
    ld a,b
23
    inc d
24
    dec d
25
    jr z,upper
26
    ld l,a
27
    ld a,c
28-
    ld c,h
28+
    ld b,h
29
lower:
30-
    ld b,8
30+
;-110cc
31-
loop:
31+
    rla \ adc hl,hl \ sbc hl,de \ jr nc,$+3 \ add hl,de
32
    rla \ adc hl,hl \ sbc hl,de \ jr nc,$+3 \ add hl,de
33-
    adc hl,hl
33+
    rla \ adc hl,hl \ sbc hl,de \ jr nc,$+3 \ add hl,de
34-
    sbc hl,de
34+
    rla \ adc hl,hl \ sbc hl,de \ jr nc,$+3 \ add hl,de
35-
    jr nc,$+3
35+
    rla \ adc hl,hl \ sbc hl,de \ jr nc,$+3 \ add hl,de
36-
    add hl,de
36+
    rla \ adc hl,hl \ sbc hl,de \ jr nc,$+3 \ add hl,de
37-
    djnz loop
37+
    rla \ adc hl,hl \ sbc hl,de \ jr nc,$+3 \ add hl,de
38-
    ld b,c
38+
    rla \ adc hl,hl \ sbc hl,de \ jr nc,$+3 \ add hl,de
39
    rla
40
    cpl
41
    ld c,a
42
    ret
43
upper:
44-
    ld b,8
44+
;-106
45
    ld a,h
46
loop_upper:
47-
    rl c
47+
    rl c \ rla \ sub e \ jr nc,$+3 \ add a,e
48
    rl c \ rla \ sub e \ jr nc,$+3 \ add a,e
49-
    sub e
49+
    rl c \ rla \ sub e \ jr nc,$+3 \ add a,e
50-
    jr nc,$+3
50+
    rl c \ rla \ sub e \ jr nc,$+3 \ add a,e
51-
    add a,e
51+
    rl c \ rla \ sub e \ jr nc,$+3 \ add a,e
52-
    djnz loop_upper
52+
    rl c \ rla \ sub e \ jr nc,$+3 \ add a,e
53
    rl c \ rla \ sub e \ jr nc,$+3 \ add a,e
54
    rl c \ rla \ sub e \ jr nc,$+3 \ add a,e
55
    ld l,a
56
    ld a,c
57
    rla
58
    cpl
59
    ld b,a
60
    jp lower