1 \ -*- coding: utf-8 -*-
3 ; -----------------------------------------------------------------------
5 ; -----------------------------------------------------------------------
8 \ MSP_EXP430FR5739 MSP_EXP430FR5969 MSP_EXP430FR5994 MSP_EXP430FR6989
9 \ MSP_EXP430FR4133 MSP_EXP430FR2433 MSP_EXP430FR2355 CHIPSTICK_FR2433
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
14 \ example : PUSHM #6,IP pushes IP,S,T,W,X,Y registers to return stack
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
19 \ example : POPM #6,IP pop Y,X,W,T,S,IP registers from return stack
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<
24 \ FORTH conditionnal : 0= 0< = < > U<
26 \ -----------------------------------------------------------------------
27 \ test CPUx instructions PUSHM, POPM, RLAM, RRAM, RRCM, RRUM
28 \ -----------------------------------------------------------------------
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"
42 PUSHM #4,IP \ PUSHM IP,S,T,W
43 POPM #4,IP \ POPM W,T,S,IP
45 MOV TOS,8(PSP) \ save old 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
57 COLON \ high level part of the word starts here...
59 ; \ and finishes here.
61 TESTPUSHM ; you should see 11111 3 2 1 0 -->
68 TESTPOPM ; you should see 11111 3 2 1 0 -->
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...
78 MOV &BASE,&BASE \ to test &xxxx src operand
80 0<> IF MOV #2,&BASE \ if base <> 2
81 ELSE MOV #$0A,&BASE \ else base = 2
83 COLON \ tips : no "ok" displayed in start of line <==> compilation mode
84 BASE @ U. \ always display 10 !
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
97 0<> IF MOV #2, &BASE \ if variable system BASE <> 2
98 ELSE MOV #10,&BASE \ else (BASE = 2)
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
104 ENDCODE \ ends assembler : remove vocabulary ASSEMBLER from CONTEXT
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
112 0<> IF MOV #2, &BASE \ if variable system BASE <> 2
113 ELSE MOV #10,&BASE \ else (BASE = 2)
115 BASE @ U. \ always display 10 !
120 \ -----------------------------------------------------------------------
121 \ test an assembly jump spanning a section written in FORTH
122 \ -----------------------------------------------------------------------
128 MOV #%1010,TOS \ init count = 10
131 \ IP is already saved by word ":"
132 DUP U. \ display count
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
141 TEST5 ; you should see : 9 8 7 6 5 4 3 2 1 0 -->
144 \ -----------------------------------------------------------------------
145 \ tests indexing address
146 \ -----------------------------------------------------------------------
156 8 BYTES_TABLE_IDX BYTES_TABLE \ create table "BYTES_TABLE" with bytes content = 0,1,2,3,4,5,6,7
158 2 BYTES_TABLE C@ . ; you should see 2 -->
162 VARIABLE BYTES_TABLE1
164 $0201 BYTES_TABLE1 ! \ words written in memory are little endian !
166 CODE IDX_TEST1 \ index -- value
167 MOV.B BYTES_TABLE1(TOS),TOS \ -- value
172 0 IDX_TEST1 ; you should see 1 -->
180 1 TEST6 . ; you should see 1 -->
183 \ -----------------------------------------------------------------------
184 \ tests access to a CREATED word with assembler
185 \ -----------------------------------------------------------------------
214 TABLE 2 - CONSTANT PFA_TABLE \ PFA_TABLE leave the PFA of TABLE
217 CODE REDIRECT ; <table> -- redirects TABLE to argument <table>
224 CODE REDIRECT0 ; -- redirects TABLE to TABLE0
225 MOV #TABLE0,&PFA_TABLE
230 CODE REDIRECT10 ; -- redirects TABLE to TABLE10
231 MOV #TABLE10,&PFA_TABLE
236 CODE REDIRECT20 ; -- redirects TABLE to TABLE20
237 MOV #TABLE20,&PFA_TABLE
249 TABLE0 REDIRECT TABLE 10 DUMP
251 TABLE10 REDIRECT TABLE 10 DUMP
253 TABLE20 REDIRECT TABLE 10 DUMP
256 REDIRECT0 TABLE 10 DUMP
258 REDIRECT10 TABLE 10 DUMP
260 REDIRECT20 TABLE 10 DUMP
263 TABLE0 PFA_TABLE ! TABLE 10 DUMP
265 TABLE10 PFA_TABLE ! TABLE 10 DUMP
267 TABLE20 PFA_TABLE ! TABLE 10 DUMP
270 \ -----------------------------------------------------------------------
271 \ tests behaviour of assembly error
272 \ -----------------------------------------------------------------------
273 \ R16 causes an error, assembler context is aborted and the word TEST7 is "hidden".
276 \ MOV 0(truc),0(R16) ; display an error "out of bounds" -->
278 ; -----------------------------------------------------------------------
279 ; create a primary DEFERred assembly word
280 ; -----------------------------------------------------------------------
282 DEFER TRUC ; here, TRUC is a secondary DEFERred word (i.e. without BODY)
285 CODENNM ; leaves its execution address (CFA) on stack
290 DUP . IS TRUC ; TRUC becomes a primary DEFERred word
291 ; with its default action (DUP) located at its BODY addresse.
293 TRUC . ; display TOS value -->
296 ' TRUC >BODY IS TRUC ; TRUC is reinitialzed with its default action
299 TRUC . ; display TOS value -->
301 \ ' DROP IS TRUC ; TRUC is redirected to DROP
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? -->