SHOW:
|
|
- or go back to the newest paste.
1 | ;+17 bytes -150.5cc | |
2 | ;=============================================================== | |
3 | BC_Div_DE: | |
4 | ;=============================================================== | |
5 | - | ;Speed: 1150+6b cycles when DE<256 (1/256 of the time) |
5 | + | |
6 | - | ; 688+6b cycles when DE>=256 (255/256 of the time) |
6 | + | ;Speed: 890+6b+a cycles when DE<256 (1/256 of the time) |
7 | - | ; Avg = 716.88671875cc |
7 | + | ; 541+6b cycles when DE>=256 (255/256 of the time) |
8 | - | ;Size: 35 bytes |
8 | + | ; Avg = 566.37890625cc |
9 | ;Size: 52 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 b,16 |
22 | + | |
23 | inc d | |
24 | dec d | |
25 | - | jr z,loop |
25 | + | jr z,upper |
26 | ld l,a | |
27 | ld a,c | |
28 | ld c,h | |
29 | lower: | |
30 | ld b,8 | |
31 | loop: | |
32 | rla | |
33 | adc hl,hl | |
34 | sbc hl,de | |
35 | jr nc,$+3 | |
36 | add hl,de | |
37 | djnz loop | |
38 | ld b,c | |
39 | rla | |
40 | - | ld b,a |
40 | + | |
41 | ld c,a | |
42 | ret | |
43 | upper: | |
44 | - | ret |
44 | + | |
45 | ld a,h | |
46 | loop_upper: | |
47 | rl c | |
48 | rla | |
49 | sub e | |
50 | jr nc,$+3 | |
51 | add a,e | |
52 | djnz loop_upper | |
53 | ld l,a | |
54 | ld a,c | |
55 | rla | |
56 | cpl | |
57 | ld c,a | |
58 | jp lower |