1 \ -----------------------------
2 \ MSP-EXP430FR5969_TSTWORDS.f
3 \ -----------------------------
5 \ first, we test for downloading driver only if UART TERMINAL target
10 SUB #309,TOS \ FastForth V3.9
12 'CR' EMIT \ return to column 1 without 'LF'
13 ABORT" FastForth V3.9 please!"
14 RST_RET \ remove ABORT_TEST_ASM definition before resuming
17 ABORT_TSTWORDS \ abort test
19 [DEFINED] {TSTWORDS} [IF] {TSTWORDS} [THEN] \ remove it
24 \ https://forth-standard.org/standard/core/ZeroEqual
25 \ 0= n/u -- flag return true if TOS=0
29 SUB #1,TOS \ 1 borrow (clear cy) if TOS was 0
30 SUBC TOS,TOS \ 1 TOS=-1 if borrow was set
36 [IF] \ define DUP and ?DUP
37 \ https://forth-standard.org/standard/core/DUP
38 \ DUP x -- x x duplicate top of stack
40 BW1 SUB #2,PSP \ 2 push old TOS..
41 MOV TOS,0(PSP) \ 3 ..onto stack
45 \ https://forth-standard.org/standard/core/qDUP
46 \ ?DUP x -- 0 | x x DUP if nonzero
48 CMP #0,TOS \ 2 test for TOS nonzero
54 \ https://forth-standard.org/standard/core/IF
55 \ IF -- IFadr initialize conditional forward branch
63 ADD #4,&DP \ compile one word, reserve one word
64 MOV #QFBRAN,0(TOS) \ -- HERE compile QFBRAN
65 ADD #2,TOS \ -- HERE+2=IFadr
69 \ https://forth-standard.org/standard/core/THEN
70 \ THEN IFadr -- resolve forward branch
72 MOV &DP,0(TOS) \ -- IFadr
78 \ https://forth-standard.org/standard/core/ELSE
79 \ ELSE IFadr -- ELSEadr resolve forward IF branch, leave ELSEadr on stack
83 ADD #4,&DP \ make room to compile two words
86 MOV W,0(TOS) \ HERE+4 ==> [IFadr]
88 MOV W,TOS \ -- ELSEadr
93 \ https://forth-standard.org/standard/core/SWAP
94 \ SWAP x1 x2 -- x2 x1 swap top two items
105 \ https://forth-standard.org/standard/core/BEGIN
106 \ BEGIN -- BEGINadr initialize backward branch
108 [IF] \ define BEGIN UNTIL AGAIN WHILE REPEAT
114 \ https://forth-standard.org/standard/core/UNTIL
115 \ UNTIL BEGINadr -- resolve conditional backward branch
118 BW1 ADD #4,&DP \ compile two words
120 MOV X,-4(W) \ compile Bran or QFBRAN at HERE
121 MOV TOS,-2(W) \ compile bakcward adr at HERE+2
126 \ https://forth-standard.org/standard/core/AGAIN
127 \ AGAIN BEGINadr -- resolve uncondionnal backward branch
133 \ https://forth-standard.org/standard/core/WHILE
134 \ WHILE BEGINadr -- WHILEadr BEGINadr
139 \ https://forth-standard.org/standard/core/REPEAT
140 \ REPEAT WHILEadr BEGINadr -- resolve WHILE loop
142 POSTPONE AGAIN POSTPONE THEN
147 [IF] \ define DO LOOP +LOOP
149 \ https://forth-standard.org/standard/core/DO
150 \ DO -- DOadr L: -- 0
151 HDNCODE XDO \ DO run time
152 MOV #$8000,X \ 2 compute 8000h-limit = "fudge factor"
154 MOV TOS,Y \ 1 loop ctr = index+fudge
155 ADD X,Y \ 1 Y = INDEX
156 PUSHM #2,X \ 4 PUSHM X,Y, i.e. PUSHM LIMIT, INDEX
164 ADD #2,&DP \ make room to compile xdo
165 MOV &DP,TOS \ -- HERE+2
166 MOV #XDO,-2(TOS) \ compile xdo
167 ADD #2,&LEAVEPTR \ -- HERE+2 LEAVEPTR+2
169 MOV #0,0(W) \ -- HERE+2 L-- 0, init
173 \ https://forth-standard.org/standard/core/LOOP
174 \ LOOP DOadr -- L-- an an-1 .. a1 0
175 HDNCODE XLOOP \ LOOP run time
176 ADD #1,0(RSP) \ 4 increment INDEX
177 BW1 BIT #$100,SR \ 2 is overflow bit set?
178 0= IF \ branch if no overflow
182 ADD #4,RSP \ 1 empties RSP
183 ADD #2,IP \ 1 overflow = loop done, skip branch ofs
184 MOV @IP+,PC \ 4 14~ taken or not taken xloop/loop
189 BW2 ADD #4,&DP \ make room to compile two words
191 MOV X,-4(W) \ xloop --> HERE
192 MOV TOS,-2(W) \ DOadr --> HERE+2
193 BEGIN \ resolve all "leave" adr
194 MOV &LEAVEPTR,TOS \ -- Adr of top LeaveStack cell
195 SUB #2,&LEAVEPTR \ --
196 MOV @TOS,TOS \ -- first LeaveStack value
197 CMP #0,TOS \ -- = value left by DO ?
199 MOV W,0(TOS) \ move adr after loop as UNLOOP adr
205 \ https://forth-standard.org/standard/core/PlusLOOP
206 \ +LOOP adrs -- L-- an an-1 .. a1 0
207 HDNCODE XPLOO \ +LOOP run time
208 ADD TOS,0(RSP) \ 4 increment INDEX by TOS value
209 MOV @PSP+,TOS \ 2 get new TOS, doesn't change flags
221 \ -----------------------------------------------------------------------
222 \ test some assembler words and show how to mix FORTH/ASSEMBLER routines
223 \ -----------------------------------------------------------------------
224 LOAD" \misc\TestASM.4th"
228 \ -------------------------------------
229 \ here we returned in the TestWords.4th
230 \ -------------------------------------
235 : LOOP_TEST 8 0 DO I . LOOP
238 LOOP_TEST \ you should see 0 1 2 3 4 5 6 7 -->
241 : LOOP_TEST1 \ n <LOOP_TEST1> ---
247 \ : LOOP_MAX \ FIND_NOTHING --
250 \ LOOP \ 14 cycles by loop
251 \ ABORT" 65536 LOOP "
254 : FIND_TEST \ FIND_TEST <word> --
262 0= IF ABORT" <-- not found !"
263 ELSE ABORT" <-- found !"
267 \ \ seeking $ word, FIND jumps all words on their first character so time of word loop is 20 cycles
268 \ \ see FIND in the source file for more information
270 \ \ FIND_TEST <lastword> result @ 8MHz, monothread : 1,2s
272 \ \ FIND_TEST $ results @ 8MHz, monothread, 201 words in vocabulary FORTH :
273 \ \ 27 seconds with only FORTH vocabulary in CONTEXT
274 \ \ 540 us for one search ( which gives the delay for QNUMBER in INTERPRET routine)
275 \ \ 2.6866 us / word, 21,49 cycles / word (for 20 cycles calculated (see FIND in source file)
278 \ \ FIND_TEST $ results @ 8MHz, 2 threads, 201 words in vocabulary FORTH :
279 \ \ 13 second with only FORTH vocabulary in CONTEXT
280 \ \ 260 us for one search ( which gives the delay for QNUMBER in INTERPRET routine)
281 \ \ 1,293 us / word, 10,34 cycles / word
283 \ \ FIND_TEST $ results @ 8MHz, 4 threads, 201 words in vocabulary FORTH :
284 \ \ 8 second with only FORTH vocabulary in CONTEXT
285 \ \ 160 us for one search ( which gives the delay for QNUMBER in INTERPRET routine)
286 \ \ 0,796 us / word, 6,37 cycles / word
288 \ \ FIND_TEST $ results @ 8MHz, 8 threads, 201 words in vocabulary FORTH :
289 \ \ 4.66 second with only FORTH vocabulary in CONTEXT
290 \ \ 93 us for one search ( which gives the delay for QNUMBER in INTERPRET routine)
291 \ \ 0,4463 us / word, 3,7 cycles / word
293 \ \ FIND_TEST $ results @ 8MHz, 16 threads, 201 words in vocabulary FORTH :
294 \ \ 2,8 second with only FORTH vocabulary in CONTEXT
295 \ \ 56 us for one search ( which gives the delay for QNUMBER in INTERPRET routine)
296 \ \ 0,278 us / word, 2,22 cycles / word
303 \ KEY EMIT \ wait for a KEY, then emit it