57
|
1 ;print value as decimal
|
|
2
|
|
3 org $100
|
|
4
|
|
5 ldx #$ff00
|
|
6 loop:
|
|
7 bsr printdec
|
|
8 ldb #32
|
|
9 swi2
|
|
10 leax 1,x
|
|
11 bne loop
|
|
12 sync
|
|
13
|
|
14
|
|
15 printdec:
|
|
16 pshs cc,d,x ; save regs
|
|
17 lda #$80 ; init. terminator
|
|
18 nxtdg:
|
|
19 sta ,-s ; push digit term
|
|
20 ldb #16 ; 16 bit counter for rotate
|
|
21 clra ; clear accu and carry
|
|
22 roll:
|
|
23 rola ; divide by 10 using binary
|
|
24 adda #$f6 ; long division, shifting X one
|
|
25 bcs sub ; bit at a time info A and
|
|
26 suba #$f6 ; subtracting 10 which sets
|
|
27 sub:
|
|
28 exg d,x ; C if sub goes, else add 10
|
|
29 rolb ; back and reset C. Rotating X
|
|
30 rola ; by means of A & B both shifts
|
|
31 exg d,x ; X bits into A and shifts
|
|
32 decb ; result bits into X. Do 17
|
|
33 bpl roll ; times to get last result bit.
|
|
34 leax ,x ; test X and repeat if
|
|
35 bne nxtdg ; X is not zero
|
|
36 tfr a,b
|
|
37 prog:
|
|
38 orb #$30 ; make into ASCII digit, call
|
|
39 swi2 ; print char
|
|
40 ldb ,s+ ; pull next digit of stack and
|
|
41 bpl prog ; repeat if not terminator
|
|
42 puls cc,d,x,pc ; restore regs and return
|
|
43
|
|
44
|
|
45 end
|
|
46
|