FVM - Definitions Glossary

Forth-like for the TI MSP430

Currently under heavy development.

Unstable and Unfinished
Software and Documentation

 

 

Others Documents

Forth VM

16-bits Parameters Stack

32-bits Parameters Stack

16-bits integer arithmetic

32-bits Integer Arithmetic

16-bits Integer Logical

16-bits Integer Memory

Flash operations

 

 

Others Documents

FVM: Forth-like VM for the MSP430

Inside FVM

Forth VM

Definition

Parameters
Stack

Remark

MSP430
Cycles

Description

(:)

( --- )

Runtime only

6

Runtime for : (colon definition)

(;)

( --- )

Runtime only

4

Runtime for ; (end of a colon definition)

(BRANCH)

( --- )

Runtime only

4

Unconditional relative branch

(0BRANCH)

(f --- )

Runtime only

no branch: 9
branch: 8

Conditional relative branch: branch if f=0

(==0BRANCH)

(n1 n2 --- )

Runtime only

no branch: 10
branch: 9

Conditional relative branch: branch if the top two 16-bits
values are equal

(1BRANCH)

(f --- )

Runtime only

no branch: 9
branch: 8

Conditional relative branch: branch if f is not 0

NOP

( --- )

 

3

No OPeration

(cold)

( --- )

 

 

Perform a cold restart

(warm)

( --- )

 

 

Perform a warm restart

Code for the Forth VM is here (MSP430) and also here (x86 Linux).

16-bits Parameters Stack

Definition

Parameters
Stack

Remark

MSP430
Cycles

Description

(LIT)

( --- n1)

Runtime only

4

Push on the stack a 16-bits literal

SP!

(… --- )

 

4

Empty the stack

DEPTH

(… --- n)

 

6

Number of 16-bits numbers on the stack

SWAP

(n1 n2 --- n2 n1)

 

14

Exchange the top 16-bits two values on stack

DUP

(n --- n n)

 

4

Duplicate the 16-bits value on top of the stack

OVER

(n1 n2 --- n1 n2 n2)

 

5

Duplicate the 16-bits value under the top of the stack

ABOVE

(n1 n2 n3 --- n1 n2 n3 n1)

 

5

Duplicate the 16-bits value under under the top of the stack

TUCK

(n1 n2 --- n2 n1 n2)

 

14

SWAP OVER

DROP

(n --- )

 

3

Discard the 16-bits value from the top of the stack

UNDER

(n1 n2 --- n2)

 

7

Discard the 16-bits value under the top of the stack

BELOW

(n1 n2 n3 --- n2 n3)

 

13

Discard the 16-bits value under under the top of the stack

ROT

(n1 n2 n3 --- n2 n3 n1)

 

20

Rotate the top three 16-bits value on top of the stack

-ROT

(n1 n2 n3 --- n3 n1 n2)

 

20

Rotate the top three 16-bits value on top of the stack

Code for Stack Operations (16-bits) is here (MSP430) and also here (x86 Linux).

32-bits Parameters Stack

Definition

Parameters
Stack

Remark

MSP430
Cycles

Description

(DLIT)

( --- d1)

Runtime only

15

Push on the stack a 36-bits literal

DSWAP

(d1 d2 --- d2 d1)

 

28

Exchange the top two 32-bits values on stack

DDUP

(d --- d d)

 

18

Duplicate the 32-bits value on top of the stack

DOVER

(d1 d2 --- d1 d2 d2)

 

19

Duplicate the 32-bits value under the top of the stack

DABOVE

(d1 d2 d3 --- d1 d2 d3 d1)

 

19

Duplicate the 32-bits value under under the top of the stack

DTUCK

(d1 d2 --- d2 d1 d2)

 

37

DSWAP DOVER

DDROP

(d --- )

 

3

Discard the 32-bits value from the top of the stack

DUNDER

(d1 d2 --- d2)

 

12

Discard the 32-bits value under the top of the stack

DBELOW

(d1 d2 d3 --- d2 d3)

 

26

Discard the 32-bits value under under the top of the stack

DROT

(d1 d2 d3 --- d2 d3 d1)

 

45

Rotate the top three 32-bits value on top of the stack

-DROT

(d1 d2 d3 --- d3 d1 d2)

 

45

Rotate the top three 32-bits value on top of the stack

Code for Stack Operations (32-bits) is here (MSP430) and also here (x86 Linux).

16-bits Return Stack

Definition

Parameters
Stack

Return
Stack

Remark

MSP430
Cycles

Description

 

 

 

 

 

 

RP!

 

(… --- )

 

4

Empty the return stack

>R

(n --- )

( --- n)

 

6

Push a value to the return stack

R>

( --- n)

(n --- )

 

9

Pop a value from the return stack.

R

( --- n)

(n --- n)

 

9

Push onto the parameters stack the value from the top of the return stack

RDROP

 

(n --- )

 

4

Discard the value on top of the return stack

(do)

(n1 n2 --- )

( --- n1 n2)

Runtime only

Can do: 20
no loop: 12

Runtime for DO: n1:limit n2:index

(loop)

 

(n1 n2 --- n1 n3)

Runtime only

16

Runtime for LOOP:

(+loop)

(n --- )

(n1 n2 --- n1 n3)

Runtime only

16

Runtime for +LOOP:

(lit+loop)

 

(n1 n2 --- n1 n3)

Runtime only

7

Runtime for +LOOP (with a compiled literal value):

(J)

( --- n)

(n1 n2 n3 n4 --- n1 n2 n3 n4)

 

10

 

(K)

( --- n)

(n1 n2 n3 n4 n5 n6 --- n1 n2 n3 n4 n5 n6)

 

10

 

(local)

 

( --- n1 n2 … )

Runtime only

5

 

(leave)

 

(n1 n2 … --- )

Runtime only

4

 

Code for Stack Operations (16-bits) is here (MSP430) and also here (x86 Linux).

16-bits Integer Arithmetic

Definition

Parameters
Stack

Remark

MSP430
Cycles

Operation

Description

+

(n1 n2 --- n3)

 

7

n3 = n1 + n2

Addition

(lit+)

(n1 --- n2)

Runtime only

7

n2 = *ip++ + n2

Addition

NEGATE

(n1 --- n2)

 

10

n2 = -n1

Two complement

-

(n1 n2 --- n3)

 

7

n3 = n1 – n2

Subtraction

(lit-)

(n1 --- n2)

Runtime only

7

n2 = *ip++ - n2

Subtraction

U*

(u1 u2 --- u3)

Software multiply

160 (medium)

u3 = u1 * u2

Multiply

MU*

(u1 u2 --- d)

Software multiply

160 (medium)

d = u1 * u2

Multiply

*

(n1 n2 --- n3)

Software multiply

160 (medium)

n3 = n1 * n2

Multiply

M*

(n1 n2 --- d)

Software multiply

160 (medium)

d = n1 * n2

Multiply

U/

(u1 u2 --- u3)

Software Division

237 (medium)

u3 = u1 / u2

Division

U/MOD

(u1 u2 --- u3 u4)

Software Division

237 (medium)

u3 = u3 % u3
u4 = u1 / u2

Division

/

(n1 n2 --- n3)

Software Division

237 (medium)

u3 = u1 / u2

Division

/MOD

(n1 n2 --- u3 u4)

Software Division

237 (medium)

u3 = u3 % u3
u4 = u1 / u2

Division

Code for Integer Arithmetic (16-bits) is here (MSP430) and also here (x86 Linux).

32-bits Integer Arithmetic

Definition

Parameters
Stack

Remark

CPU
Cycles

Operation

Description

D+

(d1 d2 --- d3)

 

12

d3 = d1 + d2

Addition

(lit+)