1 \ -----------------------------------------------------------------------
3 \ -----------------------------------------------------------------------
6 \ MSP_EXP430FR5739 MSP_EXP430FR5969 MSP_EXP430FR5994 MSP_EXP430FR6989
7 \ MSP_EXP430FR4133 MSP_EXP430FR2433 MSP_EXP430FR2355 CHIPSTICK_FR2433
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
12 \ example : PUSHM #6,IP pushes IP,S,T,W,X,Y registers to return stack
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
17 \ example : POPM #6,IP pop Y,X,W,T,S,IP registers from return stack
23 \ -----------------------------------------------------------------------
24 \ test CPUx instructions PUSHM, POPM, RLAM, RRAM, RRCM, RRUM
25 \ -----------------------------------------------------------------------
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"
39 PUSHM #4,IP \ PUSHM IP,S,T,W
40 POPM #4,IP \ POPM W,T,S,IP
42 MOV TOS,8(PSP) \ save old 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
54 COLON \ high level part of the word starts here...
56 ; \ and finishes here.
58 TESTPUSHM ; you should see 11111 3 2 1 0 -->
65 TESTPOPM ; you should see 11111 3 2 1 0 -->
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...
75 MOV &BASE,&BASE \ to test &xxxx src operand
77 0<> IF MOV #2,&BASE \ if base <> 2
78 ELSE MOV #$0A,&BASE \ else base = 2
80 COLON \ tips : no "ok" displayed in start of line <==> compilation mode
81 BASE @ U. \ always display 10 !
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
94 0<> IF MOV #2, &BASE \ if variable system BASE <> 2
95 ELSE MOV #10,&BASE \ else (BASE = 2)
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
101 ENDCODE \ ends assembler : remove vocabulary ASSEMBLER from CONTEXT
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
109 0<> IF MOV #2, &BASE \ if variable system BASE <> 2
110 ELSE MOV #10,&BASE \ else (BASE = 2)
112 BASE @ U. \ always display 10 !
117 \ -----------------------------------------------------------------------
118 \ test an assembly jump spanning a section written in FORTH
119 \ -----------------------------------------------------------------------
125 MOV #%1010,TOS \ init count = 10
128 \ IP is already saved by word ":"
129 DUP U. \ display count
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
138 TEST5 ; you should see : 9 8 7 6 5 4 3 2 1 0 -->
141 \ -----------------------------------------------------------------------
142 \ tests indexing address
143 \ -----------------------------------------------------------------------
153 8 BYTES_TABLE_IDX BYTES_TABLE \ create table "BYTES_TABLE" with bytes content = 0,1,2,3,4,5,6,7
155 2 BYTES_TABLE C@ . ; you should see 2 -->
159 VARIABLE BYTES_TABLE1
161 $0201 BYTES_TABLE1 ! \ words written in memory are little endian !
163 CODE IDX_TEST1 \ index -- value
164 MOV.B BYTES_TABLE1(TOS),TOS \ -- value
169 0 IDX_TEST1 ; you should see 1 -->
177 1 TEST6 . ; you should see 1 -->
180 \ -----------------------------------------------------------------------
181 \ tests access to a CREATED word with assembler
182 \ -----------------------------------------------------------------------
211 TABLE 2 - CONSTANT PFA_TABLE \ PFA_TABLE leave the PFA of TABLE
214 CODE REDIRECT ; <table> -- redirects TABLE to argument <table>
221 CODE REDIRECT0 ; -- redirects TABLE to TABLE0
222 MOV #TABLE0,&PFA_TABLE
227 CODE REDIRECT10 ; -- redirects TABLE to TABLE10
228 MOV #TABLE10,&PFA_TABLE
233 CODE REDIRECT20 ; -- redirects TABLE to TABLE20
234 MOV #TABLE20,&PFA_TABLE
246 TABLE0 REDIRECT TABLE 10 DUMP
248 TABLE10 REDIRECT TABLE 10 DUMP
250 TABLE20 REDIRECT TABLE 10 DUMP
253 REDIRECT0 TABLE 10 DUMP
255 REDIRECT10 TABLE 10 DUMP
257 REDIRECT20 TABLE 10 DUMP
260 TABLE0 PFA_TABLE ! TABLE 10 DUMP
262 TABLE10 PFA_TABLE ! TABLE 10 DUMP
264 TABLE20 PFA_TABLE ! TABLE 10 DUMP
267 \ -----------------------------------------------------------------------
268 \ tests behaviour of assembly error
269 \ -----------------------------------------------------------------------
270 \ R16 causes an error, assembler context is aborted and the word TEST7 is "hidden".
273 \ MOV 0(truc),0(R16) ; display an error "out of bounds" -->
275 ; -----------------------------------------------------------------------
276 ; create a primary DEFERred assembly word
277 ; -----------------------------------------------------------------------
279 DEFER TRUC ; here, TRUC is a secondary DEFERred word (i.e. without BODY)
282 CODENNM ; leaves its execution address (CFA) on stack
286 ENDCODE IS TRUC ; TRUC becomes a primary DEFERred word
287 ; with its default action (DUP) located at its BODY addresse.
289 TRUC . ; display TOS value -->
292 ' TRUC >BODY IS TRUC ; TRUC is reinitialzed with its default action
295 TRUC . ; display TOS value -->
297 ' DROP IS TRUC ; TRUC is redirected to DROP
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? -->