OSDN Git Service

V205; added MSP-EXP430FR2355.
[fast-forth/master.git] / MSP430-FORTH / TESTASM.F
1 \ -----------------------------------------------------------------------
2 \ File Name TestASM.f
3 \ -----------------------------------------------------------------------
4
5 \ TARGET SELECTION
6 \ MSP_EXP430FR5739  MSP_EXP430FR5969    MSP_EXP430FR5994    MSP_EXP430FR6989
7 \ MSP_EXP430FR4133  MSP_EXP430FR2433    MSP_EXP430FR2355    CHIPSTICK_FR2433
8
9
10 \ -----------------------------------------------------------------------
11 \ test CPUx instructions PUSHM, POPM, RLAM, RRAM, RRCM, RRUM
12 \ -----------------------------------------------------------------------
13 CODE TESTPUSHM
14             MOV     #22222,Y
15             MOV     #3,X
16             MOV     #2,W
17             MOV     #1,T
18             MOV     #0,S
19 \            PUSHM   Y,IP       \ uncomment to test error (registers bad order) 
20             PUSHM   IP,W        \ PUSHM order : PSP,TOS,IP,S,T,W,X,Y,rEXIT,rDOVAR,rDOCON,rDODOES
21             POPM    W,IP        \ POPM order  : rDODOES,rDOCON,rDOVAR,rEXIT,Y,X,W,T,S,IP,TOS,PSP
22             SUB     #10,PSP
23             MOV     TOS,8(PSP)  \ save old TOS
24             MOV     S,6(PSP)
25             MOV     T,4(PSP)
26             MOV     W,2(PSP)
27             MOV     X,0(PSP)
28             MOV     Y,TOS
29 \            RLAM    #0,TOS     \ uncomment to test error (bad shift value)
30             RRAM    #1,TOS      \ 0 < shift value < 5
31             RLAM    #2,TOS
32             RRCM    #1,TOS
33             RRUM    #1,TOS
34             COLON               \ high level part of the word starts here...
35             space . . . . .
36             ;                   \ and finishes here.
37     \
38 TESTPUSHM  ; you should see 11111 3 2 1 0 -->
39
40 CODE TESTPOPM
41             MOV     #22222,Y
42             MOV     #3,X
43             MOV     #2,W
44             MOV     #1,T
45             MOV     #0,S
46 \            PUSHM   W,IP        \ uncomment to test error "out of bounds" 
47             PUSHM   IP,W        \ PUSHM order : PSP,TOS,IP,S,T,W,X,Y,rEXIT,rDOVAR,rDOCON,rDODOES
48             POPM    W,IP        \ POPM order  : rDODOES,rDOCON,rDOVAR,rEXIT,Y,X,W,T,S,IP,TOS,PSP
49             SUB     #10,PSP
50             MOV     TOS,8(PSP)  \ save old TOS
51             MOV     S,6(PSP)
52             MOV     T,4(PSP)
53             MOV     W,2(PSP)
54             MOV     X,0(PSP)
55             MOV     Y,TOS
56 \            RLAM    #0,TOS      \ uncomment to test error "out of bounds" 
57 \            RLAM    #5,TOS      \ uncomment to test error "out of bounds" 
58             RRAM    #1,TOS      \ 0 < shift value < 5
59             RLAM    #2,TOS
60             RRCM    #1,TOS
61             RRUM    #1,TOS
62             COLON               \ high level part of the word starts here...
63             space . . . . .
64             ;                   \ and finishes here.
65     \
66 TESTPOPM  ; you should see 11111 3 2 1 0 -->
67
68
69
70 \ -----------------------------------------------------------------------
71 \ test symbolic branch in assembler
72 \ test a FORTH section encapsulated in an assembly word
73 \ -----------------------------------------------------------------------
74 CODE TEST1                  \ the word "CODE" add ASSEMBLER as CONTEXT vocabulary...
75
76             MOV &BASE,&BASE \ to test &xxxx src operand
77             CMP #%10,&BASE
78 0<> IF      MOV #2,&BASE    \ if base <> 2
79 ELSE        MOV #$0A,&BASE  \ else base = 2
80 THEN        
81             COLON           \ tips : no "ok" displayed in start of line <==> compilation mode
82             BASE @ U.       \ always display 10 !
83             ;
84     \
85
86 \ -----------------------------------------------------------------------
87 \ test a word that starts as word FORTH and ends as assembly word
88 \ -----------------------------------------------------------------------
89 : TEST2                     \ ":" starts compilation
90             BASE @ U.       \ always display 10 !
91             HI2LO           \ switch FORTH to ASM : compile one word (next address)
92                             \                       add vocabulary ASSEMBLER as CONTEXT vocabulary
93                             \                       switch in interpret mode
94             CMP #2, &BASE
95 0<> IF      MOV #2, &BASE   \ if variable system BASE <> 2
96 ELSE        MOV #10,&BASE   \ else (BASE = 2)
97 THEN
98 \           MOV #EXIT,PC    \ to pair with ":" i.e. to restore IP saved by : then execute NEXT. 
99 \ but even compile two words, it's better to compile an inline EXIT :
100             MOV @RSP+,IP    \ restore IP
101             MOV @IP+,PC     \ = NEXT
102 ENDCODE                     \ ends assembler : remove vocabulary ASSEMBLER from CONTEXT
103     \
104
105 \ -----------------------------------------------------------------------
106 \ test a word that starts as assembly word and ends as FORTH word
107 \ -----------------------------------------------------------------------
108 CODE TEST3                  \ "CODE" starts assembler, i.e. add ASSEMBLER as CONTEXT vocabulary
109             CMP #2, &BASE
110 0<> IF      MOV #2, &BASE   \ if variable system BASE <> 2
111 ELSE        MOV #10,&BASE   \ else (BASE = 2)
112 THEN        COLON           \
113             BASE @  U.      \ always display 10 !
114 ;                           \
115     \
116
117
118 \ -----------------------------------------------------------------------
119 \ test an assembly jump spanning a section written in FORTH
120 \ -----------------------------------------------------------------------
121 : TEST5
122             SPACE
123             HI2LO
124             SUB #2,PSP
125             MOV TOS,0(PSP)
126             MOV #%1010,TOS  \ init count = 10
127 BEGIN       SUB #$0001,TOS
128             LO2HI
129                             \ IP is already saved by word ":"
130             DUP U.          \ display count
131             HI2LO
132             CMP #0,TOS
133 0= UNTIL    MOV @PSP+,TOS
134 \           MOV #EXIT,PC    \ to pair with ":" i.e. to restore IP saved by : then execute NEXT. 
135             MOV @RSP+,IP    \ restore IP
136             MOV @IP+,PC     \ = NEXT
137 ENDCODE
138     \
139 TEST5  ; you should see :  9 8 7 6 5 4 3 2 1 0 -->
140     \
141
142 \ -----------------------------------------------------------------------
143 \ tests indexing address
144 \ -----------------------------------------------------------------------
145
146 : BYTES_TABLE_IDX
147 CREATE 
148 0 DO I C,
149 LOOP
150 DOES>
151 +
152 ;
153
154 8 BYTES_TABLE_IDX BYTES_TABLE \ create table "BYTES_TABLE" with bytes content = 0,1,2,3,4,5,6,7
155     \
156 2 BYTES_TABLE C@ . ; you should see 2 -->
157 \
158
159
160 VARIABLE BYTES_TABLE1
161
162 $0201 BYTES_TABLE1 !              \ words written in memory are little endian !
163
164 CODE IDX_TEST1                     \ index -- value
165     MOV.B   BYTES_TABLE1(TOS),TOS  \ -- value
166 COLON
167     U. 
168 ;      
169
170 0 IDX_TEST1     ; you should see 1 -->
171
172 CODE TEST6
173             MOV 0(PSP),0(PSP)  \
174             MOV @IP+,PC
175 ENDCODE
176
177
178 1 TEST6 .       ; you should see 1 -->
179
180
181 \ -----------------------------------------------------------------------
182 \ tests behaviour of assembly error 
183 \ -----------------------------------------------------------------------
184 \ R16 causes an error, assembler context is aborted and the word TEST7 is "hidden".
185
186 \ CODE TEST7
187 \            MOV 0(PSP),0(R16)  ; display an error "out of bounds" -->
188
189
190 \ -----------------------------------------------------------------------
191 \ tests access to a CREATED word with assembler 
192 \ -----------------------------------------------------------------------
193
194
195     \
196 CREATE TABLE0
197 0 C,
198 1 C,
199 2 C,
200 3 C,
201     \
202
203 CREATE TABLE10
204 $10 C,
205 $11 C,
206 $12 C,
207 $13 C,
208
209     \
210
211 CREATE TABLE20
212 $20 C,
213 $21 C,
214 $22 C,
215 $23 C,
216     \
217
218 CREATE TABLE
219
220
221 TABLE 2 - CONSTANT PFA_TABLE      \ PFA_TABLE leave the PFA of TABLE
222
223
224 CODE REDIRECT       ; <table> --    redirects TABLE to argument <table>    
225 MOV TOS,&PFA_TABLE
226 MOV @PSP+,TOS
227 MOV @IP+,PC
228 ENDCODE
229     \
230
231 CODE REDIRECT0      ; --            redirects TABLE to TABLE0        
232 MOV #TABLE0,&PFA_TABLE
233 MOV @IP+,PC
234 ENDCODE
235     \
236
237 CODE REDIRECT10     ; --            redirects TABLE to TABLE10        
238 MOV #TABLE10,&PFA_TABLE
239 MOV @IP+,PC
240 ENDCODE
241     \
242
243 CODE REDIRECT20     ; --            redirects TABLE to TABLE20        
244 MOV #TABLE20,&PFA_TABLE
245 MOV @IP+,PC
246 ENDCODE
247     \
248
249 ' TABLE0 10 DUMP
250     \
251 ' TABLE10 10 DUMP
252     \
253 ' TABLE20 10 DUMP
254     \
255     \
256 TABLE0 REDIRECT TABLE 10 DUMP
257     \
258 TABLE10 REDIRECT TABLE 10 DUMP
259     \
260 TABLE20 REDIRECT TABLE 10 DUMP
261     \
262     \
263 REDIRECT0 TABLE 10 DUMP
264     \
265 REDIRECT10 TABLE 10 DUMP
266     \
267 REDIRECT20 TABLE 10 DUMP
268     \
269
270 TABLE0 PFA_TABLE ! TABLE 10 DUMP
271     \
272 TABLE10 PFA_TABLE ! TABLE 10 DUMP
273     \
274 TABLE20 PFA_TABLE ! TABLE 10 DUMP
275     \
276