Mercurial > hg > Members > kono > nitros9-code
annotate lib/alib/ptsearch.as @ 3003:68a167bc476d
level3 makefiles: Order BOOTERS list like in level2
author | Tormod Volden <debian.tormod@gmail.com> |
---|---|
date | Sun, 26 Oct 2014 13:02:12 +0100 |
parents | 03f26e88b809 |
children |
rev | line source |
---|---|
2474 | 1 *************************************** |
2 | |
3 * Pattern Search | |
4 | |
5 * OTHER MODULES REQUIRED: COMPARE | |
6 | |
7 * ENTRY: X=start of memory to search | |
8 * U=end of memory | |
9 * Y=start of pattern | |
10 * D=size of pattern | |
11 * CASEMTCH (a global variable in COMPARE) =0 if A<>a, -1 if A=a | |
12 | |
13 * EXIT: X=address of match if found, unchanged if no match | |
14 * CC zero set if match, clear for no-match | |
15 * A,B,U,Y preserved | |
16 | |
17 | |
18 nam Pattern Search | |
19 ttl Assembler Library Module | |
20 | |
21 | |
2782
aaba193af04f
Updated code to use lwasm/lwlink
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2474
diff
changeset
|
22 section .data |
2474 | 23 |
24 pattend rmb 2 end of pattern in memory | |
25 memend rmb 2 realend-pattern size | |
26 patsize rmb 2 saved <D> | |
27 memstrt rmb 2 saved <X> | |
28 patstrt rmb 2 saved <Y> | |
29 realend rmb 2 saved <U> | |
30 | |
31 endsect | |
32 | |
2782
aaba193af04f
Updated code to use lwasm/lwlink
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2474
diff
changeset
|
33 section .text |
aaba193af04f
Updated code to use lwasm/lwlink
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2474
diff
changeset
|
34 |
aaba193af04f
Updated code to use lwasm/lwlink
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2474
diff
changeset
|
35 * set up stack frame for variables |
aaba193af04f
Updated code to use lwasm/lwlink
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2474
diff
changeset
|
36 |
2474 | 37 PTSEARCH: |
38 pshs d,x,y,u | |
39 leas -4,s room for temps | |
40 tfr u,d end of memory to check | |
41 subd patsize,s end-pattern size | |
42 std memend,s where we stop looking | |
43 ldd patstrt,s | |
44 addd patsize,s | |
45 std pattend,s | |
46 | |
47 * loop here looking for a match of the first characters | |
48 | |
49 inmatch | |
50 cmpx memend,s raeched end of memory | |
51 bhs nomatch | |
52 lda ,x+ get char from memory | |
53 ldb ,y compare to pattern | |
54 lbsr COMPARE compare them | |
55 bne inmatch keep looking for inital match | |
56 | |
57 * see if rest of pattern matches | |
58 | |
59 more | |
60 tfr x,u save pointer | |
61 leay 1,y already matched that one | |
62 | |
63 more1 | |
64 cmpy pattend,s all chars matched, go home happy | |
65 beq match | |
66 lda ,x+ | |
67 ldb ,y+ | |
68 lbsr COMPARE | |
69 beq more1 keep matching | |
70 tfr u,x match fails, backup and do more | |
71 ldy patstrt,s start of pattern | |
72 bra inmatch | |
73 | |
74 | |
75 nomatch | |
76 lda #1 clear zero | |
77 bra exit | |
78 | |
79 match | |
80 leau -1,u start of match | |
81 stu memstrt,s where pattern starts | |
82 clra set zero flag=found | |
83 | |
84 exit | |
85 leas 4,s clean stack | |
86 puls d,x,y,u,pc | |
87 | |
88 endsect | |
89 | |
2782
aaba193af04f
Updated code to use lwasm/lwlink
Boisy Pitre <boisy.pitre@nuance.com>
parents:
2474
diff
changeset
|
90 |