OSDN Git Service

V300, la Der de Der
[fast-forth/master.git] / MSP430-FORTH / TESTASM.F
1 \ -*- coding: utf-8 -*-
2
3 ; -----------------------------------------------------------------------
4 ; TEST_ASM.f
5 ; -----------------------------------------------------------------------
6 \
7 \ TARGET SELECTION
8 \ MSP_EXP430FR5739  MSP_EXP430FR5969    MSP_EXP430FR5994    MSP_EXP430FR6989
9 \ MSP_EXP430FR4133  MSP_EXP430FR2433    MSP_EXP430FR2355    CHIPSTICK_FR2433
10 \
11 \ PUSHM order : PSP,TOS, IP,  S,  T,  W,  X,  Y, rEXIT,rDOVAR,rDOCON, rDODOES, R3, SR,RSP, PC
12 \ PUSHM order : R15,R14,R13,R12,R11,R10, R9, R8,  R7  ,  R6  ,  R5  ,   R4   , R3, R2, R1, R0
13 \
14 \ example : PUSHM #6,IP pushes IP,S,T,W,X,Y registers to return stack
15 \
16 \ POPM  order :  PC,RSP, SR, R3, rDODOES,rDOCON,rDOVAR,rEXIT,  Y,  X,  W,  T,  S, IP,TOS,PSP
17 \ POPM  order :  R0, R1, R2, R3,   R4   ,  R5  ,  R6  ,  R7 , R8, R9,R10,R11,R12,R13,R14,R15
18 \
19 \ example : POPM #6,IP   pop Y,X,W,T,S,IP registers from return stack
20 \
21 \ ASSEMBLER conditionnal usage after IF UNTIL WHILE : S< S>= U< U>= 0= 0<> 0>=
22 \ ASSEMBLER conditionnal usage before ?JMP ?GOTO    : S< S>= U< U>= 0= 0<> 0< 
23 \
24 \ FORTH conditionnal    : 0= 0< = < > U<
25
26 \ -----------------------------------------------------------------------
27 \ test CPUx instructions PUSHM, POPM, RLAM, RRAM, RRCM, RRUM
28 \ -----------------------------------------------------------------------
29 CODE TESTPUSHM
30 \            PUSHM  #16,R14     \ uncomment to test error "out of bounds"
31 \            PUSHM  #2,R0       \ uncomment to test error "out of bounds"
32 \            PUSHM  #0,IP       \ uncomment to test error "out of bounds"
33 \            POPM   #17,R15     \ uncomment to test error "out of bounds"
34 \            POPM   #2,R0       \ uncomment to test error "out of bounds"
35 \            POPM   #0,IP       \ uncomment to test error "out of bounds"
36             MOV     #22222,Y
37             MOV     #3,X
38             MOV     #2,W
39             MOV     #1,T
40             MOV     #0,S
41
42             PUSHM   #4,IP       \ PUSHM IP,S,T,W
43             POPM    #4,IP       \ POPM  W,T,S,IP
44             SUB     #10,PSP
45             MOV     TOS,8(PSP)  \ save old TOS
46             MOV     S,6(PSP)
47             MOV     T,4(PSP)
48             MOV     W,2(PSP)
49             MOV     X,0(PSP)
50             MOV     Y,TOS
51 \            RLAM    #0,TOS      \ uncomment to test error "out of bounds" 
52 \            RLAM    #5,TOS      \ uncomment to test error "out of bounds" 
53             RRAM    #1,TOS      \ 0 < shift value < 5
54             RLAM    #2,TOS
55             RRCM    #1,TOS
56             RRUM    #1,TOS
57             COLON               \ high level part of the word starts here...
58             space . . . . .
59             ;                   \ and finishes here.
60     \
61 TESTPUSHM  ; you should see 11111 3 2 1 0 -->
62
63 CODE TESTPOPM
64             JMP TESTPUSHM
65 ENDCODE
66
67     \
68 TESTPOPM  ; you should see 11111 3 2 1 0 -->
69
70
71
72 \ -----------------------------------------------------------------------
73 \ test symbolic branch in assembler
74 \ test a FORTH section encapsulated in an assembly word
75 \ -----------------------------------------------------------------------
76 CODE TEST1                  \ the word "CODE" add ASSEMBLER as CONTEXT vocabulary...
77
78             MOV &BASE,&BASE \ to test &xxxx src operand
79             CMP #%10,&BASE
80 0<> IF      MOV #2,&BASE    \ if base <> 2
81 ELSE        MOV #$0A,&BASE  \ else base = 2
82 THEN        
83             COLON           \ tips : no "ok" displayed in start of line <==> compilation mode
84             BASE @ U.       \ always display 10 !
85             ;
86     \
87
88 \ -----------------------------------------------------------------------
89 \ test a word that starts as word FORTH and ends as assembly word
90 \ -----------------------------------------------------------------------
91 : TEST2                     \ ":" starts compilation
92             BASE @ U.       \ always display 10 !
93             HI2LO           \ switch FORTH to ASM : compile one word (next address)
94                             \                       add vocabulary ASSEMBLER as CONTEXT vocabulary
95                             \                       switch in interpret mode
96             CMP #2, &BASE
97 0<> IF      MOV #2, &BASE   \ if variable system BASE <> 2
98 ELSE        MOV #10,&BASE   \ else (BASE = 2)
99 THEN
100 \           MOV #EXIT,PC    \ to pair with ":" i.e. to restore IP saved by : then execute NEXT. 
101 \ but even compile two words, it's better to compile an inline EXIT :
102             MOV @RSP+,IP    \ restore IP
103             MOV @IP+,PC     \ = NEXT
104 ENDCODE                     \ ends assembler : remove vocabulary ASSEMBLER from CONTEXT
105     \
106
107 \ -----------------------------------------------------------------------
108 \ test a word that starts as assembly word and ends as FORTH word
109 \ -----------------------------------------------------------------------
110 CODE TEST3                  \ "CODE" starts assembler, i.e. add ASSEMBLER as CONTEXT vocabulary
111             CMP #2, &BASE
112 0<> IF      MOV #2, &BASE   \ if variable system BASE <> 2
113 ELSE        MOV #10,&BASE   \ else (BASE = 2)
114 THEN        COLON           \
115             BASE @  U.      \ always display 10 !
116 ;                           \
117     \
118
119
120 \ -----------------------------------------------------------------------
121 \ test an assembly jump spanning a section written in FORTH
122 \ -----------------------------------------------------------------------
123 : TEST5
124             SPACE
125             HI2LO
126             SUB #2,PSP
127             MOV TOS,0(PSP)
128             MOV #%1010,TOS  \ init count = 10
129 BEGIN       SUB #$0001,TOS
130             LO2HI
131                             \ IP is already saved by word ":"
132             DUP U.          \ display count
133             HI2LO
134             CMP #0,TOS
135 0= UNTIL    MOV @PSP+,TOS
136 \           MOV #EXIT,PC    \ to pair with ":" i.e. to restore IP saved by : then execute NEXT. 
137             MOV @RSP+,IP    \ restore IP
138             MOV @IP+,PC     \ = NEXT
139 ENDCODE
140     \
141 TEST5  ; you should see :  9 8 7 6 5 4 3 2 1 0 -->
142     \
143
144 \ -----------------------------------------------------------------------
145 \ tests indexing address
146 \ -----------------------------------------------------------------------
147
148 : BYTES_TABLE_IDX
149 CREATE 
150 0 DO I C,
151 LOOP
152 DOES>
153 +
154 ;
155
156 8 BYTES_TABLE_IDX BYTES_TABLE \ create table "BYTES_TABLE" with bytes content = 0,1,2,3,4,5,6,7
157     \
158 2 BYTES_TABLE C@ . ; you should see 2 -->
159 \
160
161
162 VARIABLE BYTES_TABLE1
163
164 $0201 BYTES_TABLE1 !              \ words written in memory are little endian !
165
166 CODE IDX_TEST1                     \ index -- value
167     MOV.B   BYTES_TABLE1(TOS),TOS  \ -- value
168 COLON
169     U. 
170 ;      
171
172 0 IDX_TEST1     ; you should see 1 -->
173
174 CODE TEST6
175             MOV 0(PSP),0(PSP)  \
176             MOV @IP+,PC
177 ENDCODE
178
179
180 1 TEST6 .       ; you should see 1 -->
181
182
183 \ -----------------------------------------------------------------------
184 \ tests access to a CREATED word with assembler 
185 \ -----------------------------------------------------------------------
186
187
188     \
189 CREATE TABLE0
190 0 C,
191 1 C,
192 2 C,
193 3 C,
194     \
195
196 CREATE TABLE10
197 $10 C,
198 $11 C,
199 $12 C,
200 $13 C,
201
202     \
203
204 CREATE TABLE20
205 $20 C,
206 $21 C,
207 $22 C,
208 $23 C,
209     \
210
211 CREATE TABLE
212
213
214 TABLE 2 - CONSTANT PFA_TABLE      \ PFA_TABLE leave the PFA of TABLE
215
216
217 CODE REDIRECT       ; <table> --    redirects TABLE to argument <table>    
218 MOV TOS,&PFA_TABLE
219 MOV @PSP+,TOS
220 MOV @IP+,PC
221 ENDCODE
222     \
223
224 CODE REDIRECT0      ; --            redirects TABLE to TABLE0        
225 MOV #TABLE0,&PFA_TABLE
226 MOV @IP+,PC
227 ENDCODE
228     \
229
230 CODE REDIRECT10     ; --            redirects TABLE to TABLE10        
231 MOV #TABLE10,&PFA_TABLE
232 MOV @IP+,PC
233 ENDCODE
234     \
235
236 CODE REDIRECT20     ; --            redirects TABLE to TABLE20        
237 MOV #TABLE20,&PFA_TABLE
238 MOV @IP+,PC
239 ENDCODE
240     \
241
242 ' TABLE0 10 DUMP
243     \
244 ' TABLE10 10 DUMP
245     \
246 ' TABLE20 10 DUMP
247     \
248     \
249 TABLE0 REDIRECT TABLE 10 DUMP
250     \
251 TABLE10 REDIRECT TABLE 10 DUMP
252     \
253 TABLE20 REDIRECT TABLE 10 DUMP
254     \
255     \
256 REDIRECT0 TABLE 10 DUMP
257     \
258 REDIRECT10 TABLE 10 DUMP
259     \
260 REDIRECT20 TABLE 10 DUMP
261     \
262
263 TABLE0 PFA_TABLE ! TABLE 10 DUMP
264     \
265 TABLE10 PFA_TABLE ! TABLE 10 DUMP
266     \
267 TABLE20 PFA_TABLE ! TABLE 10 DUMP
268     \
269
270 \ -----------------------------------------------------------------------
271 \ tests behaviour of assembly error 
272 \ -----------------------------------------------------------------------
273 \ R16 causes an error, assembler context is aborted and the word TEST7 is "hidden".
274
275 \CODE TEST7
276 \           MOV 0(truc),0(R16)  ; display an error "out of bounds" -->
277
278 ; -----------------------------------------------------------------------
279 ; create a primary DEFERred assembly word
280 ; -----------------------------------------------------------------------
281
282 DEFER TRUC              ; here, TRUC is a secondary DEFERred word (i.e. without BODY)
283     \
284
285 CODENNM                 ; leaves its execution address (CFA) on stack
286     SUB #2,PSP
287     MOV TOS,0(PSP)
288     MOV @IP+,PC
289 ENDCODE 
290 DUP . IS TRUC         ; TRUC becomes a primary DEFERred word
291                         ; with its default action (DUP) located at its BODY addresse.
292
293 TRUC .                  ; display TOS value -->
294
295
296 ' TRUC >BODY IS TRUC    ; TRUC is reinitialzed with its default action
297
298
299 TRUC .                  ; display TOS value --> 
300
301 \ ' DROP IS TRUC          ; TRUC is redirected to DROP
302
303 \ TRUC                   ; The generated error displays stack empty! in reverse video, removes the TRUC definition and restarts the interpretation after the end of the file. And as you see, FastForth is able to display long lines, interesting, doesn't it? --> 
304 \    
305 \ bla
306 \ bla
307 \ bla
308
309
310
311
312
313
314
315 \ bla
316 \ ...
317
318
319
320