OSDN Git Service

0440bc4ec54121af5338e4bed1c6101c5b7757ac
[fast-forth/master.git] / MSP430-FORTH / ANS_COMP.f
1 \ -*- coding: utf-8 -*-
2
3 ; -----------------------------------------------------
4 ; ANS_COMP.f    words complement to pass CORETEST.4TH
5 ; -----------------------------------------------------
6 \
7 \ to see kernel options, download FastForthSpecs.f
8 \ FastForth kernel options: MSP430ASSEMBLER, CONDCOMP
9 \
10 \ TARGET Current Selection 
11 \ (used by preprocessor GEMA to load the pattern: \config\gema\TARGET.pat)
12 \ MSP_EXP430FR5739  MSP_EXP430FR5969    MSP_EXP430FR5994    MSP_EXP430FR6989
13 \ MSP_EXP430FR2433  MSP_EXP430FR4133    MSP_EXP430FR2355    CHIPSTICK_FR2433
14 \
15 \ REGISTERS USAGE
16 \ rDODOES to rEXIT must be saved before use and restored after
17 \ scratch registers Y to S are free for use
18 \ under interrupt, IP is free for use
19 \
20 \ PUSHM order : PSP,TOS, IP,  S,  T,  W,  X,  Y, rEXIT, rDOVAR, rDOCON, rDODOES
21 \ example : PUSHM #6,IP pushes IP,S,T,W,X,Y registers to return stack
22 \
23 \ POPM  order :  rDODOES, rDOCON, rDOVAR, rEXIT,  Y,  X,  W,  T,  S, IP,TOS,PSP
24 \ example : POPM #6,IP   pulls Y,X,W,T,S,IP registers from return stack
25 \
26 \ FORTH conditionnals:  unary{ 0= 0< 0> }, binary{ = < > U< }
27 \
28 \ ASSEMBLER conditionnal usage with IF UNTIL WHILE  S<  S>=  U<   U>=  0=  0<>  0>=
29 \ ASSEMBLER conditionnal usage with ?GOTO           S<  S>=  U<   U>=  0=  0<>  0<
30
31 [UNDEFINED] {ANS_COMP} [IF]
32
33 PWR_STATE
34
35 MARKER {ANS_COMP}
36
37 \ https://forth-standard.org/standard/core/VALUE
38 \ ( x "<spaces>name" -- )                      define a Forth VALUE
39 \ Skip leading space delimiters. Parse name delimited by a space.
40 \ Create a definition for name with the execution semantics defined below,
41 \ with an initial value equal to x.
42
43 \ name Execution: ( -- x )
44 \ Place x on the stack. The value of x is that given when name was created,
45 \ until the phrase x TO name is executed, causing a new value of x to be assigned to name.
46
47 \ TO name Run-time: ( x -- )
48 \ Assign the value x to name.
49
50 [UNDEFINED] VARIABLE [IF]
51 \ https://forth-standard.org/standard/core/VARIABLE
52 \ VARIABLE <name>       --                      define a Forth VARIABLE
53
54 : VARIABLE 
55 DEFER
56 HI2LO
57 MOV @RSP+,IP
58 MOV #DOVAR,-4(W)        \   CFA = DOVAR
59 MOV @IP+,PC
60 ENDCODE
61
62 [THEN]
63
64 [UNDEFINED] CONSTANT [IF]
65 \ https://forth-standard.org/standard/core/CONSTANT
66 \ CONSTANT <name>     n --                      define a Forth CONSTANT 
67 : CONSTANT 
68 DEFER
69 HI2LO
70 MOV @RSP+,IP
71 MOV #DOCON,-4(W)        \   CFA = DOCON
72 MOV TOS,-2(W)           \   PFA = n
73 MOV @PSP+,TOS
74 MOV @IP+,PC
75 ENDCODE
76 [THEN]
77
78 \ https://forth-standard.org/standard/core/STATE
79 \ STATE   -- a-addr       holds compiler state
80 STATEADR CONSTANT STATE
81
82 [UNDEFINED] BASE [IF]
83 \ https://forth-standard.org/standard/core/BASE
84 \ BASE    -- a-addr       holds conversion radix
85 BASEADR CONSTANT BASE
86 [THEN]
87
88 [UNDEFINED] >IN [IF]
89 \ https://forth-standard.org/standard/core/toIN
90 \ C >IN     -- a-addr       holds offset in input stream
91 TOIN CONSTANT >IN
92 [THEN]
93
94 [UNDEFINED] PAD [IF]
95 \ https://forth-standard.org/standard/core/PAD
96 \  PAD           --  addr
97 PAD_ORG CONSTANT PAD
98 [THEN]
99
100 [UNDEFINED] BL [IF]
101 \ https://forth-standard.org/standard/core/BL
102 \ BL      -- char            an ASCII space
103 #32 CONSTANT BL
104 [THEN]
105
106 [UNDEFINED] SPACE [IF]
107 \ https://forth-standard.org/standard/core/SPACE
108 \ SPACE   --               output a space
109 : SPACE
110 BL EMIT ;
111 [THEN]
112
113 [UNDEFINED] SPACES [IF]
114 \ https://forth-standard.org/standard/core/SPACES
115 \ SPACES   n --            output n spaces
116 CODE SPACES
117 CMP #0,TOS
118 0<> IF
119     PUSH IP
120     BEGIN
121         LO2HI
122         BL EMIT
123         HI2LO
124         SUB #2,IP 
125         SUB #1,TOS
126     0= UNTIL
127     MOV @RSP+,IP
128 THEN
129 MOV @PSP+,TOS           \ --         drop n
130 NEXT              
131 ENDCODE
132 [THEN]
133
134
135 \ \ https://forth-standard.org/standard/core/VALUE
136 \ : VALUE                 \ x "<spaces>name" -- 
137 \ CREATE ,
138 \ DOES> 
139 \ HI2LO
140 \ MOV @RSP+,IP
141 \ BIT #UF10,SR    \ see TO
142 \ 0= IF
143 \     MOV #@,PC
144 \ THEN 
145 \ BIC #UF10,SR
146 \ MOV #!,PC
147 \ ENDCODE
148
149 \ \ https://forth-standard.org/standard/core/TO
150 \ \ TO name Run-time: ( x -- )
151 \ \ Assign the value x to named VALUE.
152 \ CODE TO
153 \ BIS #UF10,SR
154 \ MOV @IP+,PC
155 \ ENDCODE
156
157 \ https://forth-standard.org/standard/core/StoD
158 \ S>D    n -- d          single -> double prec.
159 : S>D
160     DUP 0<
161 ;
162
163 [UNDEFINED] NIP [IF]
164 \ https://forth-standard.org/standard/core/NIP
165 \ NIP      x1 x2 -- x2         Drop the first item below the top of stack
166 CODE NIP
167 ADD #2,PSP
168 MOV @IP+,PC
169 ENDCODE
170 [THEN]
171
172 [UNDEFINED] C@ [IF]
173 \ https://forth-standard.org/standard/core/CFetch
174 \ C@     c-addr -- char   fetch char from memory
175 CODE C@
176 MOV.B @TOS,TOS
177 MOV @IP+,PC
178 ENDCODE
179 [THEN]
180
181 [UNDEFINED] C! [IF]
182 \ https://forth-standard.org/standard/core/CStore
183 \ C!      char c-addr --    store char in memory
184 CODE C!
185 MOV.B @PSP+,0(TOS)  \ 4
186 ADD #1,PSP          \ 1
187 MOV @PSP+,TOS       \ 2
188 MOV @IP+,PC
189 ENDCODE
190 [THEN]
191
192 [UNDEFINED] C, [IF]
193 \ https://forth-standard.org/standard/core/CComma
194 \ C,   char --        append char
195 CODE C,
196 MOV &DP,W
197 MOV.B TOS,0(W)
198 ADD #1,&DP
199 MOV @PSP+,TOS
200 MOV @IP+,PC
201 ENDCODE
202 [THEN]
203
204 [UNDEFINED] AND [IF]
205 \ https://forth-standard.org/standard/core/AND
206 \ C AND    x1 x2 -- x3           logical AND
207 CODE AND
208 AND @PSP+,TOS
209 MOV @IP+,PC
210 ENDCODE
211 [THEN]
212
213 [UNDEFINED] OR [IF]
214 \ https://forth-standard.org/standard/core/OR
215 \ C OR     x1 x2 -- x3           logical OR
216 CODE OR
217 BIS @PSP+,TOS
218 MOV @IP+,PC
219 ENDCODE
220 [THEN]
221
222 [UNDEFINED] XOR [IF]
223 \ https://forth-standard.org/standard/core/XOR
224 \ C XOR    x1 x2 -- x3           logical XOR
225 CODE XOR
226 XOR @PSP+,TOS
227 MOV @IP+,PC
228 ENDCODE
229 [THEN]
230
231 [UNDEFINED] + [IF]
232 \ https://forth-standard.org/standard/core/Plus
233 \ +       n1/u1 n2/u2 -- n3/u3     add n1+n2
234 CODE +
235 ADD @PSP+,TOS
236 MOV @IP+,PC
237 ENDCODE
238 [THEN]
239
240 \ https://forth-standard.org/standard/core/INVERT
241 \ INVERT   x1 -- x2            bitwise inversion
242 CODE INVERT
243 XOR #-1,TOS
244 MOV @IP+,PC
245 ENDCODE
246
247 \ https://forth-standard.org/standard/core/less
248 \ <      n1 n2 -- flag        test n1<n2, signed
249 CODE <
250         SUB @PSP+,TOS   \ 1 TOS=n2-n1
251         S< ?GOTO FW1    \ 2 signed
252     0<> IF              \ 2
253 BW1     MOV #-1,TOS     \ 1 flag Z = 0
254     THEN
255         MOV @IP+,PC
256 ENDCODE
257
258 \ https://forth-standard.org/standard/core/more
259 \ >     n1 n2 -- flag         test n1>n2, signed
260 CODE >
261         SUB @PSP+,TOS   \ 2 TOS=n2-n1
262         S< ?GOTO BW1    \ 2 --> +5
263 FW1     AND #0,TOS      \ 1 flag Z = 1
264         MOV @IP+,PC
265 ENDCODE
266
267 \ https://forth-standard.org/standard/core/LSHIFT
268 \ LSHIFT  x1 u -- x2    logical L shift u places
269 CODE LSHIFT
270             MOV @PSP+,W
271             AND #$1F,TOS        \ no need to shift more than 16
272 0<> IF
273     BEGIN   ADD W,W
274             SUB #1,TOS
275     0= UNTIL
276 THEN        MOV W,TOS
277             MOV @IP+,PC
278 ENDCODE
279
280 \ https://forth-standard.org/standard/core/RSHIFT
281 \ RSHIFT  x1 u -- x2    logical R7 shift u places
282 CODE RSHIFT
283             MOV @PSP+,W
284             AND #$1F,TOS       \ no need to shift more than 16
285 0<> IF
286     BEGIN   BIC #C,SR           \ Clr Carry
287             RRC W
288             SUB #1,TOS
289     0= UNTIL
290 THEN        MOV W,TOS
291             MOV @IP+,PC
292 ENDCODE
293
294 [UNDEFINED] MAX [IF]
295 \ https://forth-standard.org/standard/core/MAX
296 \ MAX    n1 n2 -- n3       signed maximum
297 CODE MAX
298     CMP @PSP,TOS    \ n2-n1
299     S<  ?GOTO FW1   \ n2<n1
300 BW1 ADD #2,PSP
301     MOV @IP+,PC
302 ENDCODE
303
304 \ https://forth-standard.org/standard/core/MIN
305 \ MIN    n1 n2 -- n3       signed minimum
306 CODE MIN
307     CMP @PSP,TOS    \ n2-n1
308     S< ?GOTO BW1    \ n2<n1
309 FW1 MOV @PSP+,TOS
310     MOV @IP+,PC
311 ENDCODE
312 [THEN]
313
314 \ https://forth-standard.org/standard/core/TwoTimes
315 \ 2*      x1 -- x2         arithmetic left shift
316 CODE 2*
317 ADD TOS,TOS
318 MOV @IP+,PC
319 ENDCODE
320
321 \ https://forth-standard.org/standard/core/TwoDiv
322 \ 2/      x1 -- x2        arithmetic right shift
323 CODE 2/
324 RRA TOS
325 MOV @IP+,PC
326 ENDCODE
327
328 \ --------------------
329 \ ARITHMETIC OPERATORS
330 \ --------------------
331 TLV_ORG 4 + @ $81F3 U<
332 $81EF TLV_ORG 4 + @ U< 
333 = [IF]   ; MSP430FR413x subfamily without hardware_MPY
334
335 \ https://forth-standard.org/standard/core/MTimes
336 \ M*     n1 n2 -- dlo dhi  signed 16*16->32 multiply
337 CODE M*
338 MOV @PSP,S          \ S= n1
339 CMP #0,S            \ n1 > -1 ?
340 S< IF
341     XOR #-1,0(PSP)  \ n1 --> u1
342     ADD #1,0(PSP)   \
343 THEN
344 XOR TOS,S           \ S contains sign of result
345 CMP #0,TOS          \ n2 > -1 ?
346 S< IF
347     XOR #-1,TOS     \ n2 --> u2 
348     ADD #1,TOS      \
349 THEN
350 PUSHM #2,IP         \ UMSTAR use S,T,W,X,Y
351 LO2HI               \ -- ud1 u2
352 UM*       
353 HI2LO
354 POPM #2,IP           \ pop S,IP
355 CMP #0,S            \ sign of result > -1 ?
356 S< IF
357     XOR #-1,0(PSP)  \ ud --> d
358     XOR #-1,TOS
359     ADD #1,0(PSP)
360     ADDC #0,TOS
361 THEN
362 MOV @IP+,PC
363 ENDCODE
364
365 [ELSE]  ; MSP430FRxxxx with hardware_MPY
366
367 \ https://forth-standard.org/standard/core/UMTimes
368 \ UM*     u1 u2 -- udlo udhi   unsigned 16x16->32 mult.
369 CODE UM*
370     MOV @PSP,&MPY       \ Load 1st operand for unsigned multiplication
371 BW1 MOV TOS,&OP2        \ Load 2nd operand
372     MOV &RES0,0(PSP)    \ low result on stack
373     MOV &RES1,TOS       \ high result in TOS
374     MOV @IP+,PC
375 ENDCODE
376
377 \ https://forth-standard.org/standard/core/MTimes
378 \ M*     n1 n2 -- dlo dhi  signed 16*16->32 multiply
379 CODE M*
380     MOV @PSP,&MPYS      \ Load 1st operand for signed multiplication
381     GOTO BW1
382 ENDCODE
383
384 [THEN]
385
386 \ https://forth-standard.org/standard/core/UMDivMOD
387 \ UM/MOD   udlo|udhi u1 -- r q   unsigned 32/16->r16 q16
388 CODE UM/MOD
389     PUSH #DROP      \
390     MOV #<#,X       \ X = addr of <#
391     ADD #8,X        \ X = addr of MUSMOD
392     MOV X,PC        \ execute MUSMOD then RET to DROP
393 ENDCODE
394
395 \ https://forth-standard.org/standard/core/SMDivREM
396 \ SM/REM   DVDlo DVDhi DIVlo -- r3 q4  symmetric signed div
397 CODE SM/REM
398 MOV TOS,S           \           S=DIVlo
399 MOV @PSP,T          \           T=DVD_sign==>rem_sign
400 CMP #0,TOS          \           n2 >= 0 ?
401 S< IF               \
402     XOR #-1,TOS
403     ADD #1,TOS      \ -- d1 u2
404 THEN
405 CMP #0,0(PSP)       \           d1hi >= 0 ?
406 S< IF               \
407     XOR #-1,2(PSP)  \           d1lo
408     XOR #-1,0(PSP)  \           d1hi
409     ADD #1,2(PSP)   \           d1lo+1
410     ADDC #0,0(PSP)  \           d1hi+C
411 THEN                \ -- uDVDlo uDVDhi uDIVlo
412 PUSHM #3,IP         \           save IP,S,T
413 LO2HI
414     UM/MOD          \ -- uREMlo uQUOTlo
415 HI2LO
416 POPM #3,IP          \           restore T,S,IP
417 CMP #0,T            \           T=rem_sign
418 S< IF
419     XOR #-1,0(PSP)
420     ADD #1,0(PSP)
421 THEN
422 XOR S,T             \           S=divisor T=quot_sign
423 CMP #0,T            \ -- n3 u4  T=quot_sign
424 S< IF
425 BW1
426 BW2
427     XOR #-1,TOS
428     ADD #1,TOS
429 THEN                \ -- n3 n4  S=divisor
430 MOV @IP+,PC
431 ENDCODE
432
433 \ https://forth-standard.org/standard/core/NEGATE
434 \ C NEGATE   x1 -- x2            two's complement
435 CODE NEGATE
436 GOTO BW1 
437 ENDCODE
438
439 \ https://forth-standard.org/standard/core/ABS
440 \ C ABS     n1 -- +n2     absolute value
441 CODE ABS
442 CMP #0,TOS       \  1
443 0< ?GOTO BW2
444 MOV @IP+,PC
445 ENDCODE
446
447 \ https://forth-standard.org/standard/core/FMDivMOD
448 \ FM/MOD   d1 n1 -- r q   floored signed div'n
449 : FM/MOD
450 SM/REM
451 HI2LO               \ -- remainder quotient       S=divisor
452 CMP #0,0(PSP)       \ remainder <> 0 ?
453 0<> IF
454     CMP #1,TOS      \ quotient < 1 ?
455     S< IF
456       ADD S,0(PSP)  \ add divisor to remainder
457       SUB #1,TOS    \ decrement quotient
458     THEN
459 THEN
460 MOV @RSP+,IP
461 MOV @IP+,PC
462 ENDCODE
463
464 \ https://forth-standard.org/standard/core/Times
465 \ *      n1 n2 -- n3       signed multiply
466 : *
467 M* DROP
468 ;
469
470 \ https://forth-standard.org/standard/core/DivMOD
471 \ /MOD   n1 n2 -- r3 q4     signed division
472 : /MOD
473 >R DUP 0< R> FM/MOD
474 ;
475
476 \ https://forth-standard.org/standard/core/Div
477 \ /      n1 n2 -- n3       signed quotient
478 : /
479 >R DUP 0< R> FM/MOD NIP
480 ;
481
482 \ https://forth-standard.org/standard/core/MOD
483 \ MOD    n1 n2 -- n3       signed remainder
484 : MOD
485 >R DUP 0< R> FM/MOD DROP
486 ;
487
488 \ https://forth-standard.org/standard/core/TimesDivMOD
489 \ */MOD  n1 n2 n3 -- r4 q5    signed mult/div
490 : */MOD
491 >R M* R> FM/MOD
492 ;
493
494 \ https://forth-standard.org/standard/core/TimesDiv
495 \ */     n1 n2 n3 -- n4        n1*n2/q3
496 : */
497 >R M* R> FM/MOD NIP
498 ;
499
500 \ -------------------------------------------------------------------------------
501 \  STACK OPERATIONS
502 \ -------------------------------------------------------------------------------
503
504 [UNDEFINED] OVER [IF]
505 \ https://forth-standard.org/standard/core/OVER
506 \ OVER    x1 x2 -- x1 x2 x1
507 CODE OVER
508 MOV TOS,-2(PSP)     \ 3 -- x1 (x2) x2
509 MOV @PSP,TOS        \ 2 -- x1 (x2) x1
510 SUB #2,PSP          \ 1 -- x1 x2 x1
511 MOV @IP+,PC
512 ENDCODE
513 [THEN]
514
515 \ https://forth-standard.org/standard/core/ROT
516 \ ROT    x1 x2 x3 -- x2 x3 x1
517 CODE ROT
518 MOV @PSP,W          \ 2 fetch x2
519 MOV TOS,0(PSP)      \ 3 store x3
520 MOV 2(PSP),TOS      \ 3 fetch x1
521 MOV W,2(PSP)        \ 3 store x2
522 MOV @IP+,PC
523 ENDCODE
524
525 \ https://forth-standard.org/standard/core/RFetch
526 \ R@    -- x     R: x -- x   fetch from return stack
527 CODE R@
528 SUB #2,PSP
529 MOV TOS,0(PSP)
530 MOV @RSP,TOS
531 MOV @IP+,PC
532 ENDCODE
533
534 \ ----------------------------------------------------------------------
535 \ DOUBLE OPERATORS
536 \ ----------------------------------------------------------------------
537
538 [UNDEFINED] {DOUBLE} [IF]
539
540 \ https://forth-standard.org/standard/core/TwoFetch
541 \ 2@    a-addr -- x1 x2    fetch 2 cells ; the lower address will appear on top of stack
542 CODE 2@
543 BW1 SUB #2,PSP
544     MOV 2(TOS),0(PSP)
545     MOV @TOS,TOS
546     MOV @IP+,PC
547 ENDCODE
548
549 \ https://forth-standard.org/standard/core/TwoStore
550 \ 2!    x1 x2 a-addr --    store 2 cells ; the top of stack is stored at the lower adr
551 CODE 2!
552 BW2 MOV @PSP+,0(TOS)
553     MOV @PSP+,2(TOS)
554     MOV @PSP+,TOS
555     MOV @IP+,PC
556 ENDCODE
557
558 \ \ https://forth-standard.org/standard/double/TwoVALUE
559 \ : 2VALUE        \ x1 x2 "<spaces>name" --
560 \ CREATE , ,      \ compile Shi then Flo
561 \ DOES>
562 \ HI2LO
563 \ MOV @RSP+,IP
564 \ BIT #UF10,SR    \see TO
565 \ 0= ?GOTO BW1 
566 \ BIC #UF10,SR
567 \ GOTO BW2
568 \ ENDCODE
569
570 \ https://forth-standard.org/standard/core/TwoDROP
571 \ 2DROP  x1 x2 --          drop 2 cells
572 CODE 2DROP
573 ADD #2,PSP
574 MOV @PSP+,TOS
575 MOV @IP+,PC
576 ENDCODE
577
578 \ https://forth-standard.org/standard/core/TwoSWAP
579 \ 2SWAP  x1 x2 x3 x4 -- x3 x4 x1 x2
580 CODE 2SWAP
581 MOV @PSP,W          \ -- x1 x2 x3 x4    W=x3
582 MOV 4(PSP),0(PSP)   \ -- x1 x2 x1 x4
583 MOV W,4(PSP)        \ -- x3 x2 x1 x4
584 MOV TOS,W           \ -- x3 x2 x1 x4    W=x4
585 MOV 2(PSP),TOS      \ -- x3 x2 x1 x2    W=x4
586 MOV W,2(PSP)        \ -- x3 x4 x1 x2
587 MOV @IP+,PC
588 ENDCODE
589
590 \ https://forth-standard.org/standard/core/TwoOVER
591 \ 2OVER  x1 x2 x3 x4 -- x1 x2 x3 x4 x1 x2
592 CODE 2OVER
593 SUB #4,PSP          \ -- x1 x2 x3 x x x4
594 MOV TOS,2(PSP)      \ -- x1 x2 x3 x4 x x4
595 MOV 8(PSP),0(PSP)   \ -- x1 x2 x3 x4 x1 x4
596 MOV 6(PSP),TOS      \ -- x1 x2 x3 x4 x1 x2
597 MOV @IP+,PC
598 ENDCODE
599
600 [THEN]
601
602 \ ----------------------------------------------------------------------
603 \ ALIGNMENT OPERATORS
604 \ ----------------------------------------------------------------------
605 \ https://forth-standard.org/standard/core/ALIGNED
606 \ ALIGNED  addr -- a-addr       align given addr
607 CODE ALIGNED
608 BIT #1,TOS
609 ADDC #0,TOS
610 MOV @IP+,PC
611 ENDCODE
612
613 \ https://forth-standard.org/standard/core/ALIGN
614 \ ALIGN    --                         align HERE
615 CODE ALIGN
616 BIT #1,&DP  \ 3
617 ADDC #0,&DP \ 4
618 MOV @IP+,PC
619 ENDCODE
620
621 \ ---------------------
622 \ PORTABILITY OPERATORS
623 \ ---------------------
624 \ https://forth-standard.org/standard/core/CHARS
625 \ CHARS    n1 -- n2            chars->adrs units
626 CODE CHARS
627 MOV @IP+,PC
628 ENDCODE
629
630 \ https://forth-standard.org/standard/core/CHARPlus
631 \ CHAR+    c-addr1 -- c-addr2   add char size
632 CODE CHAR+
633 ADD #1,TOS
634 MOV @IP+,PC
635 ENDCODE
636
637 \ https://forth-standard.org/standard/core/CELLS
638 \ CELLS    n1 -- n2            cells->adrs units
639 CODE CELLS
640 ADD TOS,TOS
641 MOV @IP+,PC
642 ENDCODE
643
644 \ https://forth-standard.org/standard/core/CELLPlus
645 \ CELL+    a-addr1 -- a-addr2      add cell size
646 CODE CELL+
647 ADD #2,TOS
648 MOV @IP+,PC
649 ENDCODE
650
651 \ ---------------------------
652 \ BLOCK AND STRING COMPLEMENT
653 \ ---------------------------
654
655 \ https://forth-standard.org/standard/core/CHAR
656 \ CHAR   -- char           parse ASCII character
657 : CHAR
658     BL WORD 1+ C@
659 ;
660
661 \ https://forth-standard.org/standard/core/BracketCHAR
662 \ [CHAR]   --          compile character literal
663 : [CHAR]
664     CHAR POSTPONE LITERAL
665 ; IMMEDIATE
666
667 \ https://forth-standard.org/standard/core/PlusStore
668 \ +!     n/u a-addr --       add n/u to memory
669 CODE +!
670 ADD @PSP+,0(TOS)
671 MOV @PSP+,TOS
672 MOV @IP+,PC
673 ENDCODE
674
675 \ https://forth-standard.org/standard/core/FILL
676 \ FILL   c-addr u char --  fill memory with char
677 CODE FILL
678 MOV @PSP+,X     \ count
679 MOV @PSP+,W     \ address
680 CMP #0,X
681 0<> IF
682     BEGIN
683         MOV.B TOS,0(W)    \ store char in memory
684         ADD #1,W
685         SUB #1,X
686     0= UNTIL
687 THEN
688 MOV @PSP+,TOS     \ empties stack
689 MOV @IP+,PC
690 ENDCODE
691
692 \ --------------------
693 \ INTERPRET COMPLEMENT
694 \ --------------------
695
696 \ https://forth-standard.org/standard/core/HEX
697 CODE HEX
698 MOV #$10,&BASE
699 MOV @IP+,PC
700 ENDCODE
701
702 \ https://forth-standard.org/standard/core/DECIMAL
703 CODE DECIMAL
704 MOV #$0A,&BASE
705 MOV @IP+,PC
706 ENDCODE
707
708 \ https://forth-standard.org/standard/core/p
709 \ (         --          skip input until char ) or EOL
710 : ( 
711 $29 WORD DROP
712 ; IMMEDIATE
713
714 \ https://forth-standard.org/standard/core/Dotp
715 \ .(        --          type comment immediatly.
716 CODE .(         \ "
717 MOV #0,&CAPS    \ CAPS OFF
718 COLON
719 $29 WORD
720 COUNT TYPE
721 BL CAPS !       \ CAPS ON
722 ; IMMEDIATE
723
724 \ https://forth-standard.org/standard/core/J
725 \ J        -- n   R: 4*sys -- 4*sys
726 \ C                  get the second loop index
727 CODE J
728 SUB #2,PSP      
729 MOV TOS,0(PSP)
730 MOV 4(RSP),TOS
731 SUB 6(RSP),TOS
732 MOV @IP+,PC
733 ENDCODE
734
735 \ https://forth-standard.org/standard/core/UNLOOP
736 \ UNLOOP   --   R: sys1 sys2 --  drop loop parms
737 CODE UNLOOP
738 ADD #4,RSP
739 MOV @IP+,PC
740 ENDCODE
741
742 \ https://forth-standard.org/standard/core/LEAVE
743 \ LEAVE    --    L: -- adrs
744 CODE LEAVE
745 MOV &DP,W               \ compile three words
746 MOV #UNLOOP,0(W)        \ [HERE] = UNLOOP
747 MOV #.,2(W)             \ DOT + 8 = BRAN
748 ADD #8,2(W)             \ [HERE+2] = BRAN
749 ADD #6,&DP              \ [HERE+4] = After LOOP adr
750 ADD #2,&LEAVEPTR
751 ADD #4,W
752 MOV &LEAVEPTR,X
753 MOV W,0(X)              \ leave HERE+4 on LEAVEPTR stack
754 MOV @IP+,PC
755 ENDCODE IMMEDIATE
756
757 \ https://forth-standard.org/standard/core/RECURSE
758 \ C RECURSE  --      recurse to current definition (compile current definition)
759 CODE RECURSE
760 MOV &DP,X
761 MOV &LAST_CFA,0(X)
762 ADD #2,&DP
763 MOV @IP+,PC
764 ENDCODE IMMEDIATE
765
766 \ https://forth-standard.org/standard/core/SOURCE
767 \ SOURCE    -- adr u    of current input buffer
768 CODE SOURCE
769 SUB #4,PSP
770 MOV TOS,2(PSP)
771 MOV &SOURCE_LEN,TOS
772 MOV &SOURCE_ORG,0(PSP)
773 MOV @IP+,PC
774 ENDCODE
775
776 RST_HERE
777
778 [THEN]
779 ECHO