Minimal inline PIC Forth

From ScienceZero
Jump to: navigation, search

Minimal inline PIC Forth for PIC16xxx version 1.0 This minimal version of Forth is implemented by a series of Macro functions for the MASM assembler. The code is generated as inline code and not as a series of calls, it makes it fast but wasteful of code space. It is meant to work side by side with assembly commands. To use it you include pforth10.inc, set the variables and call 'finit' to initialize Forth before use. For details, read pforth10.inc.

If you plan to launch it into space then remember to check everything first. A sample program showing how to use the include file can be found here: picforth.asm


Forth words

Miscellaneous

finit    Initialize and set stack pointer
ldc n    Load Constant n
pushw    Push W on stack
pullw    Pull W on from stack
skp      Skip following instruction

pause n  Pause for 0-1024 cpu cycles
nop2     Pause for 2 cpu cycles
nop3     Pause for 3 cpu cycles
nop4     Pause for 4 cpu cycles

Arithmetic

inc      Increase by 1
dec      Decrease by 1
add      Add
sub      Subtract
mul      Multiply
twoexp   Two to the power

Bitwise Logical operations

and      Bitwise AND
or       Bitwise OR
eor      Bitwise Exclusive-OR
nand     Bitwise NAND
nor      Bitwise NOT OR
neor     Bitwise NOT EOR
bic      Bit Clear (AND NOT)
not      Invert bits

Logical operations

tst      Test if zero
flag     Create Boolean flag

Bit manipulation

bset     Set bit
bclr     Clear bit
bcng     Change bit
btst     Test bit
bsetc n  Set bit n
bclrc n  Clear bit n
bcngc n  Change bit n
btstc n  Test bit n 

Shifting

lsl      Logical shift left
lsr      Logical shift right
rol      Rotate left
ror      Rotate right
asr      Arithmetic shift right
lsl1     Logical shift left by one
lsl4     Logical shift left by four
lsr1     Logical shift right by one
lsr4     Logical shift right by four
rol1     Rotate left by one
ror1     Rotate right by one
ror4     Rotate right by four
rol1c    Rotate left through carry by one
ror1c    Rotate right through carry by one
asr1     Arithmetic shift right by one

Stack manipulation

dup      Duplicate top of stack
drop     Delete top of stack
over     Copy second item
swap     Swap topmost items
rot      Rotate top 3 times
nip      Delete second topmost item
tuck     Insert topmost item above second topmost item

PIC hardware

readEE   Read EPROM on PIC 16F84
writeEE  Write Eprom on PIC 16F84