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+)

(n1 --- n2)

Runtime only

7

n2 = *ip++ + n2

Addition

DNEGATE

(d1 --- d2)

 

18

d2 = -d1

Two complement

D-

(d1 d2 --- d3)

 

12

d3 = d1 – d2

Subtraction

(lit-)

(n1 --- n2)

Runtime only

7

n2 = *ip++ - n2

Subtraction

D*

(d1 d2 --- d3)

Software multiply

160 (medium)

n3 = n1 * n2

Multiply

/

(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 (32-bits) is here (MSP430) and also here (x86 Linux).

16-bits Integer Logical

Definition

Parameters
Stack

Remark

MSP430
Cycles

Operation

Description

AND

(n1 n2 --- n3)

 

7

n3 = n1 & n2

Logical And

OR

(n1 n2 --- n3)

 

7

n3 = n1 ! n2

Logical Or

NEGATE

(n1 n2 --- n3)

 

7

n3 = n1 ^ n2

Logical Xor

==

(n1 n2 --- l)

 

13

l= (n1==n2) ? 1 : 0

Comparison

!=

(n1 n2 --- l)

 

13

l= (n1!=n2) ? 1 : 0

Comparison

< 

(n1 n2 --- l)

 

13

l= (n1< n2) ? 1 : 0

Signed Comparison

<=

(n1 n2 --- l)

 

14

l= (n1<= n2) ? 1 : 0

Signed Comparison

> 

(n1 n2 --- l)

 

14

l= (n1> n2) ? 1 : 0

Signed Comparison

>=

(n1 n2 --- l)

 

13

l= (n1>= n2) ? 1 : 0

Signed Comparison

U<

(u1 u2 --- l)

 

13

l= (u1< u2) ? 1 : 0

Unsigned Comparison

U<

(u1 u2 --- l)

 

14

l= (u1<= u2) ? 1 : 0

Unsigned Comparison

U>

(u1 u2 --- l)

 

14

l= (u1> u2) ? 1 : 0

Unsigned Comparison

U>=

(u1 u2 --- l)

 

13

l= (u1>= u2) ? 1 : 0

Unsigned Comparison

U*

(u1 u2 --- u3)

Software multiply

160 (medium)

 

Comparison

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

16-bits Integer Memory

Definition

Parameters
Stack

Address
Register

Remark

MSP430
Cycles

Operation

Description

(VARIABLE)

( --- )

Write

Runtime only

4

 

Runtime for VARIABLE

(CONSTANT)

( --- n)

 

Runtime only

9

 

Runtime for CONSTANT

>A

(a --- )

Write

 

4

AREG=a

Set the address register

A>

( --- a)

Read

 

8

A=AREG

Get the address register value

+A

(n --- )

Write

 

4

AREG+=n

Set the address register:

@

( --- n)

Read

 

9

n=@AREG

Read the 16-bits value pointed by the Address Register

@+

( --- n)

Read/Write

 

9

n=@AREG ++

Read the 16-bits value pointed by the Address Register,
then increment the Address Register

!

(n --- )

Read

 

7

@AREG =n

Write a 16-bits value at the address pointed by the Address Register

(LIT!)

( --- )

Read

Runtime only
Used by the optimizer

7

@AREG=lit

Write a literal 16-bits value at the address pointed by the Address Register

!+

(n --- )

Read/Write

 

8

@AREG++=n

Increment the 16-bits value pointed by the Address Register,
then increment the Address Register

INC

( --- )

Read

 

6

@AREG++

Increment the 16-bits value pointed by the Address Register

DEC

( --- )

Read

 

6

@AREG--

Decrement the 16-bits value pointed by the Address Register

+!

(n --- )

Read

 

7

@AREG += n

Add a value to the 16-bits value pointed by the Address Register

(“)

 

 

 

 

 

 

(build_static)

 

 

Runtime only

6

 

 

(alloc_auto-vars)

 

 

Runtime only

5

 

 

(free-auto-vars)

 

 

Runtime only

22 (with 2 auto variables)

 

 

(build-auto)

 

 

Runtime only

6

 

 

(does-static)

 

 

Runtime only

9

 

 

(does-auto)

 

 

Runtime only

13

 

 

(lit-auto)

 

 

Runtime only

24

 

 

(allot)

 

 

Runtime only

Static alloc: 16
Auto alloc: 32

 

 

(end-build)

 

 

Runtime only

Static: 12
Auto: 8

 

 

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

32-bits Integer Memory

Definition

Parameters
Stack

Address
Register

Remark

MSP430
Cycles

Operation

Description

(DVARIABLE)

( --- )

Write

Runtime only

4

 

Runtime for DVARIABLE

(DCONSTANT)

( --- d)

 

Runtime only

17

 

Runtime for DCONSTANT

D@

( --- d)

Read

 

18

d=@AREG

Read the 32-bits value pointed by the Address Register

D@+

( --- d)

Read/Write

 

17

d=@AREG ++

Read the 32-bits value pointed by the Address Register,
then increment the Address Register

D!

(d --- )

Read

 

12

@AREG =d

Write a 32-bits value at the address pointed by the Address Register

(DLIT!)

( --- )

Read

Runtime only
Used by the optimizer

 

@AREG=lit

Write a literal 32-bits value at the address pointed by the Address Register

D!+

(d --- )

Read/Write

 

13

@AREG++=d

Increment the 32-bits value pointed by the Address Register,
then increment the Address Register

DINC

( --- )

Read

 

 

@AREG++

Increment the 32-bits value pointed by the Address Register

DDEC

( --- )

Read

 

 

@AREG--

Decrement the 32-bits value pointed by the Address Register

D+!

(d --- )

Read

 

 

@AREG += d

Add a value to the 32-bits value pointed by the Address Register

Code for Integer Memory (32-bits) is here (MSP430 and also here (x86 Linux).

Flash operations

Definition

Parameters
Stack

Remark

MSP430
Cycles

Operation

Description

!FLASH16

(n a --- )

 

 

n: value
a: address

Write a 16-bits value into the flash

!FLASH8

(b a --- )

 

 

b: value
a: address

Write a 8-bits value into the flash

CLEAR_FLASH

(a --- )

Runtime only

7

a: address

Erase a segment of Flash

Code for Flash is here.

Pages created:
December 27th 2002

Olivier Singla

 Pages last revised:
March 13rd 2006

 

SourceForge.net Logo