
; -----------------------------------------------------
; ANS_COMP.4th    words complement to pass CORETEST.4TH
; -----------------------------------------------------

[UNDEFINED] {ANS_COMP} [IF]

PWR_STATE

MARKER {ANS_COMP}


[UNDEFINED] VARIABLE [IF]

: VARIABLE 
DEFER
HI2LO
MOV @R1+,R13
MOV #$1286,-4(R10)
MOV @R13+,R0
ENDCODE

[THEN]

[UNDEFINED] CONSTANT [IF]
: CONSTANT 
DEFER
HI2LO
MOV @R1+,R13
MOV #$1285,-4(R10)
MOV R14,-2(R10)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE
[THEN]

$1DBE CONSTANT STATE

[UNDEFINED] BASE [IF]
$1DDC CONSTANT BASE
[THEN]

[UNDEFINED] >IN [IF]
$1DC4 CONSTANT >IN
[THEN]

[UNDEFINED] PAD [IF]
$1CE4 CONSTANT PAD
[THEN]

[UNDEFINED] BL [IF]
#32 CONSTANT BL
[THEN]

[UNDEFINED] SPACE [IF]
: SPACE
BL EMIT ;
[THEN]

[UNDEFINED] SPACES [IF]
CODE SPACES
CMP #0,R14
0<> IF
    PUSH R13
    BEGIN
        LO2HI
        BL EMIT
        HI2LO
        SUB #2,R13 
        SUB #1,R14
    0= UNTIL
    MOV @R1+,R13
THEN
MOV @R15+,R14
MOV @R13+,R0              
ENDCODE
[THEN]


: VALUE
CREATE ,
DOES> 
HI2LO
MOV @R1+,R13
BIT #$400,R2
0= IF
    MOV #@,R0
THEN 
BIC #$400,R2
MOV #!,R0
ENDCODE

CODE TO
BIS #$400,R2
MOV @R13+,R0
ENDCODE

: S>D
    DUP 0<
;

[UNDEFINED] NIP [IF]
CODE NIP
ADD #2,R15
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] C@ [IF]
CODE C@
MOV.B @R14,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] C! [IF]
CODE C!
MOV.B @R15+,0(R14)
ADD #1,R15
MOV @R15+,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] C, [IF]
CODE C,
MOV &$1DC6,R10
MOV.B R14,0(R10)
ADD #1,&$1DC6
MOV @R15+,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] AND [IF]
CODE AND
AND @R15+,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] OR [IF]
CODE OR
BIS @R15+,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] XOR [IF]
CODE XOR
XOR @R15+,R14
MOV @R13+,R0
ENDCODE
[THEN]

[UNDEFINED] PLUS [IF]
CODE +
ADD @R15+,R14
MOV @R13+,R0
ENDCODE
[THEN]

CODE INVERT
XOR #-1,R14
MOV @R13+,R0
ENDCODE

CODE <
        SUB @R15+,R14
        S< ?GOTO FW1
    0<> IF
BW1     MOV #-1,R14
    THEN
        MOV @R13+,R0
ENDCODE

CODE >
        SUB @R15+,R14
        S< ?GOTO BW1
FW1     AND #0,R14
        MOV @R13+,R0
ENDCODE

CODE LSHIFT
            MOV @R15+,R10
            AND #$1F,R14
0<> IF
    BEGIN   ADD R10,R10
            SUB #1,R14
    0= UNTIL
THEN        MOV R10,R14
            MOV @R13+,R0
ENDCODE

CODE RSHIFT
            MOV @R15+,R10
            AND #$1F,R14
0<> IF
    BEGIN   BIC #1,R2
            RRC R10
            SUB #1,R14
    0= UNTIL
THEN        MOV R10,R14
            MOV @R13+,R0
ENDCODE

[UNDEFINED] MAX [IF]
CODE MAX
    CMP @R15,R14
    S<  ?GOTO FW1
BW1 ADD #2,R15
    MOV @R13+,R0
ENDCODE

CODE MIN
    CMP @R15,R14
    S< ?GOTO BW1
FW1 MOV @R15+,R14
    MOV @R13+,R0
ENDCODE
[THEN]

CODE 2*
ADD R14,R14
MOV @R13+,R0
ENDCODE

CODE 2/
RRA R14
MOV @R13+,R0
ENDCODE

$1A00 4 + @ $81F3 U<
$81EF $1A00 4 + @ U< 
= [IF]   ; MSP430FR413x subfamily without hardware_MPY

CODE M*
MOV @R15,R12
CMP #0,R12
S< IF
    XOR #-1,0(R15)
    ADD #1,0(R15)
THEN
XOR R14,R12
CMP #0,R14
S< IF
    XOR #-1,R14
    ADD #1,R14
THEN
PUSHM #2,R13
LO2HI
UM*       
HI2LO
POPM #2,R13
CMP #0,R12
S< IF
    XOR #-1,0(R15)
    XOR #-1,R14
    ADD #1,0(R15)
    ADDC #0,R14
THEN
MOV @R13+,R0
ENDCODE

[ELSE]  ; MSP430FRxxxx with hardware_MPY

CODE UM*
    MOV @R15,&$4C0
BW1 MOV R14,&$4C8
    MOV &$4E4,0(R15)
    MOV &$4E6,R14
    MOV @R13+,R0
ENDCODE

CODE M*
    MOV @R15,&$4C2
    GOTO BW1
ENDCODE

[THEN]

CODE UM/MOD
    PUSH #DROP
    MOV #<#,R9
    ADD #8,R9
    MOV R9,R0
ENDCODE

CODE SM/REM
MOV R14,R12
MOV @R15,R11
CMP #0,R14
S< IF
    XOR #-1,R14
    ADD #1,R14
THEN
CMP #0,0(R15)
S< IF
    XOR #-1,2(R15)
    XOR #-1,0(R15)
    ADD #1,2(R15)
    ADDC #0,0(R15)
THEN
PUSHM #3,R13
LO2HI
    UM/MOD
HI2LO
POPM #3,R13
CMP #0,R11
S< IF
    XOR #-1,0(R15)
    ADD #1,0(R15)
THEN
XOR R12,R11
CMP #0,R11
S< IF
BW1
BW2
    XOR #-1,R14
    ADD #1,R14
THEN
MOV @R13+,R0
ENDCODE

CODE NEGATE
GOTO BW1 
ENDCODE

CODE ABS
CMP #0,R14
0< ?GOTO BW2
MOV @R13+,R0
ENDCODE

: FM/MOD
SM/REM
HI2LO
CMP #0,0(R15)
0<> IF
    CMP #1,R14
    S< IF
      ADD R12,0(R15)
      SUB #1,R14
    THEN
THEN
MOV @R1+,R13
MOV @R13+,R0
ENDCODE

: *
M* DROP
;

: /MOD
>R DUP 0< R> FM/MOD
;

: /
>R DUP 0< R> FM/MOD NIP
;

: MOD
>R DUP 0< R> FM/MOD DROP
;

: */MOD
>R M* R> FM/MOD
;

: */
>R M* R> FM/MOD NIP
;


[UNDEFINED] OVER [IF]
CODE OVER
MOV R14,-2(R15)
MOV @R15,R14
SUB #2,R15
MOV @R13+,R0
ENDCODE
[THEN]

CODE ROT
MOV @R15,R10
MOV R14,0(R15)
MOV 2(R15),R14
MOV R10,2(R15)
MOV @R13+,R0
ENDCODE

CODE R@
SUB #2,R15
MOV R14,0(R15)
MOV @R1,R14
MOV @R13+,R0
ENDCODE


[UNDEFINED] {DOUBLE} [IF]

CODE 2@
BW1 SUB #2,R15
    MOV 2(R14),0(R15)
    MOV @R14,R14
    MOV @R13+,R0
ENDCODE

CODE 2!
BW2 MOV @R15+,0(R14)
    MOV @R15+,2(R14)
    MOV @R15+,R14
    MOV @R13+,R0
ENDCODE

: 2VALUE
CREATE , ,
DOES>
HI2LO
MOV @R1+,R13
BIT #$400,R2
0= ?GOTO BW1 
BIC #$400,R2
GOTO BW2
ENDCODE

CODE 2DROP
ADD #2,R15
MOV @R15+,R14
MOV @R13+,R0
ENDCODE

CODE 2SWAP
MOV @R15,R10
MOV 4(R15),0(R15)
MOV R10,4(R15)
MOV R14,R10
MOV 2(R15),R14
MOV R10,2(R15)
MOV @R13+,R0
ENDCODE

CODE 2OVER
SUB #4,R15
MOV R14,2(R15)
MOV 8(R15),0(R15)
MOV 6(R15),R14
MOV @R13+,R0
ENDCODE

[THEN]

CODE ALIGNED
BIT #1,R14
ADDC #0,R14
MOV @R13+,R0
ENDCODE

CODE ALIGN
BIT #1,&$1DC6
ADDC #0,&$1DC6
MOV @R13+,R0
ENDCODE

CODE CHARS
MOV @R13+,R0
ENDCODE

CODE CHAR+
ADD #1,R14
MOV @R13+,R0
ENDCODE

CODE CELLS
ADD R14,R14
MOV @R13+,R0
ENDCODE

CODE CELL+
ADD #2,R14
MOV @R13+,R0
ENDCODE


: CHAR
    BL WORD 1+ C@
;

: [CHAR]
    CHAR POSTPONE LITERAL
; IMMEDIATE

CODE +!
ADD @R15+,0(R14)
MOV @R15+,R14
MOV @R13+,R0
ENDCODE

CODE FILL
MOV @R15+,R9
MOV @R15+,R10
CMP #0,R9
0<> IF
    BEGIN
        MOV.B R14,0(R10)
        ADD #1,R10
        SUB #1,R9
    0= UNTIL
THEN
MOV @R15+,R14
MOV @R13+,R0
ENDCODE


CODE HEX
MOV #$10,&BASE
MOV @R13+,R0
ENDCODE

CODE DECIMAL
MOV #$0A,&BASE
MOV @R13+,R0
ENDCODE

: ( 
$29 WORD DROP
; IMMEDIATE

CODE .(
MOV #0,&$1DB4
COLON
$29 WORD
COUNT TYPE
BL $1DB4 !
; IMMEDIATE

CODE J
SUB #2,R15      
MOV R14,0(R15)
MOV 4(R1),R14
SUB 6(R1),R14
MOV @R13+,R0
ENDCODE

CODE UNLOOP
ADD #4,R1
MOV @R13+,R0
ENDCODE

CODE LEAVE
MOV &$1DC6,R10
MOV #UNLOOP,0(R10)
MOV #.,2(R10)
ADD #8,2(R10)
ADD #6,&$1DC6
ADD #2,&$1C00
ADD #4,R10
MOV &$1C00,R9
MOV R10,0(R9)
MOV @R13+,R0
ENDCODE IMMEDIATE

CODE RECURSE
MOV &$1DC6,R9
MOV &$1DBA,0(R9)
ADD #2,&$1DC6
MOV @R13+,R0
ENDCODE IMMEDIATE

CODE SOURCE
SUB #4,R15
MOV R14,2(R15)
MOV &$1DC0,R14
MOV &$1DC2,0(R15)
MOV @R13+,R0
ENDCODE

RST_HERE

[THEN]

