OSDN Git Service

V201, added MSP-EXP430FR2433
[fast-forth/master.git] / forthMSP430FR_ASM.asm
index f12c558..53b3333 100644 (file)
@@ -120,41 +120,48 @@ ASSEMBLER_BODY  .word   lastasmword ; here is the structure created by VOCABULAR
                 .word   voclink
 voclink         .set    $-2
 
-             FORTHWORDIMM "HI2LO"    ; immediate, switch to low level, add ASSEMBLER context, set interpretation state
+             FORTHWORDIMM "HI2LO"   ; immediate, switch to low level, add ASSEMBLER context, set interpretation state
             mDOCOL
-            .word   HERE,CELLPLUS,COMMA
+HI2LO       .word   HERE,CELLPLUS,COMMA
             .word   LEFTBRACKET
 HI2LONEXT   .word   ALSO,ASSEMBLER
             .word   EXIT
 
-           FORTHWORD "CODE"    ;
-ASMCODE     CALL #HEADER        ; same as ":" ...
-            SUB #4,&DDP         ; ...but compile nothing
+;             FORTHWORDIMM "SEMIC"   ; same as HI2LO, plus restore IP; counterpart of COLON
+;            mDOCOL
+;            .word   HI2LO
+;            .word   LIT,413Dh,COMMA ; compile MOV @RSP+,IP
+;            .word   EXIT
+
+           FORTHWORD "CODE"     ; a CODE word must be finished with ENDCODE
+ASMCODE     CALL #HEADER        ;
+            SUB #4,&DDP         ;
             mDOCOL
             .word   SAVE_PSP
             .word   BRAN,HI2LONEXT
 
 
+            asmword "ENDCODE"   ; restore previous context and test PSP balancing
+ENDCODE     mDOCOL
+            .word   PREVIOUS,QREVEAL
+            .word   EXIT
+
             FORTHWORD "ASM"     ; used to define an assembler word which is not executable by FORTH interpreter
                                 ; i.e. typically an assembler word called by CALL and ended by RET
-                                ; ASM word is only accessible in ASSEMBLER CONTEXT
+                                ; ASM words are only usable in another ASSEMBLER words
+                                ; an ASM word must be finished with ENDASM
             MOV     &CURRENT,&ASM_CURRENT
             MOV     #ASSEMBLER_BODY,&CURRENT
             JMP     ASMCODE
 
-            asmword "ENDCODE"   ; restore previous context and test PSP balancing
-ENDCODE     mDOCOL
-            .word   PREVIOUS,QREVEAL
-            .word   EXIT
-
-            asmword "ENDASM"    ; end of ASM word
+            asmword "ENDASM"    ; end of an ASM word
             MOV     &ASM_CURRENT,&CURRENT
             JMP     ENDCODE
 
 
             asmword "COLON"     ; compile DOCOL, remove ASSEMBLER from CONTEXT, switch to compilation state
             MOV &DDP,W
-            
+
     .SWITCH DTC
     .CASE 1
             MOV #DOCOL1,0(W)    ; compile CALL xDOCOL
@@ -218,9 +225,10 @@ SKIPEND:    MOV     W,TOS               ; -- addr
 ; Search ARG of <sep>"xxxx(REG)"            ; <== PARAM210
 SearchARG   ASMtoFORTH                      ; -- separator      search word first
             .word   WORDD,FIND              ; -- c-addr
-            .word   ZEROEQUAL
-            .word   QBRAN,SearchARGW        ; -- c-addr         if found
-            .word   QNUMBER                 ;           
+;            .word   ZEROEQUAL
+;            .word   QBRAN,SearchARGW        ; -- c-addr         if found
+            .word   QZBRAN,SearchARGW        ; -- c-addr         if found
+            .word   QNUMBER                 ;
             .word   QBRAN,NotFound          ; -- c-addr
             .word   AsmSrchEnd              ; -- value          end if number found
 SearchARGW  FORTHtoASM                      ; -- xt
@@ -231,13 +239,13 @@ QDOVAR      CMP     #DOVAR,X
             MOV     @RSP+,PC                ; ret
 QDOCON      CMP     #DOCON,X
             JNZ     QDODOES
-            MOV     2(TOS),TOS              ; remplace CFA by [PFA] for CONSTANT and CREATE words
+            MOV     2(TOS),TOS              ; remplace CFA by [PFA] for CONSTANT (and CREATEd) words
             MOV     @RSP+,PC                ; ret
 QDODOES     CMP     #DODOES,X
             JNZ     AsmSrchEnd
             ADD     #4,TOS                  ; leave BODY for DOES words (but don't execute !)
 AsmSrchEnd  RET                             ;
-            
+
 ; ----------------------------------------------------------------------
 ; DTCforthMSP430FR5xxx ASSEMBLER : search REG
 ; ----------------------------------------------------------------------
@@ -260,7 +268,7 @@ StoARGsearchREG
 SearchREG   PUSH    &TOIN                   ; -- separator  save >IN
             ADD     #1,&TOIN                ;               skip "R"
             ASMtoFORTH                      ;               search xx of Rxx
-            .word   WORDD,QNUMBER           ;    
+            .word   WORDD,QNUMBER           ;
             .word   QBRAN,notREG            ; -- xxxx       if number found
             FORTHtoASM                      ; -- c-addr     if number not found
             ADD     #2,RSP                  ;           remove >IN
@@ -272,7 +280,7 @@ notREG      FORTHtoASM                      ; -- c-addr
             MOV     @RSP+,&TOIN             ; -- c-addr          restore >IN
             BIS     #Z,SR                   ;           Z=1 ==> not found
             MOV     @RSP+,PC                ; -- c_addr
-            
+
 ; ----------------------------------------------------------------------
 ; DTCforthMSP430FR5xxx ASSEMBLER : INTERPRET FIRST OPERAND
 ; ----------------------------------------------------------------------
@@ -333,7 +341,7 @@ PARAM10M1   CMP #-1,TOS                     ; -- xxxx       = -1 ?
 
 ; case of all others "#xxxx"<sep>           ; -- xxxx
 PARAM1000   MOV #0030h,&ASMTYPE             ; -- xxxx       add immediate code type : @PC+,
-            
+
 ; case of "&xxxx"<sep>                      ; <== PARAM110
 ; case of <sep>"&xxxx"                      ; <== PARAM20
 StoreArg    MOV &DDP,X                      ; -- xxxx
@@ -357,7 +365,7 @@ PARAM110    MOV     #0210h,&ASMTYPE         ; -- sep        set code type : xxxx
 ; case of "&xxxx"<sep>
 ; case of <sep>"&xxxx"                      ; <== PARAM20
 PARAM111    ADD     #1,&TOIN                ; -- sep        skip "&" prefix
-            PUSH    #StoreArg               ;               prepare next ret : compile xxxx then ret                
+            PUSH    #StoreArg               ;               prepare next ret : compile xxxx then ret
             JMP     SearchARG               ; -- sep        abort if not found
 ; ------------------------------------------
 
@@ -415,7 +423,7 @@ PARAM130    ADD     #0010h,&ASMTYPE         ;               AS=0b01 for indexing
 
 ; PARAM2     --                             ; parse input buffer until BL and compute this 2th operand
 
-PARAM2      mDOCOL                          ;               
+PARAM2      mDOCOL                          ;
             .word   FBLANK,SKIP             ;               skip space(s) between "arg1," and "arg2" if any
             FORTHtoASM                      ; -- c-addr     search for '&' of "&xxxx
             CMP.B   #'&',0(TOS)             ;
@@ -760,7 +768,7 @@ CODE_JMP    mDOCON                      ; branch always
             mDOCON
             .word   3400h
 
-            asmword "0>="               ; if 0>= assertion  ; use only with IF UNTIL WHILE ! 
+            asmword "0>="               ; if 0>= assertion  ; use only with IF UNTIL WHILE !
             mDOCON
             .word   3000h
 
@@ -809,7 +817,7 @@ ASM_THEN1   MOV     @PSP+,TOS           ; --
 ;C ELSE     @OPCODE1 -- @OPCODE2    branch for IF..ELSE
             asmword "ELSE"
 ASM_ELSE    MOV     &DDP,W              ; --        W=HERE
-            MOV     #3C00h,0(W)         ;           compile unconditionnal branch 
+            MOV     #3C00h,0(W)         ;           compile unconditionnal branch
             ADD     #2,&DDP             ; --        DP+2
             SUB     #2,PSP
             MOV     W,0(PSP)            ; -- dst
@@ -868,7 +876,7 @@ JUMP        mDOCOL
             .word   ASM_UNTIL,EXIT
 
 
-; invert FORTH conditionnal branch      FORTH_JMP_OPCODE -- LABEL_JMP_OPCODE      
+; invert FORTH conditionnal branch      FORTH_JMP_OPCODE -- LABEL_JMP_OPCODE
 INVJMP      BIT #1000h,TOS  ; 3xxxh case ?
             JNZ INVJMP3xxxh ; yes
 INVJMP2xxxh XOR #0400h,TOS  ; no: case of JNE/JNZ JEQ/JZ JNC/JLO JC/JHS
@@ -879,7 +887,7 @@ INVJMP3xxxh CMP #3400h,TOS
 INVJMP3800h MOV #3400h,TOS  ; not jump if >= --> jump if <
             mNEXT
 INVJMP3400h MOV #3800h,TOS  ; not jump if <  --> jump if >=
-INVJMPEND   mNEXT           
+INVJMPEND   mNEXT
 
 
 ;ASM    <cond> ?JMP <word>  ;  OPCODE --       conditionnal branch to a previous definition
@@ -899,7 +907,7 @@ BACKWARDDOES        ;
     MOV @RSP+,IP
     MOV TOS,Y
     MOV @PSP+,TOS
-    MOV @Y,W        ;               W = [PFA]   
+    MOV @Y,W        ;               W = [PFA]
     CMP #0,W        ;               W = 0 ?
     JNZ BACKWUSE
 BACKWSET            ; --
@@ -911,19 +919,19 @@ BACKWUSE            ; -- OPCODE
 
 ; backward label 1
             asmword "BW1"
-            mdodoes 
+            mdodoes
             .word BACKWARDDOES
 CLRBW1      .word 0
 
 ; backward label 2
             asmword "BW2"
-            mdodoes 
+            mdodoes
             .word BACKWARDDOES
 CLRBW2      .word 0
 
 ; backward label 3
             asmword "BW3"
-            mdodoes 
+            mdodoes
             .word BACKWARDDOES
 CLRBW3      .word 0
 
@@ -947,19 +955,19 @@ FORWUSE             ; PFA -- @OPCODE
 
 ; forward label 1
             asmword "FW1"
-            mdodoes 
+            mdodoes
             .word FORWARDDOES
 CLRFW1      .word 0
 
 ; forward label 2
             asmword "FW2"
-            mdodoes 
+            mdodoes
             .word FORWARDDOES
 CLRFW2      .word 0
 
 ; forward label 3
             asmword "FW3"
-            mdodoes 
+            mdodoes
             .word FORWARDDOES
 CLRFW3      .word 0
 
@@ -978,37 +986,3 @@ CLRFW3      .word 0
 
 
 
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-