OSDN Git Service

bug bug bug...
[fast-forth/master.git] / MSP430_FORTH / TESTASM.F
1 \ -----------------------------------------------------------------------
2 \ File Name TestASM.f
3 \ -----------------------------------------------------------------------
4
5 \ TARGET SELECTION
6 \ MSP_EXP430FR5739  MSP_EXP430FR5969    MSP_EXP430FR5994    MSP_EXP430FR6989
7 \ MSP_EXP430FR4133  CHIPSTICK_FR2433
8
9 \ MY_MSP430FR5738_1 MY_MSP430FR5738     MY_MSP430FR5948     MY_MSP430FR5948_1   
10 \ JMJ_BOX
11
12
13
14
15 ECHO
16
17 \ -----------------------------------------------------------------------
18 \ test CPUx instructions PUSHM, POPM, RLAM, RRAM, RRCM, RRUM
19 \ -----------------------------------------------------------------------
20 CODE TESTPUSHM
21             MOV     #22222,Y
22             MOV     #3,X
23             MOV     #2,W
24             MOV     #1,T
25             MOV     #0,S
26 \            PUSHM   Y,IP       \ uncomment to test error (registers bad order) 
27             PUSHM   IP,W        \ PUSHM order : PSP,TOS,IP,S,T,W,X,Y,rEXIT,rDOVAR,rDOCON,rDODOES
28             POPM    W,IP        \ POPM order  : rDODOES,rDOCON,rDOVAR,rEXIT,Y,X,W,T,S,IP,TOS,PSP
29             SUB     #10,PSP
30             MOV     TOS,8(PSP)  \ save old TOS
31             MOV     S,6(PSP)
32             MOV     T,4(PSP)
33             MOV     W,2(PSP)
34             MOV     X,0(PSP)
35             MOV     Y,TOS
36 \            RLAM    #0,TOS     \ uncomment to test error (bad shift value)
37             RRAM    #1,TOS      \ 0 < shift value < 5
38             RLAM    #2,TOS
39             RRCM    #1,TOS
40             RRUM    #1,TOS
41             COLON               \ high level part of the word starts here...
42             space . . . . .
43             ;                   \ and finishes here.
44     \
45 TESTPUSHM  ; you should see 11111 3 2 1 0 -->
46
47 CODE TESTPOPM
48             MOV     #22222,Y
49             MOV     #3,X
50             MOV     #2,W
51             MOV     #1,T
52             MOV     #0,S
53 \            PUSHM   W,IP        \ uncomment to test error "out of bounds" 
54             PUSHM   IP,W        \ PUSHM order : PSP,TOS,IP,S,T,W,X,Y,rEXIT,rDOVAR,rDOCON,rDODOES
55             POPM    W,IP        \ POPM order  : rDODOES,rDOCON,rDOVAR,rEXIT,Y,X,W,T,S,IP,TOS,PSP
56             SUB     #10,PSP
57             MOV     TOS,8(PSP)  \ save old TOS
58             MOV     S,6(PSP)
59             MOV     T,4(PSP)
60             MOV     W,2(PSP)
61             MOV     X,0(PSP)
62             MOV     Y,TOS
63 \            RLAM    #0,TOS      \ uncomment to test error "out of bounds" 
64 \            RLAM    #5,TOS      \ uncomment to test error "out of bounds" 
65             RRAM    #1,TOS      \ 0 < shift value < 5
66             RLAM    #2,TOS
67             RRCM    #1,TOS
68             RRUM    #1,TOS
69             COLON               \ high level part of the word starts here...
70             space . . . . .
71             ;                   \ and finishes here.
72     \
73 TESTPOPM  ; you should see 11111 3 2 1 0 -->
74
75
76
77 \ -----------------------------------------------------------------------
78 \ test symbolic branch in assembler
79 \ test a FORTH section encapsulated in an assembly word
80 \ -----------------------------------------------------------------------
81 CODE TEST1                  \ the word "CODE" add ASSEMBLER as CONTEXT vocabulary...
82
83             MOV &BASE,&BASE \ to test &xxxx src operand
84             CMP #%10,&BASE
85 0<> IF      MOV #2,&BASE    \ if base <> 2
86 ELSE        MOV #$0A,&BASE  \ else base = 2
87 THEN        
88             COLON           \ tips : no "ok" displayed in start of line <==> compilation mode
89             BASE @ U.       \ always display 10 !
90             ;
91     \
92
93 \ -----------------------------------------------------------------------
94 \ test a word that starts as word FORTH and ends as assembly word
95 \ -----------------------------------------------------------------------
96 : TEST2                     \ ":" starts compilation
97             BASE @ U.       \ always display 10 !
98             HI2LO           \ switch FORTH to ASM : compile one word (next address)
99                             \                       add vocabulary ASSEMBLER as CONTEXT vocabulary
100                             \                       switch in interpret mode
101             CMP #2, &BASE
102 0<> IF      MOV #2, &BASE   \ if variable system BASE <> 2
103 ELSE        MOV #10,&BASE   \ else (BASE = 2)
104 THEN
105 \           MOV #EXIT,PC    \ to pair with ":" i.e. to restore IP saved by : then execute NEXT. 
106 \ but even compile two words, it's better to compile an inline EXIT :
107             MOV @RSP+,IP    \ restore IP
108             MOV @IP+,PC     \ = NEXT
109 ENDCODE                     \ ends assembler : remove vocabulary ASSEMBLER from CONTEXT
110     \
111
112 \ -----------------------------------------------------------------------
113 \ test a word that starts as assembly word and ends as FORTH word
114 \ -----------------------------------------------------------------------
115 CODE TEST3                  \ "CODE" starts assembler, i.e. add ASSEMBLER as CONTEXT vocabulary
116             CMP #2, &BASE
117 0<> IF      MOV #2, &BASE   \ if variable system BASE <> 2
118 ELSE        MOV #10,&BASE   \ else (BASE = 2)
119 THEN        COLON           \
120             BASE @  U.      \ always display 10 !
121 ;                           \
122     \
123
124
125 \ -----------------------------------------------------------------------
126 \ test an assembly jump spanning a section written in FORTH
127 \ -----------------------------------------------------------------------
128 : TEST5
129             SPACE
130             HI2LO
131             SUB #2,PSP
132             MOV TOS,0(PSP)
133             MOV #%1010,TOS  \ init count = 10
134 BEGIN       SUB #$0001,TOS
135             LO2HI
136                             \ IP is already saved by word ":"
137             DUP U.          \ display count
138             HI2LO
139             CMP #0,TOS
140 0= UNTIL    MOV @PSP+,TOS
141 \           MOV #EXIT,PC    \ to pair with ":" i.e. to restore IP saved by : then execute NEXT. 
142             MOV @RSP+,IP    \ restore IP
143             MOV @IP+,PC     \ = NEXT
144 ENDCODE
145     \
146 TEST5  ; you should see :  9 8 7 6 5 4 3 2 1 0 -->
147     \
148
149 \ -----------------------------------------------------------------------
150 \ tests indexing address
151 \ -----------------------------------------------------------------------
152
153 : TABLE
154 CREATE 
155 0 DO I C,
156 LOOP
157 DOES>
158 +
159 ;
160
161 8 TABLE BYTES_TABLE
162     \
163 2 BYTES_TABLE C@ . ; you should see 2 -->
164 \
165
166
167 VARIABLE BYTES_TABLE1
168
169 $0201 BYTES_TABLE1 !              \ words written in memory are little endian !
170
171 CODE IDX_TEST1                     \ index -- value
172     MOV.B   BYTES_TABLE1(TOS),TOS  \ -- value
173 COLON
174     U. 
175 ;      
176
177 0 IDX_TEST1     ; you should see 1 -->
178
179 CODE TEST6
180             MOV 0(PSP),0(PSP)  \
181             MOV @IP+,PC
182 ENDCODE
183
184
185 1 TEST6 .       ; you should see 1 -->
186
187
188 \ -----------------------------------------------------------------------
189 \ tests behaviour of assembly error 
190 \ -----------------------------------------------------------------------
191 \ R16 causes an error, assembler context is aborted and the word TEST7 is "hidden".
192
193 ; CODE TEST7
194 ;            MOV 0(PSP),0(R16)  ; display an error "out of bounds" -->
195
196
197
198
199
200