Dictionary

Stack Jugglers

Single-Jugglers

nip             ( x1 x2 -- x2 )
drop            ( x -- )
rot             ( x1 x2 x3 -- x2 x3 x1 )
-rot            ( x1 x2 x3 -- x3 x1 x2 )
swap            ( x1 x2 -- x2 x1 )
tuck            ( x1 x2 -- x2 x1 x2 )
over            ( x1 x2 -- x1 x2 x1 )
?dup            ( x -- 0 | x x )
dup             ( x -- x x )
>r              ( x -- ) (R: -- x )
r>              ( -- x ) (R: x -- )
r@              ( -- x ) (R: x -- x )
rdrop           (  --  ) (R: x -- )

Double-Jugglers

They perform the same for double numbers.

2drop           ( x1 x2 -- )
2dup            ( x1 x2 -- x1 x2 x1 x2 )
2swap           ( x1 x2 x3 x4 -- x3 x4 x1 x2 )

Logic

arshift         ( x1 u -- x2 ) Arithmetric right-shift of u bit-places
rshift          ( x1 u -- x2 ) Logical right-shift of u bit-places
lshift          ( x1 u -- x2 ) Logical  left-shift of u bit-places
shr             ( x1 -- x2 )   Logical right-shift of one bit-place
shl             ( x1 -- x2 )   Logical  left-shift of one bit-place
ror             ( x1 -- x2 )   Logical right-rotation of one bit-place
rol             ( x1 -- x2 )   Logical  left-rotation of one bit-place
bic             ( x1 x2 -- x3 ) Bit clear, identical to "not and"
not             ( x1 -- x2 )   Invert all bits
xor             ( x1 x2 -- x3 ) Bitwise Exclusive-OR
or              ( x1 x2 -- x3 ) Bitwise OR
and             ( x1 x2 -- x3 ) Bitwise AND
false           ( --  0 ) False-Flag
true            ( -- -1 ) True-Flag
><              ( xy -- yx )   Swap bytes

Arithmetic for single numbers

\*               ( u1|n1 u2|n2 -- u3|n3 ) 16*16 = 16 Multiplication
2*              ( n1 -- n2 ) Arithmetric  left-shift
2/              ( n1 -- n2 ) Arithmetric right-shift
negate          ( n1 -- n2 ) Negate
-               ( u1|n1 u2|n2 -- u3|n3 ) Subtraction
+               ( u1|n1 u2|n2 -- u3|n3 ) Addition

Arithmetic involving double numbers

d2*             ( d1 -- d2 ) Arithmetric  left-shift
d2/             ( d1 -- d2 ) Arithmetric right-shift
dshl            ( ud1 -- ud2 ) Logical left-shift, same as d2*
dshr            ( ud1 -- ud2 ) Logical right-shift
d-              ( ud1|d1 ud2|d2 -- ud3|d3 ) Subtraction
d+              ( ud1|d1 ud2|d2 -- ud3|d3 ) Addition

Arithmetic without special optimisations

abs             ( n -- u ) Absolute value
dabs            ( d -- ud ) Absolute value
dnegate         ( d1 -- d2 ) Negate
s>d             ( n -- d ) Makes a signed single number double length
um*             ( u1 u2 -- ud )  16*16 = 32 Multiplication
um/mod          ( ud u1 -- u2 u3 )     ud / u1 = u3 remainder u2
m*              ( n1 n2 -- d )     n1 * n2 = d
fm/mod          ( d n1 -- n2 n3 )  d / n1 = n3 remainder r2 floored
sm/rem          ( d n1 -- n2 n3 )  d / n1 = n3 remainder r2 symmetric
/mod            ( n1 n2 -- n3 n4 ) n1 / n2 = n4 rem n3
mod             ( n1 n2 -- n3 ) n1 / n2 = remainder n3
/               ( n1 n2 -- n3 ) n1 / n2 = n3
*/              ( n1 n2 n3 -- n4 )     n1 * n2 / n3 = n4
*/mod           ( n1 n2 n3 -- n4 n5 )  n1 * n2 / n3 = n5 remainder n4

Comparisions

u<=             ( u1 u2 -- flag )  Unsigned comparisions
u>=             ( u1 u2 -- flag )
u>              ( u1 u2 -- flag )
u<              ( u1 u2 -- flag )
<=              ( n1 n2 -- flag )    Signed comparisions
>=              ( n1 n2 -- flag )
>               ( n1 n2 -- flag )
<               ( n1 n2 -- flag )
0<              ( n - flag )         Negative ?
0<>             ( x -- flag )
0=              ( x -- flag )
<>              ( x1 x2 -- flag )
=               ( x1 x2 -- flag )

Memory access

cbit@           ( mask c-addr -- flag ) Test BIts in byte-location
bit@            ( mask a-addr -- flag ) Test BIts in word-location
cxor!           ( mask c-addr -- ) Toggle bits in byte-location
xor!            ( mask a-addr -- ) Toggle bits in word-location
cbic!           ( mask c-addr -- ) Clear BIts in byte-location
bic!            ( mask a-addr -- ) Clear BIts in word-location
cbis!           ( mask c-addr -- ) Set BIts in byte-location
bis!            ( mask a-addr -- ) Set BIts in word-location
constant  name  ( u|n -- )  Makes a single constant.
variable  name  ( n|n -- )  Makes an initialized single variable
buffer: name    ( u -- ) Creates a buffer in RAM with u bytes length
@               ( a-addr -- u|n ) Fetches single number from memory
!               ( u|n a-addr -- ) Stores single number in memory
+!              ( u|n a-addr -- ) Add to memory location
c@              ( c-addr -- char ) Fetches byte from memory
c!              ( char c-addr ) Stores byte in memory
c+!             ( u|n a-addr -- ) Add to byte memory location

Flags and inventory

inline          ( -- ) Makes current definition always inlineable.
immediate       ( -- ) Makes current definition immediate.
0-foldable      ( -- ) Current word becomes foldable with zero constants
1-foldable      ( -- ) Current word becomes foldable with one constants
2-foldable      ( -- ) Current word becomes foldable with two constants
3-foldable      ( -- ) Current word becomes foldable with three   constants
...
7-foldable      ( -- ) Current word becomes foldable with seven   constants

Compiler essentials

postpone name   ( -- ) Helps compiling immediate words.
does>           ( -- ) executes: ( -- a-addr ) Gives address to where you have stored data.
<builds         ( -- ) Makes Dictionary header and reserves space for special call.
create name     ( -- ) Create a constant table.
endcreate       ( -- ) Finish a constant table
]               ( -- ) Switch to compile state
[               ( -- ) Switch to execute state
;               ( -- ) Finishes new definition
: name          ( -- ) Opens new definition
,               ( u|n -- ) Appends a single number to dictionary
[char] *        ( -- char) Compiles code of following char when executed
char *          ( -- char ) gives code of following char

Control structures

Decisions:

flag if ... then
flag if ... else ... then

        then            ( -- )           This is the common
        else            ( -- )           flag if ... [else ...] then
        if              ( flag -- )      structure.
        ahead           ( -- )

Case:

n case
     m1   of ... endof
     m2   .. ... .....
     all others
     endcase

        case            ( n -- n )       Begins case structure
        of              ( m -- )         Compares m with n, choose this if n=m
        endof           ( -- )           End of one possibility
        endcase         ( n -- )         Ends case structure, discards n

Indefinite Loops:

begin ... again
begin ... flag until
begin ... flag while ... repeat

        repeat          ( -- ) Finish of a middle-flag-checking loop.

        while           ( flag -- ) Check a flag in the middle of a loop

        until           ( flag -- ) begin ... flag until   loops until flag is true
        again           ( -- )  begin ... again is an endless loop
        begin           ( -- ) is an endless loop


Definite Loops:

limit index   do ... [one or more leave(s)] ... loop
             ?do ... [one or more leave(s)] ... loop

        j               ( -- u|n ) Gives second loop index
        i               ( -- u|n ) Gives innermost loop index


        unloop          (R: old-limit old-index -- )
                        Drops innermost loop structure,
                        pops back old loop structures to loop registers

        exit            ( -- ) Returns from current definition.
                               Compiles a ret opcode.

        leave           ( -- ) (R: old-limit old-index -- )
                        Leaves current innermost loop promptly

        loop            ( -- )
                        (R: unchanged | old-limit old-index -- )
                        Increments current loop index register by one
                        and checks whether to continue or not.

        ?do             ( Limit Index -- )
                        (R: unchanged | -- old-limit old-index )
                        Begins a loop if limit and index are not equal

        do              ( Limit Index -- )
                        (R: -- old-limit old-index )
                        Begins a loop

Reset, Interrupts and Low Power Modes

Including five low power modes.

reset           ( -- ) Reset on hardware level by triggering Watchdog

dint            ( -- ) Disables Interrupts
eint            ( -- ) Enables  Interrupts
ie1             ?
ie2             ?

lpm0            ( -- ) Enter LPM0 and enable IRQs:
                  CPU, MCLK are disabled.
                  SMCLK, ACLK are active

lpm1            ( -- ) Enter LPM1 and enable IRQs:
                  CPU, MCLK are disabled.
                  DCO and DC generator are disabled if
                  the DCO is not used for SMCLK.
                  ACLK is active.

lpm2            ( -- ) Enter LPM2 and enable IRQs:
                  CPU, MCLK, SMCLK, DCO are disabled.
                  DC generator remains enabled.
                  ACLK is active.

lpm3            ( -- ) Enter LPM3 and enable IRQs:
                  CPU, MCLK, SMCLK, DCO are disabled.
                  DC generator disabled.
                  ACLK is active.

lpm4            ( -- ) Enter LPM4 and enable IRQs:
                  CPU and all clocks disabled.

wakeup          ( -- ) Gives the current vector the ability to wake
                       from sleep modes upon return.
                       This is a flag and cannot be used conditionally

Predefined Port Constants

These are simply memory mapped Register Words, just like my svd2forth lists for Mecrisp-Stellaris. However in this case they are preset and ready to use!

From the msp430x2xx-user-guide, December 2010, part number: SLAU144F, page 363

Port Register Short Form Address Register Type
P1 Input P1IN 020h Read only
Output P1OUT 021h Read/write
Direction P1DIR 022h Read/write
Interrupt Flag P1IFG 023h Read/write
Interrupt Edge Select P1IES 024h Read/write
Interrupt Enable P1IE 025h Read/write
Port Select P1SEL 026h Read/write
Port Select 2 P1SEL2 041h Read/write
Resistor Enable P1REN 027h Read/write

From the Terminal in target mode.

hex ok.
P1IN . 20 ok.
P1OUT . 21 ok.
P1DIR . 22 ok.
P1IFG . 35 ok.
P1IES . 36 ok.
P1IE . 37 ok.
P1SEL . 38 ok.
P1REN . 39 ok.
Word-Ports:

ADC10AE0        ( -- a-addr )
ADC10CTL0
ADC10CTL1
ADC10MEM
SD16CTL
SD16CCTL0
SD16IV
SD16MEM0
TACCR1
TACCR0
TAR
TACCTL1
TACCTL0
TACTL
TAIV
FCTL3
FCTL2
FCTL1
WDTCTL

Byte-Ports:

ADC10AE         ( -- c-addr )

SD16INCTL0
SD16AE

USICTL0
USICTL1
USICKCTL
USICNT
USISR

CAPD
CACTL2
CACTL1

BCSCTL3
BCSCTL2
BCSCTL1
DCOCTL

P2REN
P2SEL
P2IE
P2IES
P2IFG
P2DIR
P2OUT
P2IN

P1REN
P1SEL
P1IE
P1IES
P1IFG
P1DIR
P1OUT
P1IN

IFG2
IFG1
IE2
IE1

Clock setup

1MHz            ( -- )      Load DCO calibration values
8MHz            ( -- )
12MHz           ( -- )
16MHz           ( -- )

Terminal-IO

Included for MSP430G2553 and emulation

uart-init       ( -- )      Prepare UART for 9600 Baud @ 8 MHz
emit?           ( -- Flag ) Ready to send a character ?
key?            ( -- Flag ) Checks if a key is waiting
key             ( -- Char ) Waits for and fetches the pressed key
emit            ( Char -- ) Emits a character.
cr              ( -- )      Emits line feed
space           ( -- )      Emits space
hex.            ( u -- )    Prints 16 bit unsigned in hex base.

Target only tools available during development

They run on the TM4C1294 but appear to run on the Target!

words           ( -- ) Prints list of defined words.
list            ( -- ) Prints a short overview of defined words.
.s              ( many -- many ) Prints stack contents, hexadecimal
see name        ( -- ) Insight into definitions
binary          ( -- ) Sets base to 2
decimal         ( -- ) Sets base to 10
hex             ( -- ) Sets base to 16
u.              ( u -- ) Print unsigned single number
.               ( n -- ) Print single number

Previous topic

Compiler Magic: What Happens To Your Source Code ?

Next topic

Installing