Mercurial > hg > Applications > Tokio
comparison Examples/6502/a.s65 @ 0:cfb7c6b24319
Initial revision
author | kono |
---|---|
date | Thu, 30 Aug 2007 14:57:44 +0900 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:cfb7c6b24319 |
---|---|
1 ;; | |
2 ;; ackerman function | |
3 | |
4 ;; procedure name ACK | |
5 ;; ACK(X,Y) | |
6 ;; == if X=0 then Y+1 | |
7 ;; else if Y=0 then ACK(X-1,1) | |
8 ;; else ACK(X-1, ACK(X,Y-1)) | |
9 | |
10 ;; calling sequence | |
11 ;; | |
12 ;; X on x | |
13 ;; Y on y | |
14 ;; non compile 11.86 sec on Sun 140 | |
15 ;; compile 7.54 sec on Sun 140 | |
16 | |
17 start cld | |
18 ldx #1 | |
19 ldy #1 | |
20 jsr ack | |
21 brk | |
22 | |
23 ack cpx #0 | |
24 bne xneqzero | |
25 xeqzero iny | |
26 tya | |
27 rts | |
28 | |
29 xneqzero cpy #0 | |
30 bne yneqzero | |
31 dex ;; x <- x-1 | |
32 yeqzero ldy #1 | |
33 jmp ack ;; tail recursion | |
34 | |
35 yneqzero txa | |
36 pha | |
37 dey ;; y <- y-1 | |
38 jsr ack ;; ack x,y-1 | |
39 tay | |
40 pla | |
41 tax | |
42 dex ;; x <- x-1 | |
43 jmp ack ;; tail recursion | |
44 | |
45 end | |
46 ;; |