Micro Vibe

My Micro Hobby Projects

  • Increase font size
  • Default font size
  • Decrease font size
Home MV4th Forth Documents MV4th extension words

MV4th extension words

Print

This article is a reference quide to the non ANS words found in the MV4th dictionary. These dictionary words fall into three main groups; forth words that allow access to the Propeller chip COG, forth words that are factors of ANS words, and forth words that have become common in many forth interpreters based on the ANS draft. There are a number of forth words in MV4th that are enclosed in parenthesize and have a name that matches defined ANS forth words. These words such as (do)  (loop)  (+loop) (literal)are the run time semantics for the forth words without the parenthesize in uppercase such as DO LOOP +LOOP and LITERAL. These words are generally not used directly in forth programs.


<=  ( n1 n2 -- flag ) 
flag is true if and only if n1 is less than or equal to n2.
>=  ( n1 n2 -- flag ) 
flag is true if and only if n1 is greater than or equal to n2. 
D>  ( d1 d2 -- flag )
flag is true if and only if double precision number d1 is greater than double precision number d2.
COGD@ ( n -- ud )
Read internal COG memory location n and return as a double (32 bit) value.
COGD! ( ud n -- )
Write the double (32 bit) value ud to the internal COG memory location n.  
NOT  ( f1  -- f2 )
flag f2 is made the logical complement of flag f1. In MV4th the word NOT is the same as the word 0=
DXOR  ( d1 d2 -- d3 )
double precision number d3 is the bit-by-bit exclusive-or of double precision number d1 with double precision number d2.
DOR  ( d1 d2 -- d3 )
double precision number d3 is the bit-by-bit logical-or of double precision number d1 with double precision number d2.
DAND  ( d1 d2 -- d3 )
double precision number d3 is the bit-by-bit logical "and" of double precision number d1 with double precision number d2
ARSHIFT  ( x1 u -- x2 )
Perform an arithmetic right shift of u bit-places on x1, giving x2. leaving the most significant bit unchanged. An ambiguous condition exists if u is greater than or equal to the number of bits in a cell.

DARSHIFT  ( d1 u -- d2 )
Perform an arithmetic right shift of u bit-places on double precision number d1, giving double precision number d2. leaving the most significant bit unchanged. An ambiguous condition exists if u is greater than or equal to the number of bits in a double cell.


DRSHIFT  ( d1 u -- d2 )
Perform a logical right shift of u bit-places on double precision number d1, giving double precision number d2. Put zero into the most significant bits vacated by the shift. An ambiguous condition exists if u is greater than or equal to the number of bits in a double cell.


DLSHIFT  ( d1 u -- d2 )
Perform a logical left shift of u bit-places on double precision number d1, giving double precision number d2. Put zero into the least significant bits vacated by the shift. An ambiguous condition exists if u is greater than or equal to the number of bits in a double cell.


SYSTEM ( n1...nn u -- na..nb )
This word is used to execute a support function provieded by a helper cog running spin or asm.  n1..nn represent parameters required by the requested system support function. u is the support function index number to execute. On return from the support function na..nb will contain any number of return values, the actual number will depend on the system support function being called. It is the responsibility of the called support function to remove any passed parameters from the Forth data stack. A support function may leave any number of return parameters on the data stack. 

This forth word requires a least one parameter on the data stack that contains the system command index to execute. The internal  variable "SystemCmdAdr" holds the address to a two word structure passed to the helper COG at start-up in the PAR COG register. The first word holds the command number index to be executed, and the second word hold the current data stack pointer address. 

The first word is set to zero by the helper COG to indicate that the last command has completed. A non zero value indicates a command index to be executed. The second word value is set to the current data stack pointer address value after the command index is removed from the data stack. After a command executes the command can set a new value for the data stack pointer if any parameters where added or removed from the data stack by the command.

MV4th reserves the first 32 support function index numbers for its own use, this is a list of the currently used index numbers;

  1             ( c -- )              Console send; c = 8 bit char to send to console.
  2             (  -- c )             Console read; c = 8 bit char read from console.
  3             (  -- f )              Does console have data to read; f = 0 no char ready from console, f= -1 char available from console.   
  4             ( u adr -- f )     Read block device block; u = mass storage block number, adr = buffer memory address, f = 0 read failed, f = -1 block read.
  5             ( u adr -- f )     Write block device block; u = mass storage block number, adr = buffer memory address, f = 0 write failed, f = -1 block written.
  6             ( -- u )              Get block device block count; u = mass storage block count, number of blocks available.
  7             ( u adr -- f )     Write block, u = mass storage block number, adr = buffer memory address, f = 0 write failed, f = -1 block written.
  8             ( -- u )              Returns number blocks available, u = mass storage block count.
  9             ( q-adr1 u1 -- u2 )       Start a new COG.
10            ( q-adr1 u1 u2 --  )      Start the COG index number u2.
11            ( u --  )             Stop the COG index number u if it is running.
12            ( -- u )              Allocate a lock u is the lock index or -1 if no locks available.
13            ( u -- )              Release a lock, u is the lock index to release/return
31            ( -- )                 Reboot the forth system.


 /-  ( n1 n2 -- n3 )
n3 is the result of dividing n1 by n2 using symmetrical division. By default MV4th uses floored division an per ANS specification for the forth word /.


 REM  ( n1 n2 -- n3 )
Divide n1 by n2, giving the single-cell remainder n3. An ambiguous condition exists if n2 is zero. Symmetrical division is used instead of the default floored division used by the forth word MOD.


 */-  ( n1 n2 n3 -- n4 )
Multiply n1 by n2 producing the double-cell intermediate result d. Divide d by n3 using symmetrical division giving the single-cell quotient n4. An ambiguous condition exists if n3 is zero or if the quotient n4 lies outside the range of a signed number.


*/REM  ( n1 n2 n3 -- n4 n5 )
Multiply n1 by n2 producing the intermediate double-cell result d. Divide d by n3 using symmetrical division producing the single-cell remainder n4 and the single-cell quotient n5. An ambiguous condition exists if n3 is zero, or if the quotient n5 lies outside the range of a single-cell signed integer.


?NEGATE  ( n1 n2 -- n3 ) or ( n1 n2 -- n2)
If n1 is negative, n3  is the arithmetic inverse of n2. If n1 is positive n2 is returned.


?DNEGATE  ( n1 d1 -- d2 ) or ( n1 d1 -- d1)
If the single precision value n1 is negative, double value d2  is the arithmetic inverse of double value d1. If n1 is positive d1 is returned.  



D0>
  (( d -- flag )
flag is true if and only if double precision number d is greater than zero.

UD*  ( ud1 u1 -- ud3 ) 
multiply the unsigned double value ud1 by the unsigned single cell value u1 to produce the unsigned double cell value ud3.


>DIGIT  (  n -- c )
convert n  to the character value c representing a single numeric digit (0..9 A..Z). This word is a factor for ?NUMBER and ?DNUMBER forth words.


UD.   (  ud --   )
display double ud as an unsigned value using the value stored in the BASE variable.


UMIN  ( u1 u2 -- u  )
u is the unsigned minimum of the unsigned values u1 and u2.


UMAX  ( u1 u2 -- u  )
u is the unsigned maximum of the unsigned values u1 and u2.


EXIT,  (   --  )
append the schemantics for EXIT to the code thread currently being compiled.


BACK,  ( -- )
remove the last execution token compiled into the current code thread by setting HERE back one cell. This is done by adjusting the value of the DP variable.


,DEST   ( u -- )
append a branch address u to the code thread being compiled  This appends the given destination address to a branch instruction.


!DEST  ( u1 u2 -- ) 
change a branch destination address  The new destination address u1 is saved to the code thread address u2.


>COUNTED  ( u1 u2 u3 -- )
copy the string of characters at address u1 with a count of u2 to a counted string at address u3.


SCAN  ( c-adr1 u1 c -- c-adr2 u2 )
Scan the character string at address c-adr1 with a length of u1 for the character c. c-adr2 contains the address of first matching character and u2 contains the number of character remaining in the string.


SKIP  ( c-adr1 u1 c -- c-adr2 u2 )
Scan the character string at address c-addr1 with a length of u1 for the first character not equal to c. c-addr2 contains the address of first character that does not match c and u2 'contains the number of character remaining in the string.


S=  ( c-adr1 c-adr2 u -- n ) 
compare the character strings at address c-adr1 with the character string at address c-adr2 to a maximum length of u. n = 0 if the strings match.
n = 1 if the string at c-adr1 is greater then the string at c-adr2. n = -1 if the string at c-adr1 is less then the string at c-adr2.


NFA>CFA  ( u1 -- u2 )
Convert the name field address of a word in the dictionary u1 to the code field address u2. u1 contains the name field address of a forth word which points to the length byte of the name string. u2 is set to the address of the start of the code field in the forth word.


NFA>LFA  ( u1 -- u2)
Convert the name field address of a forth dictionary word in u1 to the link field address u2. u1 contains the name field address of a forth word which points to the length byte of the name string. The u1 address value is adjusted to point to the link field address of the forth dictionary word and returned in u2.


NFA>FFA  ( u1 -- u2 )
Convert the name field address u1 to the flag field address u2. u1 contains the name field address of a forth word which points to the length byte of the name string. The u1 address value is adjusted to point to the flag field address and returned in u2.


IMMED?  ( u -- f )
Indicates the state of the immediate flag for the forth word whose name field address is u. If the forth word is immediate f = -1 else f = 0.


DIGIT?  ( c -- f )
checks if the character c is a valid numeric digit under the current value of BASE. f = -1 if c is a valid numeric digit else f = 0.


?SIGN  ( c-adr1 n1 -- c-adr2 n2 f )
Check the character string at address c-adr1 to see if it starts with a numeric sign character. if the character string starts with a sign character c-adr2 = c-adr1 + 1, n2 = n1 - 1, and f = -1. If no sign character is present c-adr2 = c-adr1, n2 = n1, and f = 0.


?HEX   ( c-adr1 n1 -- c-adr2 n2 f )
Check the character string at address c-adr1 to see if it starts with a dollor sign character and should be treated as a base 16 number ignoring the current value of BASE. if the character string starts with a dollar sign character c-adr2 = c-adr1 + 1, n2 = n1 - 1, and f = -1. If no dollar sign character is present c-adr2 = c-adr1, n2 = n1, and f = 0.


?DOUBLE  ( c-adr1 n1 -- c-adr1 n2 f )
Check the character string at address c-adr1 to see if it ends with a period character and should be treated as a double precision number. if the character string ends with a period character  n2 = n1 - 1, and f = -1. If no dollar sign character is present n2 = n1, and f = 0.


?NUMBER ( c-adr -- n  f )
Convert the counted character string at address c-adr to a number n. if the character string is a valid number under the numeric base stored in BASEreturn f = -1 and n = numeric value. If the string does not represent a valid number n = c-adr and f = 0.


?DNUMBER  ( c-adr -- d  f ) or ( c-adr -- c-adr f )
Convert the counted character string at address c-adr to a double precision number d. if the character string is a valid number under the numeric base stored in BASE return f = -1 for a single cell number and f = 1 if the string was a double precision number, d = numeric value. If the string does not represent a valid number c-adr and f = 0 are on the stack.


XT>NATIVE  ( xt1 -- xt2 )
Convert the execution address xt1 to a native opcode xt2. If the execution token address xt1 points to a native code execution thread the address is converted to the virtual CPU opcode xt2. If the execution token address xt1 is not pointing to a native code thread the execution token xt2 = xt1. This is a factor for COMPILE,.


?ABORT  ( f c-adr u -- )
if f = -1 print the character string at address c-adr with length u then call ABORT.


DEFER "name"  (  --  )
Create the word name whose behavior will be determined later and may be varied. See IS.


IS  "name"  ( xt -- )
Give the behavior identified by xt to the word name. Word "name" must be a deferred word created with the forth word DEFER.


USER  "name"  ( n -- )
Define a user area variable"name"  with offset n from the start of the user area.


HIDE  ( -- )
Set the smudge bit to prevent the currently compiled forth word from being found by the forth word FINDthis allows the new word to reference prior words in the forth dictionary with the same name. This word is a factor of the forth word : (colon).


REVEAL  ( -- )
Clear the smudge bit to allow the currently compiled forth to be found by the forth word FIND. This word is a factor of the forth word : (semicolon).


OF-RANGE     ( u1 u2 u3 -- u1 )
Start of case match clause where u1 is the case compare value and u2 u3 form the range of values allowed for a match to be true. See the OF forth word for more information


>L  ( x -- )  ( L: -- x )
Move the top value on the data stack to the leave stack. The leave stack is used by the compiler to track the branch address locations generated by the forth word LEAVE.


L>  (  -- x )  ( L: x -- )
Move the top value on the leave stack to the data stack. The leave stack is used by the compiler to track the branch address locations generated by the forth word LEAVE.


 
ENDLOOP   ( adrs xt -- )  ( L: 0 a1 a2 .. aN -- )
This word is a factor of the forth words LOOP and +LOOP. This word resolves the branch address locations generated by the word LEAVE. The branch address locations are saved on the leave stack.
 

 
DUMP     ( u1 u2 -- ) [removed in version 0.92, still available in TOOLS.BLK file]
Display the contents of memory  starting at location u1 and display u2 lines where each line contains 8 memory locations. This word is used a debugging tool. You need to set BASE to either 16 or 10 for the display to work correctly.
 

blk-cnt  ( -- u )
u is the number of device blocks available on the block storage device accessed by the block functions.


blk-wrt-cnt  ( -- u ) [removed in version 0.92]
u is the number of block writes that have occurred since the system started or the last time the forth word COLDis called. This is primarily a debugging feature.


block-write  (u -- )
save the block buffer to block u on the block device abort if write failed. This word is a factor for the forth words such as BUFFER and SAVE-BUFFERS.


block-read  (u -- )
Load block u from the block device into the block buffer abort if read failed. This word is a factor for the forth word BLOCK.


 


EXIT-ADR  (  -- a-adr )
Exit current code thread and leave next code address on data stack.
 


COG-INIT
  ( q-adr1 u1 u2 --  )
Start the COG index number u2, if the COG is already running stop the COG and restart the COG with the new code. q-adr1 points to a long aligned address containing the cog code to execute. u1 (upper 14 bits, bits 0,1 set to zero) is passes via the COG PAR register.
 


COG-NEW  ( q-adr1 u1 -- u2 )
Start a new COG q-adr1 points to a long aligned address containing the cog code to execute. u1 (upper 14 bits) is passes via the COG PAR register. The function returns the COG number started in u2 or u2 = -1 if no cog available.
 

COG_STOP  ( u --  )
Stop the COG index number u if it is running.


The Following forth words where added in version 0.91


LOCK-NEW  ( -- u )
Allocate a hardware propeller chip lock. u is the lock index if a lock is free to be allocated or -1 if no locks available.


 LOCK-RET  ( u -- )
Release a preciously allocated hardware lock. u is the lock index to release/return, this allows the lock to be allocated by the LOCK-NEW forth word.


 

LOCK-CLR  ( u1 -- u2 )
Set the state of a preciously allocated hardware lock. u1 to cleared (0). u2 contains the logical value TRUE if the lock state was set or FALSE if the lock state was clear prior to clearing the lock.  The lock must be allocated by the LOCK-NEW forth word.


LOCK-SET  ( u1 -- u2 )
Set the state of a preciously allocated hardware lock. u1 to set (1). u2 contains the logical value TRUE if the lock state was set or FALSE if the lock state was clear prior to setting the lock.  The lock must be allocated by the LOCK-NEW forth word.


Q@  ( u -- d )
This forth word reads a 32 bit value from memory and places the double precision value on the data stack. The supplied memory address, u must be aligned on a quad byte address (0, 4, 8, 12....). The value in memory is stored in COG format at address u, low word high word. The read operation is done using using the COG "rdlong" instruction making the read an atomic operation. The forth word 2@ is not atomic and expects the high word of the 32 bit value as the first word in memory as per the ANS forth standard.


 
Q!  ( u d --  )
This forth word writes the 32 bit double precision value d on the data stack to global memory at address u. The supplied memory address must be aligned on a quad byte address (0, 4, 8, 12....). The value in memory is stored in COG format, low word high word. The write operation is done using using the COG "wtlong" instruction making the write an atomic operation. The forth word 2! is not atomic and writes the high word of the 32 bit value as the first word in memory followed by the low word of the 32 bit value as per the ANS forth standard.


 

The Following forth words where added in version 0.92


(com1out) ( c --  )
Output the character c to the serial port. By default at start-up the deferred word EMIT is assigned to this forth word.


(com1out?) (  -- f )
See if the serial port can accept a character for output without blocking. By default at start-up the deferred word EMIT? is assigned to this forth word.

(com1in) (  -- c )
Input the character c from the serial port. By default at start-up the deferred word KEY is assigned to this forth word.


(com1in?) ( -- f )
See if a character is available from the serial port without blocking. By default at start-up the deferred word KEY? is assigned to this forth word.

(com1flush) ( -- f )
Empty the serial port input buffer. By default at start-up the deferred word EMPTY-KEYS is assigned to this forth word.
 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Last Updated on Sunday, 31 March 2013 11:49