Difference between revisions of "Minimal inline PIC Forth"

From ScienceZero
Jump to: navigation, search
(New page: 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 a...)
 
Line 4: Line 4:
 
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: [http://www.sciencezero.org/computing/download/picforth.asm picforth.asm]
 
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: [http://www.sciencezero.org/computing/download/picforth.asm picforth.asm]
  
   
 
      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
+
==Forth words==
nop2    Pause for 2 cpu cycles
+
===Miscellaneous===
nop3    Pause for 3 cpu cycles
+
finit    Initialize and set stack pointer
nop4    Pause for 4 cpu cycles
+
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
  
      Arithmetic
+
===Shifting===
inc      Increase by 1
+
  lsl      Logical shift left
dec      Decrease by 1
+
lsr      Logical shift right
add      Add
+
rol      Rotate left
sub      Subtract
+
ror      Rotate right
mul      Multiply
+
asr      Arithmetic shift right
twoexp  Two to the power
+
lsl1    Logical shift left by one
 
+
lsl4    Logical shift left by four
      Bitwise Logical operations
+
lsr1    Logical shift right by one
and      Bitwise AND
+
lsr4    Logical shift right by four
or      Bitwise OR
+
rol1    Rotate left by one
eor      Bitwise Exclusive-OR
+
ror1    Rotate right by one
nand    Bitwise NAND
+
ror4    Rotate right by four
nor      Bitwise NOT OR
+
rol1c    Rotate left through carry by one
neor    Bitwise NOT EOR
+
ror1c    Rotate right through carry by one
bic      Bit Clear (AND NOT)
+
asr1    Arithmetic shift right by one
not      Invert bits
+
 
+
===Stack manipulation===
      Logical operations
+
dup      Duplicate top of stack
tst      Test if zero
+
drop    Delete top of stack
flag    Create Boolean flag
+
over    Copy second item
 
+
swap    Swap topmost items
      Bit manipulation
+
rot      Rotate top 3 itmes
bset    Set bit
+
nip      Delete second topmost item
bclr    Clear bit
+
tuck    Insert topmost item above second topmost item
bcng    Change bit
+
btst    Test bit
+
===PIC hardware===
bsetc n Set bit n
+
readEE  Read EPROM on PIC 16F84
bclrc n  Clear bit n
+
writeEE  Write Eprom on PIC 16F84
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 itmes
+
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
+
  
 
[[Category:Computing]]
 
[[Category:Computing]]

Revision as of 11:43, 30 January 2007

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 itmes
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