2474
|
1 *********************************
|
|
2 * 8 x 8 Divide
|
|
3
|
|
4 * OTHER MODULES NEEDED: none
|
|
5
|
|
6 * ENTRY: A = divisor
|
|
7 * B = dividend
|
|
8
|
|
9 * EXIT: A = remainder
|
|
10 * B = quotient
|
|
11
|
|
12 nam 8x8 bit Divide
|
|
13 ttl Assembler Library Module
|
|
14
|
|
15
|
|
16 psect DIV88,0,0,0,0,0
|
|
17
|
|
18 vsect
|
|
19 negcount rmb 1
|
|
20 endsect
|
|
21
|
|
22 * Signed Divide
|
|
23 SDIV88:
|
|
24 clr negcount,u
|
|
25 PSHS D
|
|
26 tst ,s
|
|
27 bpl testquo
|
|
28 lda ,s
|
|
29 coma
|
|
30 inca
|
|
31 sta ,s
|
|
32 inc negcount,u
|
|
33 testquo
|
|
34 tst 1,s
|
|
35 bpl ok
|
|
36 ldd 1,s
|
|
37 coma
|
|
38 adda #$01
|
|
39 std 1,s
|
|
40 inc negcount,u
|
|
41 ok
|
|
42 puls d
|
|
43 bsr DIV88
|
|
44 dec negcount,u
|
|
45 bne goforit
|
|
46 pshs d
|
|
47 lda ,s
|
|
48 coma
|
|
49 inca
|
|
50 sta ,s
|
|
51 lda 1,s
|
|
52 coma
|
|
53 inca
|
|
54 sta 1,s
|
|
55 puls d
|
|
56 goforit
|
|
57 rts
|
|
58
|
|
59
|
|
60 DIV88:
|
|
61 PSHS A save divisor
|
|
62 LDA #8 bit counter
|
|
63 PSHS A
|
|
64 CLRA initialize remainder
|
|
65
|
|
66 div1
|
|
67 ASLB shift dividend & quotient
|
|
68 ROLA
|
|
69 CMPA 1,S trial subtraction needed
|
|
70 BLO div2
|
|
71 SUBA 1,S
|
|
72 INCB
|
|
73
|
|
74 div2
|
|
75 DEC 0,S count down # of bits
|
|
76 BNE div1
|
|
77 LEAS 2,S clean up stack
|
|
78 RTS
|
|
79
|
|
80 endsect
|
|
81
|