OSDN Git Service

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