-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy patheForth431-msp430g2553-naken.lst
4331 lines (3202 loc) · 103 KB
/
eForth431-msp430g2553-naken.lst
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; This is a 430eForth assembler listing based on the original script from
; Dr. Chen Hanson Ting as described in his book: Zen and the Forth Language:
; EFORTH for the MSP430 from Texas Instruments (Kindle Edition). It was first
; written by him in IAR Assembler, then transferred to the CCS and now adapted
; by Michael Kalus for the naken_asm.
;
; MIT License
; ----------------------------------------------------------------------------
; Copyright (c) 2014 Dr. Chen-Hanson Ting CCS Version 430eForth4.3
; (c) 2018 Michael Kalus Naken Version 430eForth4.3n
; (c) 2018 Manfred Mahlow Flash Tools 430eForth4.3n1
;
; Permission is hereby granted, free of charge, to any person obtaining a copy
; of this software and associated documentation files (the "Software"), to deal
; in the Software without restriction, including without limitation the rights
; to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
; copies of the Software, and to permit persons to whom the Software is
;furnished to do so, subject to the following conditions:
;
; The above copyright notice and this permission notice shall be included in all
; copies or substantial portions of the Software.
;
; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
; OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
; SOFTWARE.
;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; 7/7/2012 430eForth1.0, from eForth86.asm and 430uForth
; 7/4/2012 Move 430uForth2.1 from IAR to CCS 5.2
; 8/5/2014 Move 430eForth2.2 to CCS 6.0. Fix linkage of OVER.
; Software UART at 2400 baud.
; 8/10/2014 430eForth2.3 9600 baud, thanks to Dirk Bruehl and
; Michael Kalus of www.4e4th.org
; 8/10/2014 430eForth2.4 Restore ERASE and WRITE
; 8/20/2014 430eForth2.5 Test Segment D
; 8/25/2014 430eForth2.6 Turnkey
; 8/26/2014 430eForth2.7 Optimize
; 9/16/2014 430eForth3.1 Tail recursion, APP!
; 10/11/2014 430eForth4.1 Direct thread, more optimization
; 10/23/2014 430eForth4.2 Direct thread, pack lists
; 11/12/2014 430eForth4.2 Direct thread, final
;
; Build for and verified on MSP430G2 LaunchPad from TI
; Assembled with Code Composer Sudio 6.0 IDE
; Internal DCO at 8 MHz
; Hardware UART at 9600 baud. TXD and RXD must be crossed.
;CCS: ;ting
; .nolist
; .title "msp430 eForth 4.3"
; .cdecls C,LIST,"msp430g2553.h" ; Include device header file
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;
; 05/13/2018 Moved 430eForth4.3 from CSS to Michael Kohn's naken_asm (ver.
; 23 april 2018) - ok ;mk
; 20180624 $," - bug fixed. Thanks to Manfred Mahlow. ;mk
; 20180628 DIGIT? : bug fix, 0= 0> were handled as numbers ;MM
; 20180629 FSCAN added, sets CP to the lowest free flash addr at BOOT time.
; FSCAN is executed before COLD executes QUIT.
; Version string changed in HI from 43n to 43n1. ;MM
; 20180630 ERASE and WRITE renamed to IERASE IWRITE due to name conflict ;MM
; 20180701 LITERAL and ALIGNED revealed. ;MM
; 20180707 Flash Test QFLASH ( a -- a ) added. Aborts with message ?flash
; if a > EDM. (EDM = End of Dictionary Memory space in the flash) ;MM
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;naken: ;mk
.msp430
.include "msp430g2553.inc" ; MCU-specific register equates for naken_asm
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Direct Thread Model of eForth
; CCS: .equ ; naken: equ ;mk
;; CPU registers
tos equ R4
stack equ R5
ip equ R6
temp0 equ R7
temp1 equ R8
temp2 equ R9
temp3 equ R10
;; Macros
; CCS: <name> .macro ; naken: .macro <name> ;mk
.macro pops ;DROP
mov.w @stack+,tos
.endm
.macro pushs ;DUP
decd.w stack
mov.w tos,0(stack)
.endm;; Constants
.macro INEXT ;mk renamed (dollar)NEXT to INEXT - inline code for NEXT.
mov @ip+,pc ; fetch code address into PC
.endm
.macro INEST ;mk renamed (dollar)NEST to INEST - inline code for NEST.
.align 16 ; CCS: 2 bytes align ; naken: 16 bit align. mk
call #DOLST ; fetch code address into PC, W=PFA
.endm
.macro ICONST ;mk renamed (dollar)CONST to ICONST - inline code calling DOCON.
.align 16 ; CCS: 2 bytes align ; naken: 16 bit align. mk
call #DOCON ; fetch code address into PC, W=PFA
.endm
;; Assembler constants
COMPO equ 040H ;lexicon compile only bit
IMEDD equ 080H ;lexicon immediate bit
MASKK equ 07F1FH ;lexicon bit mask
CELLL equ 2 ;size of a cell
BASEE equ 10 ;default radix
VOCSS equ 8 ;depth of vocabulary stack
BKSPP equ 8 ;backspace
LF equ 10 ;line feed
CRR equ 13 ;carriage return
ERR equ 27 ;error escape
TIC equ 39 ;tick
CALLL equ 012B0H ;NOP CALL opcodes
UPP equ 200H
DPP equ 220H
SPP equ 378H ;data stack
TIBB equ 380H ;terminal input buffer
RPP equ 3F8H ;return stacl
CODEE equ 0C000H ;code dictionary
COLDD equ 0FFFEH ;cold start vector
EM equ 0FFFFH ;top of memory
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
.list
;;;;
;; Main entry points and COLD start data
; .text ; CCS: Predefined Memory Segment Name : Main memory (flash or ROM)
.org 0C000H ; naken : MSP430G2553 main memory : C000-FFFF = 16KB flash ROM
; FFE0-FFFF = interrupt vectors
; .global main ; CCS: File Reference Directive
; unused in naken
main:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Device dependent I/O
; ?KEY ( -- F | c T )
; Return input character.
.dw 0
.db 4,"?KEY",0
QKEY:
pushs
0xc008: 0x8325 sub.w #2, r5 cycles: 1
0xc00a: 0x4485 mov.w r4, 0(r5) cycles: 4
0xc00c: 0x0000
QKEY1:
BIT.B #UCA0RXIFG,&IFG2
0xc00e: 0xb3d2 bit.b #1, &0x0003 cycles: 4
0xc010: 0x0003
JZ FALSE ;return false flag
0xc012: 0x24c3 jeq 0xc19a (offset: 390) cycles: 2
MOV.B &UCA0RXBUF,tos ; read character into TOS
0xc014: 0x4254 mov.b &0x0066, r4 cycles: 3
0xc016: 0x0066
pushs
0xc018: 0x8325 sub.w #2, r5 cycles: 1
0xc01a: 0x4485 mov.w r4, 0(r5) cycles: 4
0xc01c: 0x0000
jmp TRUE
0xc01e: 0x3cbf jmp 0xc19e (offset: 382) cycles: 2
; KEY ( -- c )
; Return input character.
.dw QKEY-6
.db 3,"KEY"
KEY: ;mk naken needs colon after label.
pushs
0xc026: 0x8325 sub.w #2, r5 cycles: 1
0xc028: 0x4485 mov.w r4, 0(r5) cycles: 4
0xc02a: 0x0000
KEY1:
BIT.B #UCA0RXIFG,&IFG2
0xc02c: 0xb3d2 bit.b #1, &0x0003 cycles: 4
0xc02e: 0x0003
JZ KEY1
0xc030: 0x27fd jeq 0xc02c (offset: -6) cycles: 2
MOV.B &UCA0RXBUF,tos ; read character into TOS
0xc032: 0x4254 mov.b &0x0066, r4 cycles: 3
0xc034: 0x0066
INEXT
0xc036: 0x4630 mov.w @r6+, PC cycles: 3
; EMIT ( c -- )
; Send character c to the output device.
.dw KEY-4
.db 4,"EMIT",0
EMIT:
EMIT1:
BIT.B #UCA0TXIFG,&IFG2
0xc040: 0xb3e2 bit.b #2, &0x0003 cycles: 4
0xc042: 0x0003
JZ EMIT1
0xc044: 0x27fd jeq 0xc040 (offset: -6) cycles: 2
MOV.B tos,&UCA0TXBUF
0xc046: 0x44c2 mov.b r4, &0x0067 cycles: 4
0xc048: 0x0067
pops
0xc04a: 0x4534 mov.w @r5+, r4 cycles: 2
INEXT
0xc04c: 0x4630 mov.w @r6+, PC cycles: 3
; !IO ( -- )
; Initialize the serial I/O devices.
; .dw EMIT-6
; .db 3,"!IO"
STOIO:
; 8MHz
mov.b &CALBC1_8MHZ, &BCSCTL1 ; Set DCO
0xc04e: 0x42d2 mov.b &0x10fd, &0x0057 cycles: 6
0xc050: 0x10fd
0xc052: 0x0057
mov.b &CALDCO_8MHZ, &DCOCTL ; to 8 MHz.
0xc054: 0x42d2 mov.b &0x10fc, &0x0056 cycles: 6
0xc056: 0x10fc
0xc058: 0x0056
mov.b #006h, &P1SEL ; Use P1.1/P1.2 for USCI_A0
0xc05a: 0x40f2 mov.b #0x06, &0x0026 cycles: 5
0xc05c: 0x0006
0xc05e: 0x0026
mov.b #006h, &P1SEL2 ; Use P1.1/P1.2 for USCI_A0
0xc060: 0x40f2 mov.b #0x06, &0x0041 cycles: 5
0xc062: 0x0006
0xc064: 0x0041
; Configure UART (Koch)
bis.b #UCSSEL_2,&UCA0CTL1 ;db2 SMCLK
0xc066: 0xd0f2 bis.b #0x80, &0x0061 cycles: 5
0xc068: 0x0080
0xc06a: 0x0061
mov.b #65,&UCA0BR0 ;db3 8MHz 9600 Insgesamt &833 = $341
0xc06c: 0x40f2 mov.b #0x41, &0x0062 cycles: 5
0xc06e: 0x0041
0xc070: 0x0062
mov.b #3,&UCA0BR1 ;db4 8MHz 9600
0xc072: 0x40f2 mov.b #0x03, &0x0063 cycles: 5
0xc074: 0x0003
0xc076: 0x0063
mov.b #UCBRS_2,&UCA0MCTL ;db5 Modulation UCBRSx = 2
0xc078: 0x42e2 mov.b #4, &0x0064 cycles: 4
0xc07a: 0x0064
bic.b #UCSWRST,&UCA0CTL1 ;db6 **Initialize USCI
0xc07c: 0xc3d2 bic.b #1, &0x0061 cycles: 4
0xc07e: 0x0061
INEXT
0xc080: 0x4630 mov.w @r6+, PC cycles: 3
;called from COLD
;; The kernel
; doLIT ( -- w )
; Push an inline literal.
; .dw STOIO-4
; .db COMPO+5,"doLIT"
DOLIT:
pushs
0xc082: 0x8325 sub.w #2, r5 cycles: 1
0xc084: 0x4485 mov.w r4, 0(r5) cycles: 4
0xc086: 0x0000
mov @ip+,tos
0xc088: 0x4634 mov.w @r6+, r4 cycles: 2
INEXT
0xc08a: 0x4630 mov.w @r6+, PC cycles: 3
; doCON ( -- a )
; Run time routine for CONSTANT, VARIABLE and CREATE.
; .dw DOLIT-6
; .db COMPO+5,"doCON"
DOCON:
pushs
0xc08c: 0x8325 sub.w #2, r5 cycles: 1
0xc08e: 0x4485 mov.w r4, 0(r5) cycles: 4
0xc090: 0x0000
pop tos
0xc092: 0x4134 pop.w r4 -- mov.w @SP+, r4 cycles: 2
mov @tos,tos
0xc094: 0x4424 mov.w @r4, r4 cycles: 2
INEXT
0xc096: 0x4630 mov.w @r6+, PC cycles: 3
; doLIST ( -- )
; Process colon list..
; .dw EMIT-6
; .db 6,"doLIST",0
DOLST:
mov ip,temp0 ;exchange pointers
0xc098: 0x4607 mov.w r6, r7 cycles: 1
pop ip ;push return stack
0xc09a: 0x4136 pop.w r6 -- mov.w @SP+, r6 cycles: 2
push temp0 ;restore the pointers
0xc09c: 0x1207 push.w r7 cycles: 3
INEXT
0xc09e: 0x4630 mov.w @r6+, PC cycles: 3
; EXIT ( -- )
; Terminate a colon definition.
.dw EMIT-6
.db 4,"EXIT",0
EXIT:
mov @sp+,ip
0xc0a8: 0x4136 pop.w r6 -- mov.w @SP+, r6 cycles: 2
INEXT
0xc0aa: 0x4630 mov.w @r6+, PC cycles: 3
; EXECUTE ( ca -- )
; Execute the word at ca.
.dw EXIT-6
.db 7,"EXECUTE"
EXECU:
mov tos,temp0
0xc0b6: 0x4407 mov.w r4, r7 cycles: 1
pops
0xc0b8: 0x4534 mov.w @r5+, r4 cycles: 2
br temp0
0xc0ba: 0x4700 mov.w r7, PC cycles: 2
; @EXECUTE ( a -- )
; Execute vector stored in address a.
.dw EXECU-8
.db 8,"@EXECUTE",0
ATEXE:
mov @tos,temp0
0xc0c8: 0x4427 mov.w @r4, r7 cycles: 2
pops
0xc0ca: 0x4534 mov.w @r5+, r4 cycles: 2
br temp0
0xc0cc: 0x4700 mov.w r7, PC cycles: 2
; branch ( -- )
; Branch to an inline address.
; .dw ATEXE-10
; .db COMPO+6,"branch",0
BRAN:
mov @ip+,ip
0xc0ce: 0x4636 mov.w @r6+, r6 cycles: 2
INEXT
0xc0d0: 0x4630 mov.w @r6+, PC cycles: 3
; ?branch ( f -- )
; Branch if flag is zero.
; .dw BRAN-8
; .db COMPO+7,"?branch"
QBRAN:
tst tos
0xc0d2: 0x9304 cmp.w #0, r4 cycles: 1
pops
0xc0d4: 0x4534 mov.w @r5+, r4 cycles: 2
jz BRAN
0xc0d6: 0x27fb jeq 0xc0ce (offset: -10) cycles: 2
jmp SKIP
0xc0d8: 0x3c04 jmp 0xc0e2 (offset: 8) cycles: 2
; next ( -- )
; Run time code for the single index loop.
; : next ( -- ) \ hilevel model
; r> r> dup if 1 - >r @ >r exit then drop cell+ >r ;
; .dw QBRAB-8
; .db COMPO+4,"next",0
DONXT:
dec 0(sp) ;decrement index
0xc0da: 0x8391 sub.w #1, 0(SP) cycles: 4
0xc0dc: 0x0000
jge BRAN ;loop back
0xc0de: 0x37f7 jge 0xc0ce (offset: -18) cycles: 2
incd.w sp ;discard index
0xc0e0: 0x5321 add.w #2, SP cycles: 1
SKIP:
incd.w ip ;exit loop
0xc0e2: 0x5326 add.w #2, r6 cycles: 1
INEXT
0xc0e4: 0x4630 mov.w @r6+, PC cycles: 3
; ! ( w a -- )
; Pop the data stack to memory.
.dw ATEXE-10
.db 1,"!"
STORE:
mov.w @stack+,0(tos)
0xc0ea: 0x45b4 mov.w @r5+, 0(r4) cycles: 5
0xc0ec: 0x0000
pops
0xc0ee: 0x4534 mov.w @r5+, r4 cycles: 2
INEXT
0xc0f0: 0x4630 mov.w @r6+, PC cycles: 3
; @ ( a -- w )
; Push memory location to the data stack.
.dw STORE-2
.db 1,"@"
AT:
mov.w @tos,tos
0xc0f6: 0x4424 mov.w @r4, r4 cycles: 2
INEXT
0xc0f8: 0x4630 mov.w @r6+, PC cycles: 3
; C! ( c b -- )
; Pop the data stack to byte memory.
.dw AT-2
.db 2,"C!",0
CSTOR:
mov.b @stack+,0(tos)
0xc100: 0x45f4 mov.b @r5+, 0(r4) cycles: 5
0xc102: 0x0000
inc stack
0xc104: 0x5315 add.w #1, r5 cycles: 1
pops
0xc106: 0x4534 mov.w @r5+, r4 cycles: 2
INEXT
0xc108: 0x4630 mov.w @r6+, PC cycles: 3
; C@ ( b -- c )
; Push byte memory location to the data stack.
.dw CSTOR-4
.db 2,"C@",0
CAT:
mov.b @tos,tos
0xc110: 0x4464 mov.b @r4, r4 cycles: 2
INEXT
0xc112: 0x4630 mov.w @r6+, PC cycles: 3
; RP! ( -- )
; init return stack pointer.
; .dw CAT-4
; .db 3,"RP!"
RPSTO:
mov #RPP,SP ;init return stack
0xc114: 0x4031 mov.w #0x03f8, SP cycles: 2
0xc116: 0x03f8
INEXT
0xc118: 0x4630 mov.w @r6+, PC cycles: 3
; R> ( -- w )
; Pop the return stack to the data stack.
.dw CAT-4
.db 2,"R",3EH,0
RFROM:
pushs
0xc120: 0x8325 sub.w #2, r5 cycles: 1
0xc122: 0x4485 mov.w r4, 0(r5) cycles: 4
0xc124: 0x0000
pop tos
0xc126: 0x4134 pop.w r4 -- mov.w @SP+, r4 cycles: 2
INEXT
0xc128: 0x4630 mov.w @r6+, PC cycles: 3
; R@ ( -- w )
; Copy top of return stack to the data stack.
.dw RFROM-4
.db 2,"R@",0
RAT:
pushs
0xc130: 0x8325 sub.w #2, r5 cycles: 1
0xc132: 0x4485 mov.w r4, 0(r5) cycles: 4
0xc134: 0x0000
mov 0(sp),tos
0xc136: 0x4114 mov.w 0(SP), r4 cycles: 3
0xc138: 0x0000
INEXT
0xc13a: 0x4630 mov.w @r6+, PC cycles: 3
; >R ( w -- )
; Push the data stack to the return stack.
.dw RAT-4
.db COMPO+2,">R",0
TOR:
push tos
0xc142: 0x1204 push.w r4 cycles: 3
pops
0xc144: 0x4534 mov.w @r5+, r4 cycles: 2
INEXT
0xc146: 0x4630 mov.w @r6+, PC cycles: 3
; SP! ( -- )
; Init data stack pointer.
; .dw SPAT-4
; .db 3,"SP!"
SPSTO:
mov #SPP,stack ;init parameter stack
0xc148: 0x4035 mov.w #0x0378, r5 cycles: 2
0xc14a: 0x0378
clr tos
0xc14c: 0x4304 mov.w #0, r4 cycles: 1
INEXT
0xc14e: 0x4630 mov.w @r6+, PC cycles: 3
; DROP ( w -- )
; Discard top stack item.
.dw TOR-4
.db 4,"DROP",0
DROP:
pops
0xc158: 0x4534 mov.w @r5+, r4 cycles: 2
INEXT
0xc15a: 0x4630 mov.w @r6+, PC cycles: 3
; DUP ( w -- w w )
; Duplicate the top stack item.
.dw DROP-6
.db 3,"DUP"
DUPP:
pushs
0xc162: 0x8325 sub.w #2, r5 cycles: 1
0xc164: 0x4485 mov.w r4, 0(r5) cycles: 4
0xc166: 0x0000
INEXT
0xc168: 0x4630 mov.w @r6+, PC cycles: 3
; SWAP ( w1 w2 -- w2 w1 )
; Exchange top two stack items.
.dw DUPP-4
.db 4,"SWAP",0
SWAP:
mov.w tos,temp0
0xc172: 0x4407 mov.w r4, r7 cycles: 1
mov.w @stack,tos
0xc174: 0x4524 mov.w @r5, r4 cycles: 2
mov.w temp0,0(stack)
0xc176: 0x4785 mov.w r7, 0(r5) cycles: 4
0xc178: 0x0000
INEXT
0xc17a: 0x4630 mov.w @r6+, PC cycles: 3
; OVER ( w1 w2 -- w1 w2 w1 )
; Copy second stack item to top.
.dw SWAP-6
.db 4,"OVER",0
OVER:
mov.w @stack,temp0
0xc184: 0x4527 mov.w @r5, r7 cycles: 2
pushs
0xc186: 0x8325 sub.w #2, r5 cycles: 1
0xc188: 0x4485 mov.w r4, 0(r5) cycles: 4
0xc18a: 0x0000
mov.w temp0,tos
0xc18c: 0x4704 mov.w r7, r4 cycles: 1
INEXT
0xc18e: 0x4630 mov.w @r6+, PC cycles: 3
; 0< ( n -- t )
; Return true if n is negative.
.dw OVER-6
.db 2,"0",3CH,0
ZLESS:
tst tos
0xc196: 0x9304 cmp.w #0, r4 cycles: 1
jn TRUE
0xc198: 0x3002 jn 0xc19e (offset: 4) cycles: 2
FALSE:
clr tos
0xc19a: 0x4304 mov.w #0, r4 cycles: 1
INEXT
0xc19c: 0x4630 mov.w @r6+, PC cycles: 3
TRUE:
mov #0x-1,tos
0xc19e: 0x4334 mov.w #-1, r4 cycles: 1
INEXT
0xc1a0: 0x4630 mov.w @r6+, PC cycles: 3
; AND ( w w -- w )
; Bitwise AND.
.dw ZLESS-4
.db 3,"AND"
ANDD:
and @stack+,tos
0xc1a8: 0xf534 and.w @r5+, r4 cycles: 2
INEXT
0xc1aa: 0x4630 mov.w @r6+, PC cycles: 3
; OR ( w w -- w )
; Bitwise inclusive OR.
.dw ANDD-4
.db 2,"OR",0
ORR:
bis @stack+,tos
0xc1b2: 0xd534 bis.w @r5+, r4 cycles: 2
INEXT
0xc1b4: 0x4630 mov.w @r6+, PC cycles: 3
; XOR ( w w -- w )
; Bitwise exclusive OR.
.dw ORR-4
.db 3,"XOR"
XORR:
xor @stack+,tos
0xc1bc: 0xe534 xor.w @r5+, r4 cycles: 2
INEXT
0xc1be: 0x4630 mov.w @r6+, PC cycles: 3
; UM+ ( w w -- w cy )
; Add two numbers, return the sum and carry flag.
.dw XORR-4
.db 3,"UM+"
UPLUS:
add @stack,tos
0xc1c6: 0x5524 add.w @r5, r4 cycles: 2
mov tos,0(stack)
0xc1c8: 0x4485 mov.w r4, 0(r5) cycles: 4
0xc1ca: 0x0000
clr tos
0xc1cc: 0x4304 mov.w #0, r4 cycles: 1
rlc tos
0xc1ce: 0x6404 addc.w r4, r4 cycles: 1
INEXT
0xc1d0: 0x4630 mov.w @r6+, PC cycles: 3
;; Common functions
; ?DUP ( w -- w w | 0 )
; Dup tos if its is not zero.
.dw UPLUS-4
.db 4,"?DUP",0
QDUP:
tst tos
0xc1da: 0x9304 cmp.w #0, r4 cycles: 1
jnz DUPP
0xc1dc: 0x23c2 jne 0xc162 (offset: -124) cycles: 2
INEXT
0xc1de: 0x4630 mov.w @r6+, PC cycles: 3
; ROT ( w1 w2 w3 -- w2 w3 w1 )
; Rot 3rd item to top.
.dw QDUP-6
.db 3,"ROT"
ROT:
mov.w 0(stack),temp0
0xc1e6: 0x4517 mov.w 0(r5), r7 cycles: 3
0xc1e8: 0x0000
mov.w tos,0(stack)
0xc1ea: 0x4485 mov.w r4, 0(r5) cycles: 4
0xc1ec: 0x0000
mov.w 2(stack),tos
0xc1ee: 0x4514 mov.w 2(r5), r4 cycles: 3
0xc1f0: 0x0002
mov.w temp0,2(stack)
0xc1f2: 0x4785 mov.w r7, 2(r5) cycles: 4
0xc1f4: 0x0002
INEXT
0xc1f6: 0x4630 mov.w @r6+, PC cycles: 3
; 2DROP ( w w -- )
; Discard two items on stack.
.dw ROT-4
.db 5,"2DROP"
DDROP:
incd.w stack
0xc200: 0x5325 add.w #2, r5 cycles: 1
pops
0xc202: 0x4534 mov.w @r5+, r4 cycles: 2
INEXT
0xc204: 0x4630 mov.w @r6+, PC cycles: 3
; 2DUP ( w1 w2 -- w1 w2 w1 w2 )
; Duplicate top two items.
.dw DDROP-6
.db 4,"2DUP",0
DDUP:
mov.w @stack,temp0
0xc20e: 0x4527 mov.w @r5, r7 cycles: 2
pushs
0xc210: 0x8325 sub.w #2, r5 cycles: 1
0xc212: 0x4485 mov.w r4, 0(r5) cycles: 4
0xc214: 0x0000
decd.w stack
0xc216: 0x8325 sub.w #2, r5 cycles: 1
mov.w temp0,0(stack)
0xc218: 0x4785 mov.w r7, 0(r5) cycles: 4
0xc21a: 0x0000
INEXT
0xc21c: 0x4630 mov.w @r6+, PC cycles: 3
; + ( w w -- sum )
; Add top two items.
.dw DDUP-6
.db 1,"+"
PLUS:
add @stack+,tos
0xc222: 0x5534 add.w @r5+, r4 cycles: 2
INEXT
0xc224: 0x4630 mov.w @r6+, PC cycles: 3
; D+ ( d d -- d )
; Double addition, as an example using UM+.
;
.dw PLUS-2
.db 2,"D+",0
DPLUS:
mov.w @stack+,temp0
0xc22c: 0x4537 mov.w @r5+, r7 cycles: 2
mov.w @stack+,temp1
0xc22e: 0x4538 mov.w @r5+, r8 cycles: 2
add.w temp0,0(stack)
0xc230: 0x5785 add.w r7, 0(r5) cycles: 4
0xc232: 0x0000
addc temp1,tos
0xc234: 0x6804 addc.w r8, r4 cycles: 1