Gforth Cheat Sheet
a collaborative effort by Little Girl and Frank Pirrone
Table of Contents
Introduction............................................................................................................................................................2
Accept....................................................................................................................................................................3
Array - Address Arithmetic.....................................................................................................................................4
Array - Cells And Chars.........................................................................................................................................4
Array - Cells - Create - Multiple Mixed Data Types...............................................................................................5
Array - Cells - Create - Numbers..........................................................................................................................10
Array - Cells - Create - Reserving Allocation Space.............................................................................................11
Array - Cells - Create - Strings.............................................................................................................................11
Array - Cells - Create - Unicode...........................................................................................................................12
Array - Cells - Multiple Mixed Data Types..........................................................................................................14
Array - Cells - Numbers.......................................................................................................................................16
Array - Cells - Removing Cells From An Array...................................................................................................18
Array - Cells - String Constant.............................................................................................................................20
Array - Cells - String Constant With Unicode As Variable Name.........................................................................22
Array - Cells - Unicode Character........................................................................................................................24
Array - Cells - Unicode Character Code...............................................................................................................25
Array - Chars - ASCII...........................................................................................................................................28
Array - Chars - Create - ASCII.............................................................................................................................30
Array - Chars - Create - Numbers.........................................................................................................................31
Array - Chars - Numbers (0 - 255)........................................................................................................................31
Array - Chars - Removing Chars From An Array.................................................................................................32
Array - Chars - String Constant Character............................................................................................................34
Array - Chars - Unicode Character.......................................................................................................................35
Array - Chars - Unicode Character Code..............................................................................................................36
Array - Multiple Mixed Array Types....................................................................................................................39
Array Types..........................................................................................................................................................39
Common Errors....................................................................................................................................................39
Conditional - Boolean...........................................................................................................................................40
Conditional - Case Statement...............................................................................................................................40
Conditional - Flags...............................................................................................................................................41
Conditional - If Statement.....................................................................................................................................41
Constants.............................................................................................................................................................. 42
Constants - ASCII.................................................................................................................................................42
Constants - Numbers............................................................................................................................................43
Constants - Numbers - 2constant..........................................................................................................................43
Constants - Numbers - Fconstant..........................................................................................................................43
Constants - Strings................................................................................................................................................44
Constants - Strings - 2constant.............................................................................................................................44
Constants - Unicode..............................................................................................................................................44
Data Types - How To Store And Fetch And Display.............................................................................................45
File Management - Text Files...............................................................................................................................46
Key Codes............................................................................................................................................................ 48
Length...................................................................................................................................................................49
Loops - Begin Again.............................................................................................................................................50
Loops - Begin Until..............................................................................................................................................51
Loops - Begin While Repeat.................................................................................................................................52
Loops - Do Loop..................................................................................................................................................53
Loops - For Next..................................................................................................................................................54
Memory Access Manipulations.............................................................................................................................54
Memory Allotted To Variables And Arrays...........................................................................................................55
Memory - Reserving And Acting On Memory......................................................................................................55
Miscellaneous.......................................................................................................................................................56
Numbers - About Types Of Numbers....................................................................................................................57
Numbers - Bases - Numeric Prefixes....................................................................................................................58
Numbers - Converting And Displaying.................................................................................................................60
Numbers - Formatted Numeric Output.................................................................................................................61
Numbers - Signed Integers...................................................................................................................................62
Numbers - Unsigned Integers...............................................................................................................................62
Parsing content from the input buffer...................................................................................................................63
Random................................................................................................................................................................ 64
Refill.....................................................................................................................................................................65
Stack - Add To The Stack.....................................................................................................................................65
Stack - Addresses..................................................................................................................................................66
Stack - Clear/Drop/Delete/Remove Stack Items...................................................................................................66
Stack - Copy/Duplicate Stack Items.....................................................................................................................67
Stack - Display The Stack.....................................................................................................................................68
Stack - Math With The Stack................................................................................................................................69
Stack - Move Stack Items Around........................................................................................................................70
Stack - Return Stack Manipulatives......................................................................................................................71
Stack - TOS And NOS..........................................................................................................................................71
Stack - Types........................................................................................................................................................71
Strings - Array - Defined Words...........................................................................................................................72
Strings - Defined Words........................................................................................................................................73
Strings - Fun With Strings....................................................................................................................................74
Strings - Having 2 Stack Values............................................................................................................................74
Strings - Spaces....................................................................................................................................................75
Strings - Types......................................................................................................................................................75
Unicode Characters - Displaying..........................................................................................................................76
Values...................................................................................................................................................................77
Values - ASCII......................................................................................................................................................77
Values - Number...................................................................................................................................................77
Values - String......................................................................................................................................................78
Values - Unicode...................................................................................................................................................78
Variables...............................................................................................................................................................79
Variables - 2variables............................................................................................................................................79
Variables - ASCII..................................................................................................................................................80
Variables - Fvariables...........................................................................................................................................81
Variables - Number...............................................................................................................................................81
Variables - String..................................................................................................................................................82
Variables - Unicode..............................................................................................................................................83
Vocabulary............................................................................................................................................................84
Words...................................................................................................................................................................84
Further Reading....................................................................................................................................................84
Version.................................................................................................................................................................. 85
Introduction
Color coding was used to distinguish between different types of information. The Table of Contents is green,
tables demonstrating and explaining syntax are pink, explanatory tables are orange, and example tables are blue.
The color coding wasn't always adhered to, so there will be the occasional table that doesn't fit into any of these
categories, but for which a color was chosen nonetheless.
Some of the tables won't fit on one page, so they spill over onto other pages. Since that's the case, no effort was
made to prevent any of the tables from spilling over from one page to another, making the .pdf version of this
file possibly awkward to use. An HTML version of the file will be available for those who prefer one connected
file to scroll through, and the original LibreOffice .odt file this was created in will also be available so that you
can edit it and export it to any format you like.
In the .pdf version, the Table of Contents links to all of the headings and all of the headings link back to the
Table of Contents.
In the .odt version, the Table of Contents links to all of the headings and all of the headings link back to the
Table of Contents, but you must hold the Ctrl key when clicking the links or they won't work.
In the .html version, the Table of Contents links to all of the headings, but the headings don't link back to the
Table of Contents (LibreOffice export bug, maybe).
If you prefer copying and pasting code rather than typing it in, you may find that the .odt file is the most
comfortable to use since it allows selection of an entire column of information, unlike the .pdf and .html files.
This document is offered free of charge without warranty of any kind, either expressed or implied.
ABBREVIATIONS AND TERMS USED IN THIS DOCUMENT
addr Represents an address. If more than one needs to be represented, addr1, addr2, and so on are used.
code Represents ASCII character code, unless specified otherwise. If more than one needs to be represented,
code1, code2, and so on are used.
dpsi Represents a double precision signed integer. If more than one needs to be represented, dpsi1, dpsi2,
and so on are used.
dpui Represents a double precision unsigned integer. If more than one needs to be represented, dpui1, dpui2,
and so on are used.
fpn Represents a floating point number. If more than one needs to be represented, fpn1, fpn2, and so on are
used.
i Represents an index.
input Represents input.
n Represents a number. If more than one needs to be represented, n1, n2, and so on are used.
spsi Represents a single precision signed integer. If more than one needs to be represented, spsi1, spsi2, and
so on are used.
spui Represents a single precision unsigned integer. If more than one needs to be represented, spui1, spui2,
and so on are used.
str Represents a string. If more than one needs to be represented, str1, str2, and so on are used.
u Represents a Unicode character. If more than one needs to be represented, u1, u2, and so on are used.
xxx Represents the name of something.
Accept
ACCEPT
addr n ACCEPT Take the memory address off of the top of the stack and accept a string ( addr n1 – n2 )
of up to a specified number of characters from the user with the address,
the number, and the ACCEPT word and the user's input followed by a
press of the Enter key and store its length at the current address.
If you want to preserve the string that has been captured, move it into a constant, variable, value, or other safe
address before the next execution overwrites it.
ACCEPT - EXAMPLE - ZIP CODE
Do the following commands in the order shown to see the example.
CR ." Enter your zip code:" Displays a carriage return followed by the Enter your zip code message
followed by displaying a carriage return.
HERE Puts the next free memory address on the stack.
5 ACCEPT Takes the memory address off of the top of the stack, waits for and accepts a 5-
character form of input, and puts its address and length on the top of the stack.
HERE Puts the next free memory address on the stack.
SWAP Swaps the top of stack value with the next on stack value, putting the address
and length, which were already on the stack, in the correct order (first address,
then length) for the next step.
CR ." Your zip code is: " Displays a carriage return followed by the Your zip code is message followed
TYPE CR by typing the value obtained from the address and length at the top of stack
and next to top of stack, and displays another carriage return.
The HERE address is a place where you can play, but is an address the system will use and overwrite when it's
needed. With the ALLOT word, you can reserve some address space beginning at HERE that the system will
not touch. So, if we modify our example a bit we can reserve 5 bytes of memory for HERE 5 ACCEPT to place
our zip code where it can stay as long as we need it to. Now it reads:
HERE 5 ALLOT CR ." Enter your zip code:" CR DUP 5 ACCEPT TYPE CR
We also could have used PAD 5 ALLOT, with PAD being a scratch pad area in memory a certain distance
from HERE. Anyway. at that point in our example you'll have the address twice, from the DUP, and the 5 that
ACCEPT leaves there so that you can execute one of two words that will show what's there: TYPE and DUMP.
The TYPE word formats the data as a regular string while the DUMP word displays the data on the screen.
Note that both DUMP and TYPE are destructive.
To summarize the memory words we've encountered:
• HERE - the current end of the dictionary, next place of free memory to use, the place your next
definition will go.
• PAD - a scratch-pad place, also in free memory, some distance from HERE where the user can place
things.
• TYPE - a word that takes an address and a length and outputs the contents of that space formatted for
the screen.
• DUMP - a word that takes an address and a length and dumps what's there to the screen with no
formatting.
• ALLOT - a word that takes an address and a length and reserves a space for that length for user use,
like PAD 5 ALLOT or HERE 5 ALLOT.
• ACCEPT - a word that takes an address and a length and waits to accept what the user types up to that
length.
Play around with all that and you'll get comfortable with it. Then do .S after each word to see how the stack
was affected by that word.
Array - Address Arithmetic
ARRAY - ADDRESS ARITHMETIC - EXPLANATION
The basic address arithmetic words are + and -. For example, if you have the address of a cell, perform 1
CELLS + and you will have the address of the next cell (zero is the first cell, one is the second cell, and so on).
Array - Cells And Chars
ARRAY - CELLS AND CHARS - EXPLANATION
The CELLS and CHARS words are plural even if they refer to only one cell or one byte:
ALLOT n CELLS and ALLOT n CHARS
n CELLS ERASE and n CHARS ERASE
n CELLS character FILL and n CHARS character FILL
n CELLS DUMP and n CHARS DUMP
n CELLS TYPE and n CHARS TYPE
CELLS The primary unit of information in the architecture of a Forth system. A memory space 8 8-bit
bytes, or 64 bits, in size.
CHARS A memory space 1 8-bit byte, or 8 bits, in size.
Array - Cells - Create - Multiple Mixed Data Types
ARRAY - CELLS - CREATE - MULTIPLE MIXED DATA TYPES - EXPLANATION
A create array can hold, store, and fetch multiple data types including 1-byte ASCII characters, 2-byte Unicode
characters, string constants, string variables, and 1-byte single-precision, double-precision, signed, unsigned,
and floating-point numbers.
When indexing into an array with a mixture of single (char or num) and double (string) compiled values, you
should follow these conventions:
• Go up by 1 when moving from a single value.
• Go up by 2 when moving from a double value.
• Use the words listed below to access the different kinds of values.
C, Store a 1-byte unsigned integer or ASCII character code in a create array.
, Store a single-precision signed or unsigned integer or Unicode character code in a create array.
2, Store a double-precision signed or unsigned integer or a character string address and length in a create array.
F, Store a floating point number in a create array.
S, Store a string of character codes in a create array.
C@ Fetch a 1-byte unsigned integer or ASCII character code from a create array.
UW@ Fetch a double 8-bit 1-byte (16-bits) Unicode character code from a create array.
@ Fetch a single-precision signed or unsigned integer from a create array.
2@ Fetch a double-precision signed or unsigned integer or the address and length of a string of character codes from a create array.
F@ Fetch a floating point number from a create array.
Note: A 1-byte number is valued positive 0 - 255 and can be manipulated with the c-store (C!) word and c-
fetch (C@) word and may be thought of as a character that you don't emit.
ARRAY - CELLS - CREATE - MULTIPLE MIXED DATA TYPES
In this exploration we will demonstrate that a single CREATE array can hold, store, and fetch multiple data
types including 1-byte ASCII characters, 2-byte Unicode characters, string variables, string constants, and 1-
byte, single-precision, double-precision, signed, unsigned, and floating-point numbers.
VARIABLE yyy S" string1" Create a variable and insert a string constant value into it with the
yyy PLACE VARIABLE word, a variable name, a string constant value, the
variable name again, and the PLACE word.
CREATE xxx 'a , 'u , yyy , S" string2" Create a CELLS array with the CREATE word, an array name, the
2, n , spsi , spui , dpui 2, fpn F, tick (') word with an ASCII character code, the comma (,) word, the
tick (') word with a Unicode character, the comma (,) word, a variable
name, the comma (,) word, a string constant, the two-comma (2,)
word, a 1-byte integer, the comma (,) word, a single-precision signed
integer, the comma (,) word, a single-precision unsigned integer, the
comma (,) word, a double-precision unsigned integer, the two-comma
(2,) word, a floating point number, and the f-comma (F,) word.
xxx i CELLS + C@ EMIT Fetch and display the ASCII character value from the array's specified
cell (cells memory address) with the array name, the index, the
CELLS word, the plus (+) word, the fetch (@) word, and the EMIT
word.
xxx i CELLS + @ XEMIT Fetch and display the Unicode character from the array's specified cell
(cells memory address) with the array name, the index, the CELLS
word, the plus (+) word, the fetch (@) word, and the XEMIT word.
xxx i CELLS + @ COUNT TYPE Fetch and display the string of character codes from the array's
specified cell (cells memory address) with the array name, the index,
the CELLS word, the plus (+) word, the fetch (@) word, the COUNT
word, and the TYPE word. Note: Use COUNT for strings that were
stored with the PLACE word.
xxx i CELLS + 2@ TYPE Fetch and display the string of character codes from the array's
specified 2 cells with the array name, the index, the CELLS word, the
plus (+) word, the two-fetch (2@) word, and the TYPE word.
xxx i CELLS + C@ . Fetch and display the 1-byte integer value from the array's specified
cell (cells memory address) with the array name, the index, the
CELLS word, the plus (+) word, the c-fetch (C@) word, and the dot
(.) word.
xxx i CELLS + @ . Fetch and display the single-precision signed integer value from the
array's specified cell (cells memory address) with the array name, the
index, the CELLS word, the plus (+) word, the fetch (@) word, and
the dot (.) word.
xxx i CELLS + @ . Fetch and display the single-precision unsigned integer value from the
array's specified cell (cells memory address) with the array name, the
index, the CELLS word, the plus (+) word, the fetch (@) word, and
the dot (.) word.
xxx i CELLS + 2@ UD. Fetch and display the single-precision unsigned integer value from the
array's specified cell (cells memory address) with the array name, the
index, the CELLS word, the plus (+) word, the two-fetch (2@) word,
and the double-precision-unsigned-integer-dot (UD.) word.
xxx i CELLS + F@ F. Fetch and display the floating point number value from the array's
specified cell (cells memory address) with the array name, the index,
the CELLS word, the plus (+) word, the floating-point-fetch (F@)
word, and the f-dot (F.) word.
Note:
The , and 2, and F, compiling words were used for some data types when creating this array. When indexing
into the array to read or write with its mixture of single (character, 1-byte number, single-precision integer,
floating-point number, string variable) and double (string constant, double-precision integer) compiled values,
go up by 1 when moving from a single value, go up by 2 when moving from a double value, using the
appropriate fetch commands (the C@ or @ or 2@ or F@ words) and display commands (the . or UD. or F. or
EMIT or XEMIT or COUNT TYPE or TYPE words) for the various data types. Changing values after the fact
requires that the same data type be used at each index point.
ARRAY - CELLS - CREATE - MULTIPLE MIXED DATA TYPES - EXAMPLE 1
VARIABLE xxx S" hello" xxx PLACE Create the xxx variable and insert the hello value into it.
CREATE yyy 'a , '☺ , xxx , S" world" Create the yyy array with the ticked ASCII a value, the ticked
2, 255 , -1024 , 2048 , 65535 S>D 2, Unicode ☺ value, the xxx variable name, the world string constant
1E2 F, value, the 1-byte 255 integer value, the single-precision signed -1024
integer value, the single-precision unsigned 2048 integer value, the
double-precision unsigned 65535 S>D integer value, and the floating
point 1E2 number value.
xxx 0 CELLS + C@ EMIT Fetch and display the a stored in the yyy array's 1st cell.
xxx 1 CELLS + @ XEMIT Fetch and display the ☺ stored in the yyy array's 2nd cell.
xxx 2 CELLS + @ COUNT TYPE Fetch and display the hello stored in the yyy array's 3rd and 4th cells.
xxx 3 CELLS + 2@ TYPE Fetch and display the world stored in the yyy array's 5th and 6th cells.
xxx 5 CELLS + C@ . Fetch and display the 255 stored in the yyy array's 7th cell.
xxx 6 CELLS + @ . Fetch and display the -1024 stored in the yyy array's 8th cell.
xxx 7 CELLS + @ . Fetch and display the 2048 stored in the yyy array's 9th cell.
xxx 8 CELLS + 2@ UD. Fetch and display the 65535 stored in the yyy array's 10th and 11th
cells.
xxx 10 CELLS + F@ F. Fetch and display the 100 stored in the yyy array's 12th cell.
ARRAY - CELLS - CREATE - MULTIPLE MIXED DATA TYPES - EXAMPLE 2
CREATE xxx 'a , 'b , 'c , S" one" 2, Create the xxx array with the ticked ASCII a value, the ticked ASCII b
'd , S" two" 2, 'e , 'f , 1 , -2 , S" value, the ticked ASCII c value, the one string constant value, the ticked
three" 2, 3 , '☺ , '☻ , '☼ , S" four" ASCII d value, the two string constant value, the ticked ASCII e value, the
2, '☹ , ticked ASCII f value, the single-precision unsigned 1 integer value, the
single-precision signed -2 value, the three string constant value, the single-
precision unsigned 3 value, the ticked Unicode character ☺ value, the
ticked Unicode character ☻ value, the ticked Unicode character ☼ value,
the four string constant value, and the ticked Unicode character ☹ value.
xxx 0 cells + c@ emit Fetch and display the a stored in the xxx array's 1st cell.
xxx 1 cells + c@ emit Fetch and display the b stored in the xxx array's 2nd cell.
xxx 2 cells + c@ emit Fetch and display the c stored in the xxx array's 3rd cell.
xxx 3 cells + 2@ type Fetch and display the one string of character codes stored in the xxx array's 4th and 5th cells.
xxx 5 cells + c@ emit Fetch and display the d stored in the xxx array's 6th cell.
xxx 6 cells + 2@ type Fetch and display the two string of character codes stored in the xxx array's 7th and 8th cells.
xxx 8 cells + c@ emit Fetch and display the e stored in the xxx array's 9th cell.
xxx 9 cells + c@ emit Fetch and display the f stored in the xxx array's 10th cell.
xxx 10 cells + @ . Fetch and display the 1 stored in the xxx array's 11th cell.
xxx 11 cells + @ . Fetch and display the -2 stored in the xxx array's 12th cell.
xxx 12 cells + 2@ type Fetch and display the three string of character codes stored in the xxx array's 13th and 14th cells.
xxx 14 cells + @ . Fetch and display the 3 stored in the xxx array's 15th cell.
xxx 15 cells + @ xemit Fetch and display the ☺ stored in the xxx array's 16th cell.
xxx 16 cells + @ xemit Fetch and display the☻stored in the xxx array's 17th cell.
xxx 17 cells + @ xemit Fetch and display the ☼stored in the xxx array's 18th cell.
xxx 18 cells + 2@ type Fetch and display the four string of character codes stored in the xxx array's 19th and 20t cells.
xxx 20 cells + @ xemit Fetch and display the ☹ stored in the xxx array's 21st cell.
ARRAY - CELLS - CREATE - MULTIPLE MIXED DATA TYPES - EXAMPLE 3
This is a "monster" create array with every possible known data type for Gforth versions older than Gforth 0.7.9 and is
intended to be used as a quick reference for how to use specific data types in an array.
VARIABlE var 12345 var !
2VARIABLE 2var 12345. 2var 2!
FVARIABLE fvar 12345E0 fvar F!
54321 VALUE val
31416 CONSTANT con
31416. 2CONSTANT 2con
3.1416E0 FCONSTANT fcon
: charvariablelen dup here cell - swap - swap c! ;
: cellvariablelen dup here cell - swap - 8 / swap ! ;
: charcreatelen dup here swap - swap c! ;
: cellcreatelen dup here swap - 8 / swap ! ;
CREATE array
0 , ( spot for allocation length)
65 , ( ASCII character code)
'A , ( ASCII character)
1 2 < , ( Boolean flag)
255 , ( byte integer)
1024 SP@ @ , ( data-stack element)
2con 2, ( double-precision constant)
65535 S>D 2, ( double-precision integer)
-65535 S>D 2, ( double-precision signed int)
2var , ( double-precision variable)
' + , ( execution token)
fcon F, ( floating-point constant)
1E2 F, ( floating-point number)
fvar , ( floating-point variable)
HERE , ( memory address)
2048 >R R@ R> , ( return-stack element)
con , ( single-precision constant)
4096 , ( single-precision integer)
-4096 , ( single-precision signed int)
val , ( single-precision value)
var , ( single-precision variable)
," string compiled" ( string compiled)
S" string constant" S, ( string constant)
0x263A , ( Unicode character code)
'☺ , ( Unicode character)
array cellcreatelen
PAGE
." Allot " array ? ." cells" ( stored allocation length)
CR array 1 CELLS + C@ EMIT ( ASCII character code)
CR array 2 CELLS + C@ EMIT ( ASCII character)
CR array 3 CELLS + ? ( Boolean flag)
CR array 4 CELLS + ? ( byte integer)
CR array 5 CELLS + ? ( data-stack element)
CR array 6 CELLS + 2@ D. ( double-precision constant)
CR array 8 CELLS + 2@ D. ( double-precision integer)
CR array 10 CELLS + 2@ D. ( double-precision signed int)
CR array 12 CELLS + @ 2@ D. ( double-precision variable)
CR array 13 CELLS + ? ( execution token)
CR array 14 CELLS + F@ F. ( floating-point constant)
CR array 15 CELLS + F@ F. ( floating-point number)
CR array 16 CELLS + @ F@ F. ( floating-point variable)
CR array 17 CELLS + ? ( memory address)
CR array 18 CELLS + ? ( return-stack element)
CR array 19 CELLS + ? ( single-precision constant)
CR array 20 CELLS + ? ( single-precision integer)
CR array 21 CELLS + ? ( single-precision signed int)
CR array 22 CELLS + ? ( single-precision value)
CR array 23 CELLS + @ ? ( single-precision variable)
CR array 24 CELLS + COUNT TYPE ( string compiled)
CR array 26 CELLS + COUNT TYPE ( string constant)
CR array 28 CELLS + @ XEMIT ( Unicode character code)
CR array 29 CELLS + @ XEMIT ( Unicode character)
CR CR ." Press any key to exit " KEY PAGE
ARRAY - CELLS - CREATE - MULTIPLE MIXED DATA TYPES - EXAMPLE 4
This is a "monster" create array with every possible known data type for Gforth 0.7.9 and is intended to be used as a
quick reference for how to use specific data types in an array.
VARIABlE var 12345 var !
2VARIABLE 2var 12345. 2var 2!
FVARIABLE fvar 12345E0 fvar F!
54321 VALUE val
54321. 2VALUE 2val ( for Gforth v0.7.9)
54321E0 FVALUE fval ( for Gforth v0.7.9)
31416 CONSTANT con
31416. 2CONSTANT 2con
3.1416E0 FCONSTANT fcon
: charvariablelen dup here cell - swap - swap c! ;
: cellvariablelen dup here cell - swap - 8 / swap ! ;
: charcreatelen dup here swap - swap c! ;
: cellcreatelen dup here swap - 8 / swap ! ;
CREATE array
0 , ( spot for allocation length)
65 , ( ASCII character code)
'A , ( ASCII character)
1 2 < , ( Boolean flag)
255 , ( byte integer)
1024 SP@ @ , ( data-stack element)
2con 2, ( double-precision constant)
65535 S>D 2, ( double-precision integer)
-65535 S>D 2, ( double-precision signed int)
2val 2, ( double-precision value)
2var , ( double-precision variable)
' + , ( execution token)
fcon F, ( floating-point constant)
1E2 F, ( floating-point number)
fval F, ( floating-point value)
fvar , ( floating-point variable)
HERE , ( memory address)
2048 >R R@ R> , ( return-stack element)
con , ( single-precision constant)
4096 , ( single-precision integer)
-4096 , ( single-precision signed int)
val , ( single-precision value)
var , ( single-precision variable)
," string compiled" ( string compiled)
S" string constant" S, ( string constant)
0x263A , ( Unicode character code)
'☺ , ( Unicode character)
array cellcreatelen
PAGE
." Allot " array ? ." cells" ( stored allocation length)
CR array 1 CELLS + C@ EMIT ( ASCII character code)
CR array 2 CELLS + C@ EMIT ( ASCII character)
CR array 3 CELLS + ? ( Boolean flag)
CR array 4 CELLS + ? ( byte integer)
CR array 5 CELLS + ? ( data-stack element)
CR array 6 CELLS + 2@ D. ( double-precision constant)
CR array 8 CELLS + 2@ D. ( double-precision integer)
CR array 10 CELLS + 2@ D. ( double-precision signed int)
CR array 12 CELLS + 2@ D. ( double-precision value)
CR array 14 CELLS + @ 2@ D. ( double-precision variable)
CR array 15 CELLS + ? ( execution token)
CR array 16 CELLS + F@ F. ( floating-point constant)
CR array 17 CELLS + F@ F. ( floating-point number)
CR array 18 CELLS + F@ F. ( floating-point value)
CR array 19 CELLS + @ F@ F. ( floating-point variable)
CR array 20 CELLS + ? ( memory address)
CR array 21 CELLS + ? ( return-stack element)
CR array 22 CELLS + ? ( single-precision constant)
CR array 23 CELLS + ? ( single-precision integer)
CR array 24 CELLS + ? ( single-precision signed int)
CR array 25 CELLS + ? ( single-precision value)
CR array 26 CELLS + @ ? ( single-precision variable)
CR array 27 CELLS + COUNT TYPE ( string compiled)
CR array 29 CELLS + COUNT TYPE ( string constant)
CR array 31 CELLS + @ XEMIT ( Unicode character code)
CR array 32 CELLS + @ XEMIT ( Unicode character)
CR CR ." Press any key to exit " KEY PAGE
Array - Cells - Create - Numbers
ARRAY - CELLS - CREATE - NUMBERS
CREATE xxx n1 , n2 , n3 , n4 , Create a CELLS array with the CREATE word, an array name, and one or
more numbers, with the comma (,) word after each number.
xxx i CELLS + @ . Fetch and display the value of the array's specified cell (cells memory
address) with the array name, the index, the CELLS word, the plus (+) word,
the fetch (@) word, and the dot (.) word.
xxx i CELLS + ? Or fetch and display the value of the array's specified cell (cells memory
address) with the array name, the index, the CELLS word, the plus (+) word,
and the question (?) word.
xxx Place the base array address on the stack by using the array name.
Erasing this array's cells isn't necessary since you created the array with its values rather than converting a
variable into the array. You can erase or modify the cells if you like just like you would in any other CELLS
array.
ARRAY - CELLS - CREATE - NUMBERS - EXAMPLE
CREATE xxx 1 , 2 , 3 , 4 , Create the xxx array with the 1, 2, 3, and 4 fixed values.
xxx 0 CELLS + @ . Fetch and display the 1 stored in the xxx array's 1st cell.
xxx 1 CELLS + @ . Fetch and display the 2 stored in the xxx array's 2nd cell.
xxx 2 CELLS + @ . Fetch and display the 3 stored in the xxx array's 3rd cell.
xxx 3 CELLS + @ . Fetch and display the 4 stored in the xxx array's 4th cell.
xxx 0 CELLS + ? Fetch and display the 1 stored in the xxx array's 1st cell.
xxx 1 CELLS + ? Fetch and display the 2 stored in the xxx array's 2nd cell.
xxx 2 CELLS + ? Fetch and display the 3 stored in the xxx array's 3rd cell.
xxx 3 CELLS + ? Fetch and display the 4 stored in the xxx array's 4th cell.
Array - Cells - Create - Reserving Allocation Space
ARRAY - CELLS - CREATE - RESERVING ALLOCATION SPACE
When using CREATE to form an array, you can mix the initial compiles and the allocation. This supports
compiling in things you know you're going to store at the point of creation, and reserving additional space for
things you don't know or don't want to store yet. Either of these two methods will accomplish the same thing:
CREATE xxx 255 C, 1024 , 2 CELLS ALLOT Create the xxx array with the 255 and 1024 values and with 2
additional CELLS allocated to it.
CREATE xxx 255 C, 1024 , 0 , 0 , Create the xxx array with the 255 and 1024 values and with 2
additional CELLS allocated to it.
Array - Cells - Create - Strings
ARRAY - CELLS - CREATE - STRINGS
CREATE xxx S" str1" 2, S" str2" 2, S" str3" 2, S" str4" 2, Create a CELLS array with the CREATE word, an array
name, and one or more string constant values, with the
two-comma (2,) word after each value.
xxx i CELLS + 2@ TYPE Fetch and display the value of the array's specified cell
(cells memory address) with the array name, the index,
the CELLS word, the plus (+) word, the two-fetch (2@)
word, and the TYPE word.
xxx i CELLS + ? Fetch and display the length of the array's specified cell
(cells memory address) with the array name, the index,
the CELLS word, the plus (+) word, and the question
(?) word.
xxx Place the base array address on the stack by using the
array name.
When indexing into an array with double (string) compiled values, you should go up by 2 when moving from
one value to the next and use the two-fetch (2@) word when accessing the values.
Erasing this array's cells isn't necessary since you created the array with its values rather than converting a
variable into the array. You can erase or modify the cells if you like just like you would in any other CELLS
array.
ARRAY - CELLS - CREATE - STRINGS - EXAMPLE
CREATE XXX s" one" 2, s" two" 2, s" three" 2, s" four" 2, Create the xxx array with the one, two, three, and four
string constant values.
xxx 0 CELLS + 2@ TYPE Fetch and display the one stored in the xxx array's first 2 cells.
xxx 2 CELLS + 2@ TYPE Fetch and display the two stored in the xxx array's second 2 cells.
xxx 4 CELLS + 2@ TYPE Fetch and display the three stored in the xxx array's third 2 cells.
xxx 6 CELLS + 2@ TYPE Fetch and display the four stored in the xxx array's fourth 2 cells.
xxx 0 CELLS + ? Fetch and display the length of the xxx array's first 2 cells.
xxx 2 CELLS + ? Fetch and display the length of the xxx array's second 2 cells.
xxx 4 CELLS + ? Fetch and display the length of the xxx array's third 2 cells.
xxx 6 CELLS + ? Fetch and display the length of the xxx array's fourth 2 cells.
Array - Cells - Create - Unicode
ARRAY - CELLS - CREATE - UNICODE - METHOD 1
HEX Put Forth into base 16 (hexadecimal) mode with the HEX word.
CREATE xxx u1 , u2 , u3 , u4 , Create a CELLS array with the CREATE word, an array name, and one or
more fixed Unicode values, with the comma (,) word after each value.
xxx i CELLS + @ XEMIT Fetch and display the value of the array's specified cell (cells memory
address) with the array name, the index, the CELLS word, the plus (+) word,
the fetch (@) word, and the XEMIT word.
xxx i CELLS + ? Fetch and display the hexadecimal numeric code value of the array's specified
cell (cells memory address) with the array name, the index, the CELLS word,
the plus (+) word, and the question (?) word.
xxx Place the base array address on the stack by using the array name.
DECIMAL Put Forth back into base 10 (decimal) mode with the DECIMAL word.
Erasing this array's cells isn't necessary since you created the array with its values rather than converting a
variable into the array. You can erase or modify the cells if you like just like you would in any other CELLS
array.
ARRAY - CELLS - CREATE - UNICODE - METHOD 1 - EXAMPLE
HEX Put Forth into base 16 (hexadecimal) mode.
CREATE xxx 263a , 263b , 263c , 2639 , Create the xxx array with the 263a, 263b, 263c, and 2639 fixed
Unicode values.
xxx 0 CELLS + @ XEMIT Fetch and display the ☺ stored in the xxx array's first cell.
xxx 1 CELLS + @ XEMIT Fetch and display the ☻ stored in the xxx array's second cell.
xxx 2 CELLS + @ XEMIT Fetch and display the ☼stored in the xxx array's third cell.
xxx 3 CELLS + @ XEMIT Fetch and display the ☹ stored in the xxx array's fourth cell.
xxx 0 CELLS + ? Fetch and display the 263A stored in the xxx array's first cell.
xxx 1 CELLS + ? Fetch and display the 263B stored in the xxx array's second cell.
xxx 2 CELLS + ? Fetch and display the 263C stored in the xxx array's third cell.
xxx 3 CELLS + ? Fetch and display the 2639 stored in the xxx array's fourth cell.
DECIMAL Put Forth back into base 10 (decimal) mode.
ARRAY - CELLS - CREATE - UNICODE - METHOD 2
CREATE xxx u1 , u2 , u3 , u4 , Create a CELLS array with the CREATE word, an array name, and one or
more fixed prefixed Unicode hexadecimal numeric values, with the comma (,)
word after each value.
xxx i CELLS + @ XEMIT Fetch and display the value of the array's specified cell (cells memory address)
with the array name, the index, the CELLS word, the plus (+) word, the fetch
(@) word, and the XEMIT word.
xxx i CELLS + ? Fetch and display the decimal numeric code value of the array's specified cell
(cells memory address) with the array name, the index, the CELLS word, the
plus (+) word, and the question (?) word.
xxx Place the base array address on the stack by using the array name.
Erasing this array's cells isn't necessary since you created the array with its values rather than converting a
variable into the array. You can erase or modify the cells if you like just like you would in any other CELLS
array.
ARRAY - CELLS - CREATE - UNICODE - METHOD 2 - EXAMPLE
CREATE xxx $263a , $263b , $263c , $2639 , Create the xxx array with the 263a, 263b, 263c, and 2639 fixed
prefixed Unicode hexadecimal numeric values.
xxx 0 CELLS + @ XEMIT Fetch and display the ☺ stored in the xxx array's first cell.
xxx 1 CELLS + @ XEMIT Fetch and display the ☻ stored in the xxx array's second cell.
xxx 2 CELLS + @ XEMIT Fetch and display the ☼stored in the xxx array's third cell.
xxx 3 CELLS + @ XEMIT Fetch and display the ☹ stored in the xxx array's fourth cell.
xxx 0 CELLS + ? Fetch and display the 9786 stored in the xxx array's first cell.
xxx 1 CELLS + ? Fetch and display the 9787 stored in the xxx array's second cell.
xxx 2 CELLS + ? Fetch and display the 9788 stored in the xxx array's third cell.
xxx 3 CELLS + ? Fetch and display the 9785 stored in the xxx array's fourth cell.
ARRAY - CELLS - CREATE - UNICODE CHARACTER
HEX Put Forth into base 16 (hexadecimal) mode with the HEX word.
CREATE xxx 'u1 , 'u2 , 'u3 , 'u4 , Create a CELLS array with the CREATE word, an array name, one or more
fixed Unicode character values, with the comma (,) word after each value.
xxx i CELLS + @ XEMIT Fetch and display the value (the Unicode character) of the array's specified
cell (cells memory address) with the array name, the index, the CELLS
word, the plus (+) word, the fetch (@) word, and the XEMIT word.
xxx i CELLS + @ . Fetch and display the hexadecimal numeric code value of the array's
specified cell (cells memory address) with the array name, the index, the
CELLS word, the plus (+) word, the fetch (@) word and the dot (.) word.
xxx i CELLS + ? Or fetch and display the hexadecimal numeric code value of the array's
specified cell (cells memory address) with the array name, the index, the
CELLS word, the plus (+) word, and the question (?) word.
xxx Place the base array address on the stack by using the array name.
DECIMAL Put Forth back into base 10 (decimal) mode with the DECIMAL word.
Erasing this array's cells isn't necessary since you created the array with its values rather than converting a
variable into the array. You can erase or modify the cells if you like just like you would in any other CELLS
array.
ARRAY - CELLS - CREATE - UNICODE CHARACTER - EXAMPLE
HEX Put Forth into base 16 (hexadecimal) mode.
CREATE xxx '☺ , '☻ , '☼ , '☹ , Create the xxx array with the ticked ☺, ☻, ☼, and ☹ fixed
Unicode character values.
xxx 0 CELLS + @ XEMIT Fetch and display the ☺ stored in the xxx array's first cell.
xxx 1 CELLS + @ XEMIT Fetch and display the ☻ stored in the xxx array's second cell.
xxx 2 CELLS + @ XEMIT Fetch and display the ☼stored in the xxx array's third cell.
xxx 3 CELLS + @ XEMIT Fetch and display the ☹ stored in the xxx array's fourth cell.
xxx 0 CELLS + @ . Fetch and display the 263A stored in the xxx array's first cell.
xxx 1 CELLS + @ . Fetch and display the 263B stored in the xxx array's second cell.
xxx 2 CELLS + @ . Fetch and display the 263C stored in the xxx array's third cell.
xxx 3 CELLS + @ . Fetch and display the 2639 stored in the xxx array's fourth cell.
xxx 0 CELLS + ? Fetch and display the 263A stored in the xxx array's first cell.
xxx 1 CELLS + ? Fetch and display the 263B stored in the xxx array's second cell.
xxx 2 CELLS + ? Fetch and display the 263C stored in the xxx array's third cell.
xxx 3 CELLS + ? Fetch and display the 2639 stored in the xxx array's fourth cell.
DECIMAL Put Forth back into base 10 (decimal) mode.
Array - Cells - Multiple Mixed Data Types
ARRAY - CELLS - MULTIPLE MIXED DATA TYPES - EXAMPLE 1
This is a "monster" CELLS array with every possible known data type for Gforth versions older than Gforth 0.7.9 and is
intended to be used as a quick reference for how to use specific data types in an array.
31416. 2CONSTANT dpui-constant ( double-precision unsigned integer constant )
2VARIABLE dpui-variable 12345. dpui-variable 2! ( double-precision unsigned integer variable )
3.1416E0 FCONSTANT fpn-constant ( floating-point number constant )
FVARIABLE fpn-variable 12345E0 fpn-variable F! ( floating-point number variable )
31416 CONSTANT spui-constant ( single-precision unsigned integer constant )
54321 VALUE spui-value ( single-precision unsigned integer value )
VARIABLE spui-variable 12345 spui-variable ! ( single-precision unsigned integer variable )
: total-number-of-cells DUP HERE SWAP - 8 / SWAP ! ; ( word for displaying the total number of CELLS in the array )
VARIABLE xxx 30 CELLS ALLOT
0 xxx 0 CELLS + ! ( place holder for length )
'a xxx 1 CELLS + C! ( ASCII character1 )
97 xxx 2 CELLS + C! ( ASCII character2 )
'a xxx 3 CELLS + ! ( ASCII character code )
1 2 < xxx 4 CELLS + ! ( Boolean flag )
255 xxx 5 CELLS + C! ( byte integer )
1024 SP@ @ xxx 6 CELLS + ! ( data stack element )
-65535 S>D xxx 7 CELLS + 2! ( double-precision signed integer )
65535 S>D xxx 9 CELLS + 2! ( double-precision unsigned integer )
dpui-constant xxx 11 CELLS + 2! ( double-precision unsigned integer constant )
dpui-variable xxx 13 CELLS + ! ( double-precision unsigned integer variable )
' PAGE xxx 14 CELLS + ! ( execution token )
1e2 xxx 15 CELLS + F! ( floating-point number )
fpn-constant xxx 16 CELLS + F! ( floating-point number constant )
fpn-variable xxx 17 CELLS + ! ( floating-point number variable )
HERE xxx 18 CELLS + ! ( memory address )
1024 >R R@ R> xxx 22 CELLS + ! ( return stack element )
-400 xxx 20 CELLS + ! ( single-precision signed integer )
400 xxx 21 CELLS + ! ( single-precision unsigned integer )
spui-constant xxx 22 CELLS + ! ( single-precision unsigned integer constant )
spui-value xxx 23 CELLS + ! ( single-precision unsigned integer value )
spui-variable XXX 24 CELLS + ! ( single-precision unsigned integer variable )
S" example1" xxx 25 CELLS + 2! ( string constant1 )
S" example2" xxx 27 CELLS + PLACE ( string constant2 )
'☺ xxx 29 CELLS + ! ( Unicode character1 )
0x263A xxx 30 CELLS + ! ( unicode character2 )
0x263A xxx 31 CELLS + ! ( unicode character code )
xxx total-number-of-cells
CR xxx 0 CELLS + ? ." CELLS" ( allocation for length )
CR xxx 1 CELLS + C@ EMIT ( ASCII character1 )
CR xxx 2 CELLS + C@ EMIT ( ASCII character2 )
CR xxx 3 CELLS + ? ( ASCII character code )
CR xxx 4 CELLS + ? ( Boolean flag )
CR xxx 5 CELLS + C@ . ( byte integer )
CR xxx 6 CELLS + ? ( data stack element )
CR xxx 7 CELLS + 2@ D. ( double-precision signed integer - address and length )
CR xxx 9 CELLS + 2@ D. ( double-precision unsigned integer - address and length )
CR xxx 11 CELLS + 2@ D. ( double-precision unsigned integer constant - address and length )
CR xxx 13 CELLS + @ 2@ D. ( double-precision unsigned integer variable - address and length )
CR xxx 14 CELLS + ? ( execution token )
CR xxx 15 CELLS + F@ F. ( floating-point number )
CR xxx 16 CELLS + F@ F. ( floating-point number constant )
CR xxx 17 CELLS + @ F@ F. ( floating-point number variable )
CR xxx 18 CELLS + ? ( memory address )
CR xxx 19 CELLS + ? ( return stack element)
CR xxx 20 CELLS + ? ( single-precision signed integer )
CR xxx 21 CELLS + ? ( single-precision unsigned integer )
CR xxx 22 CELLS + ? ( single-precision unsigned integer constant )
CR xxx 23 CELLS + ? ( single-precision unsigned integer value )
CR xxx 24 CELLS + @ ? ( single-precision unsigned integer variable )
CR xxx 25 CELLS + 2@ TYPE ( string constant1 - address and length )
CR xxx 27 CELLS + COUNT TYPE ( string constant2 - length )
CR xxx 29 CELLS + @ XEMIT ( Unicode character1 )
CR xxx 30 CELLS + @ XEMIT ( Unicode character2 )
CR xxx 31 CELLS + @ . ( Unicode character code )
ARRAY - CELLS - MULTIPLE MIXED DATA TYPES - EXAMPLE 2
This is a "monster" CELLS array with every possible known data type for Gforth 0.7.9 and is intended to be used as a
quick reference for how to use specific data types in an array.
31416. 2CONSTANT dpui-constant ( double-precision unsigned integer constant )
54321. 2VALUE dpui-value ( double-precision unsigned integer value - for Gforth v0.7.9 )
2VARIABLE dpui-variable 12345. dpui-variable 2! ( double-precision unsigned integer variable )
3.1416E0 FCONSTANT fpn-constant ( floating-point number constant )
54321E0 FVALUE fpn-value ( floating-point number value - for Gforth v0.7.9 )
FVARIABLE fpn-variable 12345E0 fpn-variable F! ( floating-point number variable )
31416 CONSTANT spui-constant ( single-precision unsigned integer constant )
54321 VALUE spui-value ( single-precision unsigned integer value )
VARIABLE spui-variable 12345 spui-variable ! ( single-precision unsigned integer variable )
: total-number-of-cells DUP HERE SWAP - 8 / SWAP ! ; ( word for displaying the total number of CELLS in the array )
VARIABLE xxx 35 CELLS ALLOT
0 xxx 0 CELLS + ! ( place holder for length )
'a xxx 1 CELLS + C! ( ASCII character1 )
97 xxx 2 CELLS + C! ( ASCII character2 )
'a xxx 3 CELLS + ! ( ASCII character code )
1 2 < xxx 4 CELLS + ! ( Boolean flag )
255 xxx 5 CELLS + C! ( byte integer )
1024 SP@ @ xxx 6 CELLS + ! ( data stack element )
-65535 S>D xxx 7 CELLS + 2! ( double-precision signed integer )
65535 S>D xxx 9 CELLS + 2! ( double-precision unsigned integer )
dpui-constant xxx 11 CELLS + 2! ( double-precision unsigned integer constant )
dpui-value xxx 13 CELLS + 2! ( double-precision unsigned integer value - for Gforth v0.7.9 )
dpui-variable xxx 15 CELLS + ! ( double-precision unsigned integer variable )
' PAGE xxx 16 CELLS + ! ( execution token )
1e2 xxx 17 CELLS + F! ( floating-point number )
fpn-constant xxx 18 CELLS + F! ( floating-point number constant )
fpn-value xxx 19 CELLS + F! ( floating-point number value - for Gforth v0.7.9 )
fpn-variable xxx 20 CELLS + ! ( floating-point number variable )
HERE xxx 21 CELLS + ! ( memory address )
1024 >R R@ R> xxx 22 CELLS + ! ( return stack element )
-400 xxx 23 CELLS + ! ( single-precision signed integer )
400 xxx 24 CELLS + ! ( single-precision unsigned integer )
spui-constant xxx 25 CELLS + ! ( single-precision unsigned integer constant )
spui-value xxx 26 CELLS + ! ( single-precision unsigned integer value )
spui-variable XXX 27 CELLS + ! ( single-precision unsigned integer variable )
S" example1" xxx 28 CELLS + 2! ( string constant1 )
S" example2" xxx 30 CELLS + PLACE ( string constant2 )
'☺ xxx 32 CELLS + ! ( Unicode character1 )
0x263A xxx 33 CELLS + ! ( unicode character2 )
0x263A xxx 34 CELLS + ! ( unicode character code )
xxx total-number-of-cells
CR xxx 0 CELLS + ? ." CELLS" ( allocation for length )
CR xxx 1 CELLS + C@ EMIT ( ASCII character1 )
CR xxx 2 CELLS + C@ EMIT ( ASCII character2 )
CR xxx 3 CELLS + ? ( ASCII character code )
CR xxx 4 CELLS + ? ( Boolean flag )
CR xxx 5 CELLS + C@ . ( byte integer )
CR xxx 6 CELLS + ? ( data stack element )
CR xxx 7 CELLS + 2@ D. ( double-precision signed integer - address and length )
CR xxx 9 CELLS + 2@ D. ( double-precision unsigned integer - address and length )
CR xxx 11 CELLS + 2@ D. ( double-precision unsigned integer constant - address and length )
CR xxx 13 CELLS + 2@ D. ( double-precision unsigned integer value - address and length )
CR xxx 15 CELLS + @ 2@ D. ( double-precision unsigned integer variable - address and length )
CR xxx 16 CELLS + ? ( execution token )
CR xxx 17 CELLS + F@ F. ( floating-point number )
CR xxx 18 CELLS + F@ F. ( floating-point number constant )
CR xxx 19 CELLS + F@ F. ( floating-point number value )
CR xxx 20 CELLS + @ F@ F. ( floating-point number variable )
CR xxx 21 CELLS + ? ( memory address )
CR xxx 22 CELLS + ? ( return stack element)
CR xxx 23 CELLS + ? ( single-precision signed integer )
CR xxx 24 CELLS + ? ( single-precision unsigned integer )
CR xxx 25 CELLS + ? ( single-precision unsigned integer constant )
CR xxx 26 CELLS + ? ( single-precision unsigned integer value )
CR xxx 27 CELLS + @ ? ( single-precision unsigned integer variable )
CR xxx 28 CELLS + 2@ TYPE ( string constant1 - address and length )
CR xxx 30 CELLS + COUNT TYPE ( string constant2 - length )
CR xxx 32 CELLS + @ XEMIT ( Unicode character1 )
CR xxx 33 CELLS + @ XEMIT ( Unicode character2 )
CR xxx 34 CELLS + ? ( Unicode character code )
Array - Cells - Numbers
ARRAY - CELLS - NUMBERS
VARIABLE xxx Create a variable with the VARIABLE word and a name.
xxx n CELLS ALLOT Turn the variable into a CELLS array by allotting n more cells (cells memory
addresses) to put things into with the variable name, the number, the CELLS word,
and the ALLOT word for a total of n + 1 8-bit cells.
xxx n CELLS ERASE Erase the total number of cells of data stored at the array's address in memory with the
array name, the number, the CELLS word, and the ERASE word to make sure there
are no leftovers from when it was a variable. Note: This erases the array's contents,
but the array address is still on the stack.
xxx n CELLS DUMP Display the array's total number of cells with the array name, the number, the CELLS
word, and the DUMP word to make sure that erasure really happened.
n xxx i CELLS + ! Store a number in the array's specified cell (cells memory address) with the number,
the array name, the index, the CELLS word, the plus (+) word , and the store (!)
word.
n xxx i + ! NOT RECOMMENDED. Or store a number in the array's specified cell (cells
memory address) with the number, the array name, the index, the plus (+) word, and
the store (!) word.
xxx i CELLS + @ . Fetch and display the value of the array's specified cell (cells memory address) with
the array name, the index, the CELLS word, the plus (+) word, the fetch (@) word,
and the dot (.) word.
xxx i CELLS + ? Or fetch and display the value of the array's specified cell (cells memory address) with
the array name, the index, the CELLS word, the plus (+) word, and the question (?)
word.
xxx i CELLS + @ 1+ Modify the fetched value of the array's specified cell (cells memory address) with the
array name, the index, the CELLS word, the plus (+) word, the fetch (@) word, and
the incrementing one-plus (1+) word or the decrementing one-minus (1-) word.
Note: This doesn't change the actual value of the specified cells address of the array.
Store the modified fetched result from the stack back into the array's specified cell
(cells memory address) with the array name, the index, the CELLS word, the plus (+)
xxx i CELLS + ! word, and the store (!) word.
xxx Place the base array address on the stack by using the array name.
ARRAY - CELLS - NUMBERS - EXAMPLE 1
VARIABLE xxx Create the xxx variable.
xxx 3 CELLS ALLOT Turn the xxx variable into a 4 cells array.
xxx 4 CELLS ERASE Erase the data in the xxx array's 4 cells.
xxx 4 CELLS DUMP Display the xxx array's 4 cells to see that erasure happened.
6 xxx 0 CELLS + ! Store a 6 in the xxx array's first cell.
xxx 0 CELLS + @ . Fetch and display the 6 stored in the xxx array's first cell.
xxx 0 CELLS + ? Or fetch and display the 6 stored in the xxx array's first cell.
xxx 0 CELLS + @ 1+ Modify the fetched value of the xxx array's first cell by adding 1 to it.
xxx 0 CELLS + ! Store the modified result in the xxx array's first cell.
xxx 0 CELLS + @ . Fetch and display the 7 stored in the xxx array's first cell.
xxx 0 CELLS + ? Or fetch and display the 7 stored in the xxx array's first cell.
ARRAY - CELLS - NUMBERS - EXAMPLE 2
VARIABLE xxx Create the xxx variable.
xxx 3 CELLS ALLOT Turn the xxx variable into a 4 cells array.
xxx 4 CELLS ERASE Erase the data in the xxx array's 4 cells.
xxx 4 CELLS DUMP Display the xxx array's 4 cells to see that erasure happened.
1 xxx 0 CELLS + ! Store a 1 in the xxx array's first cell.
2 xxx 1 CELLS + ! Store a 2 in the xxx array's second cell.
3 xxx 2 CELLS + ! Store a 3 in the xxx array's third cell.
4 xxx 3 CELLS + ! Store a 4 in the xxx array's fourth cell.
xxx 0 CELLS + @ . Fetch and display the 1 stored in the xxx array's first cell.
xxx 1 CELLS + @ . Fetch and display the 2 stored in the xxx array's second cell.
xxx 2 CELLS + @ . Fetch and display the 3 stored in the xxx array's third cell.
xxx 3 CELLS + @ . Fetch and display the 4 stored in the xxx array's fourth cell.
xxx 0 CELLS + ? Fetch and display the 1 stored in the xxx array's first cell.
xxx 1 CELLS + ? Fetch and display the 2 stored in the xxx array's second cell.
xxx 2 CELLS + ? Fetch and display the 3 stored in the xxx array's third cell.
xxx 3 CELLS + ? Fetch and display the 4 stored in the xxx array's fourth cell.
ARRAY - CELLS - NUMBERS - EXAMPLE 3
VARIABLE xxx Create the xxx variable.
xxx 3 CELLS ALLOT Turn the xxx variable into a 4 cells array.
xxx 4 CELLS ERASE Erase the data in the xxx array's 4 cells.
xxx 4 CELLS DUMP Display the xxx array's 4 cells to see that erasure happened.
2 xxx 0 CELLS + ! Store a 2 in the xxx array's first cell.
4 xxx 1 CELLS + ! Store a 4 in the xxx array's second cell.
6 xxx 2 CELLS + ! Store a 6 in the xxx array's third cell.
8 xxx 3 CELLS + ! Store a 8 in the xxx array's fourth cell.
xxx 0 CELLS + @ . Fetch and display the 2 stored in the xxx array's first cell.
xxx 1 CELLS + @ . Fetch and display the 4 stored in the xxx array's second cell.
xxx 2 CELLS + @ . Fetch and display the 6 stored in the xxx array's third cell.
xxx 3 CELLS + @ . Fetch and display the 8 stored in the xxx array's fourth cell.
xxx 0 CELLS + ? Fetch and display the 2 stored in the xxx array's first cell.
xxx 1 CELLS + ? Fetch and display the 4 stored in the xxx array's second cell.
xxx 2 CELLS + ? Fetch and display the 6 stored in the xxx array's third cell.
xxx 3 CELLS + ? Fetch and display the 8 stored in the xxx array's fourth cell.
xxx 3 CELLS + @ 1+ Modify the fetched value of the xxx array's fourth cell by adding 1 to it.
xxx 2 CELLS + @ 1+ Modify the fetched value of the xxx array's third cell by adding 1 to it.
xxx 1 CELLS + @ 1+ Modify the fetched value of the xxx array's second cell by adding 1 to it.
xxx 0 CELLS + @ 1+ Modify the fetched value of the xxx array's first cell by adding 1 to it.
xxx 0 CELLS + ! Store the modified result in the xxx array's first cell.
xxx 1 CELLS + ! Store the modified result in the xxx array's second cell.
xxx 2 CELLS + ! Store the modified result in the xxx array's third cell.
xxx 3 CELLS + ! Store the modified result in the xxx array's fourth cell.
xxx 0 CELLS + @ . Fetch and display the 3 stored in the xxx array's first cell.
xxx 1 CELLS + @ . Fetch and display the 5 stored in the xxx array's second cell.
xxx 2 CELLS + @ . Fetch and display the 7 stored in the xxx array's third cell.
xxx 3 CELLS + @ . Fetch and display the 9 stored in the xxx array's fourth cell.
xxx 0 CELLS + ? Fetch and display the 3 stored in the xxx array's first cell.
xxx 1 CELLS + ? Fetch and display the 5 stored in the xxx array's second cell.
xxx 2 CELLS + ? Fetch and display the 7 stored in the xxx array's third cell.
xxx 3 CELLS + ? Fetch and display the 9 stored in the xxx array's fourth cell.
Note that when the contents of the cells were modified, they had to be modified in reverse order. This is done to
ensure that they're in the correct order when the next step pulls them off of the stack one by one to store them
back into the array. As an alternative, they could have been modified in their original order and stored in
reverse order or each of them could have been modified and stored as a two-step process before moving on to
the next one.
ARRAY - CELLS - NUMBERS - DOUBLE PRECISION SIGNED - EXAMPLE 1
VARIABLE xxx Create the xxx variable.
xxx 3 2* CELLS ALLOT Turn the xxx variable into a 4 2-cell array.
xxx 4 2* CELLS ERASE Erase the data in the xxx array's 4 2-cell cells.
xxx 4 2* CELLS DUMP Display the xxx array's 4 2-cell cells to make sure it's empty.
-65535 s>d xxx 0 CELLS + 2! Store the -65535 double precision signed integer in the xxx array's first 2 cells.
xxx 0 CELLS + 2@ D. Fetch and display the -65535 stored in the xxx array's first 2 cells.
xxx 0 CELLS + 2@ 1+ Modify the fetched value of the xxx array's first 2 cells by adding 1 to it.
xxx 0 CELLS + 2! Store the modified result in the xxx array's first 2 cells.
xxx 0 CELLS + 2@ D. Fetch and display the 18446744073709486081 stored in the xxx array's first 2 cells.
ARRAY - CELLS - NUMBERS - DOUBLE PRECISION SIGNED - EXAMPLE 2
VARIABLE xxx Create the xxx variable.
xxx 3 2* CELLS ALLOT Turn the xxx variable into a 4 2-cell array.
xxx 4 2* CELLS ERASE Erase the data in the xxx array's 4 2-cell cells.
xxx 4 2* CELLS DUMP Display the xxx array's 4 2-cell cells to make sure it's empty.
-65535 s>d xxx 0 CELLS + 2! Store a 1 in the xxx array's first two cells.
-65536 s>d xxx 2 CELLS + 2! Store a 2 in the xxx array's second two cells.
-65537 s>d xxx 4 CELLS + 2! Store a 3 in the xxx array's third two cells.
-65538 s>d xxx 6 CELLS + 2! Store a 4 in the xxx array's fourth two cells.
xxx 0 CELLS + 2@ D. Fetch and display the -65535 stored in the xxx array's first two cells.
xxx 2 CELLS + 2@ D. Fetch and display the -65536 stored in the xxx array's second two cells.
xxx 4 CELLS + 2@ D. Fetch and display the -65537 stored in the xxx array's third two cells.
xxx 6 CELLS + 2@ D. Fetch and display the -65538 stored in the xxx array's fourth two cells.
Array - Cells - Removing Cells From An Array
ARRAY - CELLS - REMOVING CELLS FROM AN ARRAY
VARIABLE xxx Create a variable with the VARIABLE word and a name.
xxx n CELLS ALLOT Turn the variable into a CELLS array by allotting n more cells (cells memory
addresses) to put things into with the variable name, the number, the CELLS word,
and the ALLOT word for a total of n + 1 8-bit cells.
xxx n CELLS ERASE Erase the total number of cells of data stored at the array's address in memory with the
array name, the number, the CELLS word, and the ERASE word, to make sure there
are no leftovers from when it was a variable. Note: This erases the array's contents,
but the array address is still on the stack.
xxx n CELLS DUMP Display the array's total number of cells with the array name, the number, the CELLS
word, and the DUMP word to make sure that erasure really happened.
n xxx i CELLS + ! Store a number in the array's specified cell (cells memory address) with the number,
the array name, the index, the CELLS word, the plus (+) word , and the store (!)
word.
n xxx i + ! NOT RECOMMENDED. Or store a number in the array's specified cell (cells
memory address) with the number, the array name, the index, the plus (+) word, and
the store (!) word.
xxx i CELLS + @ . Fetch and display the value of the array's specified cell (cells memory address) with
the array name, the index, the CELLS word, the plus (+) word, the fetch (@) word,
and the dot (.) word.
xxx i CELLS + ? Or fetch and display the value of the array's specified cell (cells memory address) with
the array name, the index, the CELLS word, the plus (+) word, and the question (?)
word.
xxx Place the base array address on the stack by using the array name.
xxx -n CELLS ALLOT Remove a number of CELLS from the array with the array name, the negative
number, the CELLS word, and the ALLOT word.
Note that Gforth will not immediately behave as though you have removed the CELLS. The data still exists, and
Gforth will access it if you ask it to. It's your responsibility to be aware that you have done so, because any new
data you create can be overwritten accidentally if you ask Gforth to access the removed CELLS in certain ways
(like erasing them or changing their values, etc.).
ARRAY - CELLS - REMOVING CELLS FROM AN ARRAY - EXAMPLE
VARIABLE xxx Create the xxx variable.
xxx 3 CELLS ALLOT Turn the xxx variable into a 4 cells array.
xxx 4 CELLS ERASE Erase the data in the xxx array's 4 cells.
xxx 4 CELLS DUMP Display the xxx array's 4 cells to see that erasure happened.
1 xxx 0 CELLS + ! Store a 1 in the xxx array's first cell.
2 xxx 1 CELLS + ! Store a 2 in the xxx array's second cell.
3 xxx 2 CELLS + ! Store a 3 in the xxx array's third cell.
4 xxx 3 CELLS + ! Store a 4 in the xxx array's fourth cell.
xxx 0 CELLS + @ . Fetch and display the 1 stored in the xxx array's first cell.
xxx 1 CELLS + @ . Fetch and display the 2 stored in the xxx array's second cell.
xxx 2 CELLS + @ . Fetch and display the 3 stored in the xxx array's third cell.
xxx 3 CELLS + @ . Fetch and display the 4 stored in the xxx array's fourth cell.
xxx 0 CELLS + ? Fetch and display the 1 stored in the xxx array's first cell.
xxx 1 CELLS + ? Fetch and display the 2 stored in the xxx array's second cell.
xxx 2 CELLS + ? Fetch and display the 3 stored in the xxx array's third cell.
xxx 3 CELLS + ? Fetch and display the 4 stored in the xxx array's fourth cell.
xxx -2 CELLS ALLOT Remove 2 CELLS from the xxx array.
Array - Cells - String Constant
ARRAY - CELLS - STRING CONSTANT - METHOD 1
VARIABLE xxx Create a variable with the VARIABLE word and a name.
xxx n 2* CELLS ALLOT Turn the variable into a 2-cell CELLS array by allotting n more cells (cells
memory addresses) to put things into with the variable name, the number, the
two-star (2*) word, the CELLS word, and the ALLOT word for a total of n
+ 1 8-bit byte cells.
xxx n 2* CELLS ERASE Erase the total number of 2-cell cells of data stored at the array's address in
memory with the array name, the number, the two-star (2*) word, the
CELLS word, and the ERASE word, to make sure there are no leftovers
from when it was a variable, the array address being still on the stack.
xxx n 2* CELLS DUMP Display the array's total number of 2-cell cells with the array name, the
number, the two-star (2*) word, the CELLS word, and the DUMP word to
make sure that erasure really happened.
S" example" xxx i CELLS + 2! Store a string constant in the array's specified two cells (cells memory
addresses) with the string constant, the array name, the index, the CELLS
word, the plus (+) word, and the two-store (2!) word.
xxx i CELLS + 2@ TYPE Fetch and display the string of character codes from the array's specified two
cells with the array name, the index, the CELLS word, the plus (+) word, the
two-fetch (2@) word, and the TYPE word.
xxx Place the base array address on the stack by using the array name.
Strings of character codes need and use 2 cells.
ARRAY - CELLS - STRING CONSTANT - METHOD 1 - EXAMPLE 1
VARIABLE xxx Create the xxx variable.
xxx 3 2* CELLS ALLOT Turn the xxx variable into a 4 2-cell cells array.
xxx 4 2* CELLS ERASE Erase the data in the xxx array's 4 2-cell cells.
xxx 4 2* CELLS DUMP Display the xxx array's 4 2-cell cells to make sure that erasure happened.
S" hello" xxx 0 CELLS + 2! Store the hello string constant in the xxx array's first two cells.
xxx 0 CELLS + 2@ TYPE Fetch and display hello from the xxx array's first two cells.
ARRAY - CELLS - STRING CONSTANT - METHOD 1 - EXAMPLE 2
VARIABLE xxx Create the xxx variable.
xxx 5 2* CELLS ALLOT Turn the xxx variable into a 6 2-cell cells array.
xxx 6 2* CELLS ERASE Erase the data in the xxx array's 6 2-cell cells.
xxx 6 2* CELLS DUMP Display the xxx array's 6 2-cell cells to make sure that erasure happened.
S" apple" xxx 0 CELLS + 2! Store apple in the xxx array's first 2 cells.
S" banana" xxx 2 CELLS + 2! Store banana in the xxx array's second 2 cells.
S" coconut" xxx 4 CELLS + 2! Store coconut in the xxx array's third 2 cells.
S" date" xxx 6 CELLS + 2! Store date in the xxx array's fourth 2 cells.
xxx 0 CELLS + 2@ TYPE Fetch and display apple from the xxx array's first 2 cells.
xxx 2 CELLS + 2@ TYPE Fetch and display banana from the xxx array's second 2 cells.
xxx 4 CELLS + 2@ TYPE Fetch and display coconut from the xxx array's third 2 cells.
xxx 6 CELLS + 2@ TYPE Fetch and display date from the xxx array's fourth 2 cells.
ARRAY - CELLS - STRING CONSTANT - METHOD 2
VARIABLE xxx Create a variable with the VARIABLE word and a name.
xxx n 2* CELLS ALLOT Turn the variable into a two-cell CELLS array by allotting n more cells
(cells memory addresses) to put things into with the variable name, the
number, the two-star word, the CELLS word, and the ALLOT word for
a total of n + 1 8-bit byte cells.
xxx n 2* CELLS ERASE Erase the total number of two-cell cells (cells memory addresses) of data
stored at the array's address in memory with the array name, the number,
the two-star (2*) word, the CELLS word, and the ERASE word to
make sure there are no leftovers from when it was a variable, the array
address being still on the stack.
xxx n 2* CELLS DUMP Display the array's total number of two-cell cells with the array name,
the number, the two-star word, the CELLS word, and the DUMP word,
to make sure that erasure really happened.
S" example" xxx i CELLS + PLACE Store a string constant in the array's specified 2 cells (cells memory
address) with the string constant, the array name, the index, the CELLS
word, the plus (+) word, and the PLACE word.
xxx i CELLS + COUNT TYPE Fetch and display the string of character codes from the array's specified
2 cells with the array name, the index, the CELLS word, the plus (+)
word, the COUNT word, and the TYPE word. Note: Use this for strings
of character codes that were stored with the PLACE word.
xxx Place the base array address on the stack by using the array name.
Strings of character codes need and use 2 cells.
ARRAY - CELLS - STRING CONSTANT - METHOD 2 - EXAMPLE 1
VARIABLE xxx Create the xxx variable.
xxx 3 2* CELLS ALLOT Turn the xxx variable into a 4 2-cell cells array.
xxx 4 2* CELLS ERASE Erase the data in the xxx array's 4 2-cell cells.
xxx 4 2* CELLS DUMP Display the xxx array's 4 2-cells cells to make sure that erasure happened.
S" hello" xxx 0 CELLS + PLACE Store hello in the xxx array's first 2 2-cell cells.
xxx 0 CELLS + COUNT TYPE Fetch and display hello from the xxx array's first two cells.
ARRAY - CELLS - STRING CONSTANT - METHOD 2 - EXAMPLE 2
VARIABLE xxx Create the xxx variable.
xxx 3 2* CELLS ALLOT Turn the xxx variable into a 4 2-cell cells array.
xxx 4 2* CELLS ERASE Erase the data in the xxx array's 4 2-cell cells.
xxx 4 2* CELLS DUMP Display the xxx array's 4 2-cell cells to make sure that erasure happened.
S" apple" xxx 0 CELLS + PLACE Store apple in the xxx array's first 2 cells.
S" banana" xxx 2 CELLS + PLACE Store banana in the xxx array's second 2 cells.
S" coconut" xxx 4 CELLS + PLACE Store coconut in the xxx array's third 2 cells.
S" date" xxx 6 CELLS + PLACE Store date in the xxx array's fourth 2 cells.
xxx 0 CELLS + COUNT TYPE Fetch apple's address and length from the xxx array's first 2 cells and display apple.
xxx 2 CELLS + COUNT TYPE Fetch banana's address and length from the xxx array's second 2 cells and display banana.
xxx 4 CELLS + COUNT TYPE Fetch coconut's address and length from the xxx array's third 2 cells and displaty coconut .
xxx 6 CELLS + COUNT TYPE Fetch date's address and length from the xxx array's fourth 2 cells and display date.
Array - Cells - String Constant With Unicode As Variable
Name
ARRAY - CELLS - STRING CONSTANT WITH UNICODE AS VARIABLE NAME - METHOD 1
VARIABLE xxx Create a variable with the VARIABLE word and a name.
xxx n CELLS ALLOT Turn a variable into a CELLS array by allotting n more cells (cells memory
addresses) to put things into with the array name, the number, the CELLS
word, and the ALLOT word for a total of n + 1 8-bit cells.
xxx n CELLS ERASE Erase the total number of cells (cells memory addresses) of data stored at the
array's address in memory with the array name, the number, the CELLS
word, and the ERASE word to make sure there are no leftovers from when it
was a variable, the array address being still on the stack.
xxx n CELLS DUMP Display the array's total number of cells (cells memory addresses) with the
array name, the number, the CELLS word, and the DUMP word to make
sure that erasure really happened.
S" example" xxx i CELLS + 2! Store a string constant in the specified array's specified two cells (cells
memory addresses) with the string constant, the array name, the index, the
CELLS word, the plus (+) word, and the two-store (2!) word.
xxx i CELLS + 2@ TYPE Fetch and display the string of character codes from the array's specified two
cells (cells memory addresses) with the array name, the index, the CELLS
word, the plus (+) word, the two-fetch (2@) word, and the TYPE word.
xxx Place the base array address on the stack by using the array name.
Strings of character codes need and use 2 cells.
ARRAY - CELLS - STRING CONSTANT WITH UNICODE AS VARIABLE NAME - METHOD 1 - EXAMPLE 1
VARIABLE ☼ Create the ☼variable (a variable with a Unicode character for its name).
☼ 4 2* CELLS ALLOT Turn the ☼ variable into a 4 2-cell cells array (because each string of
character codes uses 2 cells).
☼ 4 2* CELLS ERASE Erase the data in the ☼ array's 4 2-cell cells.
☼ 4 2* CELLS DUMP Display the ☼ array's 4 2-cell cells to make sure that erasure happened.
S" hello" ☼ 0 CELLS + 2! Store hello in the ☼ array's first two cells.
S" world" ☼ 2 CELLS + 2! Store world in the ☼ array's second two cells.
☼ 0 CELLS + 2@ TYPE Fetch hello from the ☼ array's first two cells and display it.
☼ 2 CELLS + 2@ TYPE Fetch world from the ☼ array's second two cells and display it.
ARRAY - CELLS - STRING CONSTANT WITH UNICODE AS VARIABLE NAME - METHOD 1 - EXAMPLE 2
VARIABLE ☼ Create the ☼variable (a variable with a Unicode character for its name).
☼ 4 2* CELLS ALLOT Turn the ☼ variable into a 4 2-cell cells array (because each string of
character codes uses 2 cells).
☼ 4 2* CELLS ERASE Erase the data in the ☼ array's 4 2-cell cells.
☼ 4 2* CELLS DUMP Display the ☼ array's 4 2-cell cells to make sure that erasure happened.
S" apple" ☼ 0 CELLS + 2! Store apple in the ☼ array's first two cells.
S" banana" ☼ 2 CELLS + 2! Store banana in the ☼ array's second two cells.
S" coconut" ☼ 4 CELLS + 2! Store coconut in the ☼ array's third two cells.
S" date" ☼ 6 CELLS + 2! Store date in the ☼ array's fourth two cells.
☼ 0 CELLS + 2@ TYPE Fetch hello from the ☼ array's first two cells and display it.
☼ 2 CELLS + 2@ TYPE Fetch world from the ☼ array's second two cells and display it.
☼ 4 CELLS + 2@ TYPE Fetch world from the ☼ array's third two cells and display it.
☼ 6 CELLS + 2@ TYPE Fetch world from the ☼ array's fourth two cells and display it.
ARRAY - CELLS - STRING CONSTANT WITH UNICODE AS VARIABLE NAME - METHOD 2
VARIABLE xxx Create a variable with the VARIABLE word and a name.
xxx n CELLS ALLOT Turn the variable into a CELLS array by allotting n more cells (cells
memory addresses) to put things into with the variable name, the
number, the CELLS word, and the ALLOT word, for a total of n + 1 8-
bit cells.
xxx n CELLS ERASE Erase the total number of cells (cells memory addresses) of data stored at
the array's address in memory with the array name, the number, the
CELLS word, and the ERASE word, to make sure there are no leftovers
from when it was a variable, the array address being still on the stack.
xxx n CELLS DUMP Display the array's total number of cells (cells memory addresses) with
the array name, the number, the CELLS word, and the DUMP word, to
make sure that erasure really happened.
S" example" xxx i CELLS + PLACE Store a string constant in the array's specified 2 cells (cells memory
address) with the string constant, the array name, the index, the CELLS
word, the plus (+) word, and the PLACE word.
xxx i CELLS + COUNT TYPE Fetch and display the string of character codes from the array's specified
2 cells (cells memory addresses) with the array name, the index, the
CELLS word, the plus (+) word, the COUNT word, and the TYPE
word. Note: Use this for strings of character codes that were stored with
the PLACE word.
xxx Place the base array address on the stack by using the array name.
Strings of character codes need and use 2 cells.
ARRAY - CELLS - STRING CONSTANT WITH UNICODE AS VARIABLE NAME - METHOD 2 - EXAMPLE 1
VARIABLE ☼ Create the ☼variable (a variable with a Unicode character for its name).
☼ 4 2* CELLS ALLOT Turn the ☼ variable into a 4 2-cell cells array (because each string of
character codes uses 2 cells).
☼ 4 2* CELLS ERASE Erase the data in the ☼ array's 4 2-cell cells.
☼ 4 2* CELLS DUMP Display the ☼ array's 4 2-cell cells to make sure that erasure happened.
S" hello" ☼ 0 CELLS + PLACE Store hello in the ☼ array's first two cells.
S" world" ☼ 2 CELLS + PLACE Store world in the ☼ array's second two cells.
☼ COUNT TYPE Display hello stored in the ☼array's first two cells.
☼ 0 CELLS + COUNT TYPE Fetch hello and its length stored in the ☼array's first two cells and display hello.
☼ 2 CELLS + COUNT TYPE Fetch world and its length stored in the ☼array's second two cells and display world.
ARRAY - CELLS - STRING CONSTANT WITH UNICODE AS VARIABLE NAME - METHOD 2 - EXAMPLE 2
VARIABLE ☼ Create the ☼variable (a variable with a Unicode character for its name).
☼ 4 2* CELLS ALLOT Turn the ☼ variable into a 4 2-cell cells array (because each string of
character codes uses 2 cells).
☼ 4 2* CELLS ERASE Erase the data in the ☼ array's 4 2-cell cells.
☼ 4 2* CELLS DUMP Display the ☼ array's 4 2-cell cells to make sure that erasure happened.
S" apple" ☼ 0 CELLS + PLACE Store apple in the ☼ array's first two cells.
S" banana" ☼ 2 CELLS + PLACE Store banana in the ☼ array's second two cells.
S" coconut" ☼ 4 CELLS + PLACE Store coconut in the ☼ array's third two cells.
S" date" ☼ 6 CELLS + PLACE Store date in the ☼ array's fourth two cells.
☼ COUNT TYPE Display hello stored in the ☼array's first two cells.
☼ 0 CELLS + COUNT TYPE Fetch apple and its length stored in the ☼array's first two cells and display hello.
☼ 2 CELLS + COUNT TYPE Fetch banana and its length stored in the ☼array's second two cells and display world.
☼ 4 CELLS + COUNT TYPE Fetch coconut and its length stored in the ☼array's third two cells and display world.
☼ 6 CELLS + COUNT TYPE Fetch date and its length stored in the ☼array's fourth two cells and display world.
Array - Cells - Unicode Character
ARRAY - CELLS - UNICODE CHARACTER
VARIABLE xxx Create a variable with the VARIABLE word and a name.
xxx n CELLS ALLOT Turn the variable into a byte array by allotting n more cells (cells memory
addresses) to put things into with the variable name, the number, the CELLS
word, and the ALLOT word, for a total of n + 1 8-bit cells.
xxx n CELLS ERASE Erase the total number of cells (cells memory addresses) of data stored at the
array's address in memory with the array name, the number, the CELLS word,
and the ERASE word, to make sure there are no leftovers from when it was a
variable, the array address being still on the stack.
xxx n CELLS DUMP Display the array's total number of cells (cells memory addresses) with the array
name, the number, the CELLS word, and the DUMP word, to make sure that
erasure really happened.
'u xxx i CELLS + ! Store a ticked Unicode character in the array's specified cell (cells memory
address) by using the tick (') word, a Unicode character, the array name, the index,
the CELLS word, the plus (+) word, and the store (!) word.
'u xxx i + ! NOT RECOMMENDED. Or store a Unicode character in the array's specified
cell (cells memory address) by using the tick (') word, a Unicode character, the
array name, the index, the plus (+) word, and the store (!) word.
xxx i CELLS + @ XEMIT Fetch and display the Unicode character stored in the array's specified cell (cells
memory address) with the array name, the index, the CELLS word, the plus (+)
word, the fetch (@) word, and the XEMIT word.
xxx i + @ XEMIT NOT RECOMMENDED. Or fetch and display the Unicode character stored in
the array's specified cell (cells memory address) with the array name, the index, the
plus (+) word, the fetch (@) word, and the XEMIT word.
xxx i CELLS + @ . Fetch and display the Unicode character's decimal numeric value stored in the
array's specified cell (cells memory address) with the array name, the index, the
CELLS word, the plus (+) word, the fetch (@) word, and the dot (.) word.
xxx i CELLS + ? Or fetch and display the Unicode character's decimal numeric value stored in the
array's specified cell (cells memory address) with the array name, the index, the
CELLS word, the plus (+) word, and the question (?) word.
xxx i + @ . NOT RECOMMENDED. Fetch and display the Unicode character's decimal
numeric value stored in the array's specified cell (cells memory address) with the
array name, the index, the plus (+) word, the fetch (@) word, and the dot (.) word.
xxx Place the base array address on the stack by using the array name.
ARRAY - CELLS - UNICODE CHARACTER - EXAMPLE 1
VARIABLE xxx Create the xxx variable.
xxx 3 CELLS ALLOT Turn the xxx variable into a 4 cells array.
xxx 4 CELLS ERASE Erase the data in the xxx array's 4 cells.
xxx 4 CELLS DUMP Display the xxx array's 4 cells to make sure that erasure happened.
'☺ xxx 0 CELLS + ! Store a ticked ☺ in the xxx array's first cell.
xxx 0 CELLS + @ XEMIT Fetch and display the ☺ stored in the xxx array's first cell.
xxx 0 CELLS + @ . Fetch and display the 9786 stored in the xxx array's first cell.
ARRAY - CELLS - UNICODE CHARACTER - EXAMPLE 2
VARIABLE xxx Create the xxx variable.
xxx 3 CELLS ALLOT Turn the xxx variable into a 4 cells array.
xxx 4 CELLS ERASE Erase the data in the xxx array's 4 cells.
xxx 4 CELLS DUMP Display the xxx array's 4 cells to make sure that erasure happened.
'☺ xxx 0 CELLS + ! Store a ticked ☺ in the xxx array's first cell.
'☻ xxx 1 CELLS + ! Store a ticked ☻ in the xxx array's second cell.
'☼ xxx 2 CELLS + ! Store a ticked ☼ in the xxx array's third cell.
'☹ xxx 3 CELLS + ! Store a ticked ☹ in the xxx array's fourth cell.
xxx 0 CELLS + @ XEMIT Fetch and display the ☺ stored in the xxx array's first cell.
xxx 1 CELLS + @ XEMIT Fetch and display the ☻ stored in the xxx array's second cell.
xxx 2 CELLS + @ XEMIT Fetch and display the ☼ stored in the xxx array's third cell.
xxx 3 CELLS + @ XEMIT Fetch and display the ☹ stored in the xxx array's fourth cell.
xxx 0 CELLS + @ . Fetch and display the 9786 stored in the xxx array's first cell.
xxx 1 CELLS + @ . Fetch and display the 9787 stored in the xxx array's second cell.
xxx 2 CELLS + @ . Fetch and display the 9788 stored in the xxx array's third cell.
xxx 3 CELLS + @ . Fetch and display the 9785 stored in the xxx array's fourth cell.
xxx 0 CELLS + ? Fetch and display the 9786 stored in the xxx array's first cell.
xxx 1 CELLS + ? Fetch and display the 9787 stored in the xxx array's second cell.
xxx 2 CELLS + ? Fetch and display the 9788 stored in the xxx array's third cell.
xxx 3 CELLS + ? Fetch and display the 9785 stored in the xxx array's fourth cell.
Array - Cells - Unicode Character Code
ARRAY - CELLS - UNICODE CHARACTER CODE- METHOD 1
VARIABLE xxx Create a variable with the VARIABLE word and a name.
xxx n CELLS ALLOT Turn the variable into a CELLS array by allotting n more cells (cells memory
addresses) to put things into with the variable name, the number, the CELLS
word, and the ALLOT word, for a total of n + 1 8-bit cells.
xxx n CELLS ERASE Erase the total number of cells (cells memory addresses) of data stored at the
array's address in memory with the array name, the number, the CELLS word,
and the ERASE word, to make sure there are no leftovers from when it was a
variable, the array address being still on the stack.
xxx n CELLS DUMP Display the array's total number of cells (cells memory addresses) with the array
name, the number, the CELLS word, and the DUMP word, to make sure that
erasure really happened.
HEX u xxx i CELLS + ! Store a Unicode character in the array's specified cell (cells memory address)
with the HEX word, a hexadecimal numeric code, the array name, the index, the
CELLS word, the plus (+) word, and the store (!) word.
xxx i CELLS + ? Fetch and display the hexadecimal numeric code stored in the array's specified
cell (cells memory address) with the array name, the index, the CELLS word,
the plus (+) word, and the question (?) word.
xxx @ XEMIT Fetch and display the Unicode character stored in the array's specified cell (cells
memory address) with the array name, the fetch (@) word, and the XEMIT
word.
xxx i CELLS + @ XEMIT Fetch and display the specified Unicode character stored in the array's specified
cell (cells memory address) with the array name, the index, the CELLS word,
the plus (+) word, the fetch (@) word, and the XEMIT word.
DECIMAL Put Forth back into base 10 (decimal) mode with the DECIMAL word.
xxx Place the base array address on the stack by using the array name.
ARRAY - CELLS - UNICODE CHARACTER CODE - METHOD 1 - EXAMPLE 1
VARIABLE xxx Create the xxx variable.
xxx 3 CELLS ALLOT Turn the xxx variable into a 4 cells array.
xxx 4 CELLS ERASE Erase the data in the xxx array's 4 cells.
xxx 4 CELLS DUMP Display the xxx array's 4 cells to make sure that erasure happened.
HEX 263A xxx 0 CELLS + ! Store the 263A hexadecimal numeric code in the xxx array's first cell.
xxx 0 CELLS + ? Fetch and display the 263A stored in the xxx array's first cell.
xxx @ XEMIT Fetch and display the ☺ stored in the xxx array's first cell.
xxx 0 CELLS + @ XEMIT Fetch and display the ☺ stored in the xxx array's first cell.
DECIMAL Put Forth back into base 10 (decimal) mode.
ARRAY - CELLS - UNICODE CHARACTER CODE - METHOD 1 - EXAMPLE 2
VARIABLE xxx Create the xxx variable.
xxx 3 CELLS ALLOT Turn the xxx variable into a 4 cells array.
xxx 4 CELLS ERASE Erase the data in the xxx array's 4 cells.
xxx 4 CELLS DUMP Display the xxx array's 4 cells to make sure that erasure happened.
HEX 263A xxx 0 CELLS + ! Store 263A hexadecimal numeric code in the xxx array's first cell.
HEX 263B xxx 1 CELLS + ! Store 263B hexadecimal numeric code in the xxx array's second cell.
HEX 263C xxx 2 CELLS + ! Store 263C hexadecimal numeric code in the xxx array's third cell.
HEX 2639 xxx 3 CELLS + ! Store 2639 hexadecimal numeric code in the xxx array's fourth cell.
xxx 0 CELLS + ? Fetch and display the 263A stored in the xxx array's first cell.
xxx 1 CELLS + ? Fetch and display the 263B stored in the xxx array's second cell.
xxx 2 CELLS + ? Fetch and display the 263C stored in the xxx array's third cell.
xxx 3 CELLS + ? Fetch and display the 2639 stored in the xxx array's fourth cell.
xxx 0 CELLS + @ XEMIT Fetch and display the ☺stored in the xxx array's first cell.
xxx 1 CELLS + @ XEMIT Fetch and display the ☻stored in the xxx array's second cell.
xxx 2 CELLS + @ XEMIT Fetch and display the ☼stored in the xxx array's third cell.
xxx 3 CELLS + @ XEMIT Fetch and display the ☹ stored in the xxx array's fourth cell.
DECIMAL Put Forth back into base 10 (decimal) mode.
ARRAY - CELLS - UNICODE CHARACTER CODE - METHOD 2
HEX Put Forth into base 16 (hexadecimal) mode with the HEX word.
VARIABLE xxx Create a variable with the VARIABLE word and a name.
xxx n CELLS ALLOT Turn the variable into a CELLS array by allotting n more cells (cells memory
addresses) to put things into with the variable name, the number, the CELLS
word, and the ALLOT word, for a total of n + 1 8-bit cells.
xxx n CELLS ERASE Erase the total number of cells (cells memory addresses) of data stored at the
array's address in memory with the array name, the number, the CELLS word, and
the ERASE word, to make sure there are no leftovers from when it was a variable,
the array address being still on the stack.
xxx n CELLS DUMP Display the array's total number of cells (cells memory addresses) with the array
name, the specified number, the CELLS word, and the DUMP word, to make sure
that erasure really happened.
u xxx i CELLS + ! Store a Unicode character's hexadecimal numeric code in the array's specified cell
(cells memory address) with a decimal numeric code, the array name, the index,
the CELLS word, the plus (+) word, and the store (!) word.
xxx @ XEMIT Fetch and display the Unicode character stored in the array's specified cell (cells
memory address) with the array name, the fetch (@) word, and the XEMIT word.
xxx i CELLS + @ XEMIT Fetch and display the Unicode character stored in the array's specified cell (cells
memory address) with the array name, the index, the CELLS word, the plus (+)
word, the fetch (@) word, and the XEMIT word.
xxx i + @ XEMIT NOT RECOMMENDED. Fetch and display the Unicode character stored in the
array's specified cell (cells memory address) with the array name, the index, the
plus (+) word, the fetch (@) word, and the XEMIT word.
xxx i CELLS + ? Fetch and display the Unicode character's hexadecimal numeric code stored in the
array's specified cell (cells memory address) with the array name, the index, the
CELLS word, the plus (+) word, and the question (?) word.
xxx i + ? NOT RECOMMENDED. Fetch and display the Unicode character's hexadecimal
numeric code stored in the array's specified cell (cells memory address) with the
array name,the index, the plus (+) word, and the question (?) word.
DECIMAL Put Forth back into base 10 (decimal) mode with the DECIMAL word.
xxx Place the base array address on the stack by using the array name.
ARRAY - CELLS - UNICODE CHARACTER CODE - METHOD 2 - EXAMPLE 1
HEX Put Forth into base 16 (hexadecimal) mode.
VARIABLE xxx Create the xxx variable.
xxx 3 CELLS ALLOT Turn the xxx variable into a 4 cells array.
xxx 4 CELLS ERASE Erase the data in the xxx array's 4 cells.
xxx 4 CELLS DUMP Display the xxx array's 4 cells to make sure that erasure happened.
263B xxx 0 CELLS + ! Store 263B hexadecimal numeric code in the xxx array's first cell.
xxx @ XEMIT Fetch and display the ☻stored in the xxx array's first cell.
xxx 0 CELLS + @ XEMIT Fetch and display the ☻stored in the xxx array's first cell.
xxx 0 CELLS + ? Fetch and display the 263B stored in the xxx array's first cell.
DECIMAL Put Forth back into base 10 (decimal) mode.
ARRAY - CELLS - UNICODE CHARACTER CODE - METHOD 2 - EXAMPLE 2
HEX Put Forth into base 16 (hexadecimal) mode.
VARIABLE xxx Create the xxx variable.
xxx 3 CELLS ALLOT Turn the xxx variable into a 4 cells array.
xxx 4 CELLS ERASE Erase the data in the xxx array's 4 cells.
xxx 4 CELLS DUMP Display the xxx array's 4 cells to make sure that erasure happened.
263A xxx 0 CELLS + ! Store hexadecimal numeric code 263A in the xxx array's first cell.
263B xxx 1 CELLS + ! Store hexadecimal numeric code 263B in the xxx array's second cell.
263C xxx 2 CELLS + ! Store hexadecimal numeric code 263C in the xxx array's third cell.
2639 xxx 3 CELLS + ! Store hexadecimal numeric code 2639 in the xxx array's fourth cell.
xxx @ XEMIT Fetch and display the ☺ stored in the xxx array's first cell.
xxx 1 CELLS + @ XEMIT Fetch and display the ☻ stored in the xxx array's second cell.
xxx 2 CELLS + @ XEMIT Fetch and display the ☼ stored in the xxx array's third cell.
xxx 3 CELLS + @ XEMIT Fetch and display the ☹ stored in the xxx array's fourth cell.
xxx 0 CELLS + @ XEMIT Fetch and display the ☺ stored in the xxx array's first cell.
xxx 1 CELLS + @ XEMIT Fetch and display the ☻ stored in the xxx array's second cell.
xxx 2 CELLS + @ XEMIT Fetch and display the ☼ stored in the xxx array's third cell.
xxx 3 CELLS + @ XEMIT Fetch and display the ☹ stored in the xxx array's fourth cell.
xxx 0 CELLS + ? Fetch and display the 263A stored in the xxx array's first cell.
xxx 1 CELLS + ? Fetch and display the 263B stored in the xxx array's second cell.
xxx 2 CELLS + ? Fetch and display the 263C stored in the xxx array's third cell.
xxx 3 CELLS + ? Fetch and display the 2639 stored in the xxx array's fourth cell.
DECIMAL Put Forth back into base 10 (decimal) mode.
Array - Chars - ASCII
ARRAY - CHARS - ASCII CHARACTER CODE
VARIABLE xxx Create a variable with the VARIABLE word and a name.
xxx n CHARS ALLOT Turn the variable into a CHARS array by allotting n more byte blocks to put
things into with the variable name, the number, the CHARS word, and the
ALLOT word for a total of n + 1 8-bit byte blocks.
xxx n CHARS ERASE Erase the total number of byte blocks of data stored at the array's address in
memory with the array name, the number, the CHARS word, and the ERASE
word, to make sure there are no leftovers from when it was a variable. Note: This
erases the array's contents, but leaves the array address on the stack.
xxx n CHARS DUMP Display the array's total number of byte blocks with the array name, the number,
the CHARS word, and the DUMP word, to make sure that erasure really
happened.
code xxx i CHARS + C! Store an ASCII character code in the array's specified byte block address by using
the ASCII character code, the array name, the index, the CHARS word, the plus
(+) word, and the c-store (C!) word.
code xxx i + C! NOT RECOMMENDED. Or store an ASCII character code in the array's
specified byte block address by using the code, the array name, the index, the
CHARS word, the plus (+) word, and the c-store (C!) word.
xxx i CHARS + C@ EMIT Fetch and display the ASCII character from the array's specified byte block
address with the array name, the index, the CHARS word, the plus (+) word, the
c-fetch (C@) word, and the EMIT word.
xxx i + C@ EMIT NOT RECOMMENDED. Or fetch and display the ASCII character from the
array's specified byte block address with the array name, the index, the plus (+)
word, the c-fetch (C@) word, and the EMIT word.
xxx i CHARS + C@ . Fetch and display the ASCII character code from the array's specified byte block
address with the array name, the index, the CHARS word, the plus (+) word, the
c-fetch (C@) word, and the dot (.) word.
xxx i + C@ . NOT RECOMMENDED. Or fetch and display the ASCII character code from
the array's specified byte block address with the array name, the index, the plus
(+) word, the c-fetch (C@) word, and the dot (.) word.
xxx Place the base array address on the stack by using the array name.
ASCII code is a 1-byte decimal numeric value that can be interpreted as a character.
You can use a CELLS array for ASCII character codes, but there would be unused space in each 8-bit cell.
ARRAY - CHARS - ASCII CHARACTER CODE - EXAMPLE 1
VARIABLE xxx Create the xxx variable.
xxx 3 CHARS ALLOT Turn the xxx variable into a 4-block CHARS array.
xxx 4 CHARS ERASE Erase the data in the xxx array's 4 byte blocks.
xxx 4 CHARS DUMP Display the xxx array's 4 byte blocks to make sure that erasure happened.
'a xxx 0 CHARS + C! Store a ticked a in the xxx array's first byte block address.
xxx 0 CHARS + C@ EMIT Fetch and display the a stored in the xxx array's first byte block address.
xxx 0 CHARS + C@ . Fetch and display the 97 stored in the xxx array's first byte block address.
ARRAY - CHARS - ASCII CHARACTER CODE - EXAMPLE 2
VARIABLE xxx Create the xxx variable.
xxx 3 CHARS ALLOT Turn the xxx variable into a 4-block CHARS array.
xxx 4 CHARS ERASE Erase the data in the xxx array's 4 byte blocks.
xxx 4 CHARS DUMP Display the xxx array's 4 byte blocks to make sure that erasure happened.
'a xxx 0 CHARS + C! Store a ticked a in the xxx array's first byte block address.
'b xxx 1 CHARS + C! Store a ticked b in the xxx array's second byte block address.
'c xxx 2 CHARS + C! Store a ticked c in the xxx array's third byte block address.
'd xxx 3 CHARS + C! Store a ticked d in the xxx array's fourth byte block address.
xxx 0 CHARS + C@ EMIT Fetch and display the a stored in the xxx array's first byte block address.
xxx 1 CHARS + C@ EMIT Fetch and display the b stored in the xxx array's second byte block address.
xxx 2 CHARS + C@ EMIT Fetch and display the c stored in the xxx array's third byte block address.
xxx 3 CHARS + C@ EMIT Fetch and display the d stored in the xxx array's fourth byte block address.
xxx 0 CHARS + C@ . Fetch and display the 97 stored in the xxx array's first byte block address.
xxx 1 CHARS + C@ . Fetch and display the 98 stored in the xxx array's second byte block address.
xxx 2 CHARS + C@ . Fetch and display the 99 stored in the xxx array's third byte block address.
xxx 3 CHARS + C@ . Fetch and display the 100 stored in the xxx array's fourth byte block address.
ARRAY - CHARS - ASCII CHARACTER CODE - EXAMPLE 3
VARIABLE xxx Create the xxx variable.
xxx 3 CHARS ALLOT Turn the xxx variable into a 4-block CHARS array.
xxx 4 CHARS ERASE Erase the data in the xxx array's 4 byte blocks.
xxx 4 CHARS DUMP Display the xxx array's 4 byte blocks to make sure that erasure happened.
97 xxx 0 CHARS + C! Store 97 in the xxx array's first byte block address .
xxx 0 CHARS + C@ EMIT Fetch and display the a stored in the xxx array's first byte block address.
xxx 0 CHARS + C@ . Fetch and display the 97 stored in the xxx array's first byte block address.
ARRAY - CHARS - ASCII CHARACTER CODE - EXAMPLE 4
VARIABLE xxx Create the xxx variable.
xxx 3 CHARS ALLOT Turn the xxx variable into a 4-block CHARS array.
xxx 4 CHARS ERASE Erase the data in the xxx array's 4 byte blocks.
xxx 4 CHARS DUMP Display the xxx array's 4 byte blocks to make sure that erasure happened.
97 xxx 0 CHARS + C! Store 97 in the xxx array's first byte block address .
98 xxx 1 CHARS + C! Store 98 in the xxx array's second byte block address.
99 xxx 2 CHARS + C! Store 99 in the xxx array's third byte block address.
100 xxx 3 CHARS + C! Store 100 in the xxx array's fourth byte block address.
xxx 0 CHARS + C@ EMIT Fetch and display the a stored in the xxx array's first byte block address.
xxx 1 CHARS + C@ EMIT Fetch and display the b stored in the xxx array's second byte block address.
xxx 2 CHARS + C@ EMIT Fetch and display the c stored in the xxx array's third byte block address.
xxx 3 CHARS + C@ EMIT Fetch and display the d stored in the xxx array's fourth byte block address.
xxx 0 CHARS + C@ . Fetch and display the 97 stored in the xxx array's first byte block address .
xxx 1 CHARS + C@ . Fetch and display the 98 stored in the xxx array's second byte block address.
xxx 2 CHARS + C@ . Fetch and display the 99 stored in the xxx array's third byte block address.
xxx 3 CHARS + C@ . Fetch and display the 100 stored in the xxx array's fourth byte block address.
Array - Chars - Create - ASCII
ARRAY - CHARS - CREATE - ASCII CHARACTER CODE
CREATE xxx 'code1 C, 'code2 C, Create a CHARS array with the CREATE word, an array name, and one or
'code3 C, 'code4 C, more ASCII character codes, with each value prefixed by a tick (') word,
and with a c-comma (C,) word after each value.
xxx i CHARS + C@ EMIT Fetch and display the value of the array's specified byte block address with
the array name, the index, the CHARS word, the plus (+) word, the c-fetch
(c@) word, and the EMIT word.
xxx i CHARS + ? Fetch and display the ASCII character code stored in the array's specified
byte block address with the array name, the index, the CHARS word, the
plus (+) word, and the question (?) word.
xxx Place the base array address on the stack by using the array name.
ASCII code is a 1-byte decimal numeric value that can be interpreted as a character.
You can use a CELLS array for ASCII character codes, but there would be unused space in each 8-bit cell.
Erasing this array's CHARS isn't necessary since you created the array with its values rather than converting
a variable into the array, but you can erase or modify the CHARS if you like just like you would in any other
CHARS array.
ARRAY - CHARS - CREATE - ASCII CHARACTER CODE - EXAMPLE
CREATE xxx 'a C, 'b C, 'c C, 'd C, Create the xxx array with the ticked a, b, c, and d ASCII character codes.
xxx 0 CHARS + C@ EMIT Fetch and display the a stored in the xxx array's first byte block address .
xxx 1 CHARS + C@ EMIT Fetch and display the b stored in the xxx array's second byte block address.
xxx 2 CHARS + C@ EMIT Fetch and display the c stored in the xxx array's third byte block address.
xxx 3 CHARS + C@ EMIT Fetch and display the d stored in the xxx array's fourth byte block address.
xxx 0 CHARS + C@ . Fetch and display the 97 stored in the xxx array's first byte block address.
xxx 1 CHARS + C@ . Fetch and display the 98 stored in the xxx array's second byte block address.
xxx 2 CHARS + C@ . Fetch and display the 99 stored in the xxx array's third byte block address.
xxx 3 CHARS + C@ . Fetch and display the 100 stored in the xxx array's fourth byte block address.
Array - Chars - Create - Numbers
ARRAY - CHARS - CREATE - NUMBERS
CREATE xxx n1 C, n2 C, n3 C, n4 C, Create a CHARS array with the CREATE word, the array name, and
one or more single-precision integers, with a c-comma (C,) word after
each value.
xxx i CHARS + C@ . Fetch and display the value of the array's specified byte block address
with the array name, the index, the CHARS word, the plus (+) word,
the c-fetch (c@) word, and the dot (.) word.
xxx Place the base array address on the stack by using the array name.
Erasing this array's CHARS isn't necessary since you created the array with its values rather than converting
a variable into the array, but you can erase or modify the CHARS if you like just like you would in any other
CHARS array.
ARRAY - CHARS - CREATE - NUMBERS - EXAMPLE
CREATE xxx 1 C, 2 C, 3 C, 4 C, Create the xxx array with the 1, 2, 3, and 4 single-precision integers.
xxx 0 CHARS + C@ . Fetch and display the 1 stored in the xxx array's first byte block address .
xxx 1 CHARS + C@ . Fetch and display the 2 stored in the xxx array's second byte block address.
xxx 2 CHARS + C@ . Fetch and display the 3 stored in the xxx array's third byte block address.
xxx 3 CHARS + C@ . Fetch and display the 4 stored in the xxx array's fourth byte block address.
Array - Chars - Numbers (0 - 255)
ARRAY - CHARS - NUMBERS (0 - 255)
VARIABLE xxx Create a variable with the VARIABLE word and a name.
xxx n CHARS ALLOT Turn the variable into a CHARS array by allotting n more byte blocks to put things
into with the variable name, the number, the CHARS word, and the ALLOT word,
for a total of n + 1 8-bit byte blocks.
xxx n CHARS ERASE Erase the total number of byte blocks of data stored at the array's address in memory
with the array name, the number, the CHARS word, and the ERASE word, to make
sure there are no leftovers from when it was a variable. Note: This erases the array's
contents, but leaves the array address on the stack.
xxx n CHARS DUMP Display the array's total number of byte blocks with the array name, the number, the
CHARS word, and the DUMP word, to make sure that erasure really happened.
n xxx i CHARS + C! Store a number in the array's specified byte block address by using the number, the
array name, the index, the CHARS word, the plus (+) word, and the c-store (C!)
word.
n xxx i + C! NOT RECOMMENDED. Or store a number in the array's specified byte block
address by using the number, the array name, the index, the plus (+) word, and the c-
store (C!) word.
xxx i CHARS + C@ . Fetch and display the number from the array's specified byte block address with the
array name, the index, the CHARS word, the plus (+) word, the c-fetch (C@) word,
and the dot (.) word.
xxx i + C@ . NOT RECOMMENDED. Or fetch and display the number from the array's specified
byte block address with the array name, the index, the plus (+) word, the c-fetch
(C@) word, and the dot (.) word.
xxx Place the base array address on the stack by using the array name.
ARRAY - CHARS - NUMBERS (0 - 255) - EXAMPLE 1
VARIABLE xxx Create the xxx variable.
xxx 3 CHARS ALLOT Turn the xxx variable into a 4-block CHARS array.
xxx 4 CHARS ERASE Erase the data in the xxx array's 4 byte blocks.
xxx 4 CHARS DUMP Display the xxx array's 4 byte blocks to make sure that erasure happened.
1 xxx 0 CHARS + C! Store a 1 in the xxx array's first byte block address.
xxx 0 CHARS + C@ . Fetch and display the 1 stored in the xxx array's first byte block address.
ARRAY - CHARS - NUMBERS (0 - 255) - EXAMPLE 2
VARIABLE xxx Create the xxx variable.
xxx 3 CHARS ALLOT Turn the xxx variable into a 4-block CHARS array.
xxx 4 CHARS ERASE Erase the data in the xxx array's 4 byte blocks.
xxx 4 CHARS DUMP Display the xxx array's 4 byte blocks to make sure that erasure happened.
1 xxx 0 CHARS + C! Store a 1 in the xxx array's first byte block address.
2 xxx 1 CHARS + C! Store a 2 in the xxx array's second byte block address.
3 xxx 2 CHARS + C! Store a 3 in the xxx array's third byte block address.
4 xxx 3 CHARS + C! Store a 4 in the xxx array's fourth byte block address.
xxx 0 CHARS + C@ . Fetch and display the 1 stored in the xxx array's first byte block address.
xxx 1 CHARS + C@ . Fetch and display the 2 stored in the xxx array's second byte block address.
xxx 2 CHARS + C@ . Fetch and display the 3 stored in the xxx array's third byte block address.
xxx 3 CHARS + C@ . Fetch and display the 4 stored in the xxx array's fourth byte block address.
Array - Chars - Removing Chars From An Array
ARRAY - CHARS - REMOVING CHARS FROM AN ARRAY
VARIABLE xxx Create a variable with the VARIABLE word and a name.
xxx n CHARS ALLOT Turn the variable into a CHARS array by allotting n more byte blocks to put things
into with the variable name, the number, the CHARS word, and the ALLOT word,
for a total of n + 1 8-bit byte blocks.
xxx n CHARS ERASE Erase the total number of byte blocks of data stored at the array's address in memory
with the array name, the number, the CHARS word, and the ERASE word to make
sure there are no leftovers from when it was a variable. Note: This erases the array's
contents, but leaves the array address on the stack.
xxx n CHARS DUMP Display the array's total number of byte blocks with the array name, the number, the
CHARS word, and the DUMP word, to make sure that erasure really happened.
n xxx i CHARS + C! Store a number (from 0 to 255) in the array's specified byte block address by using
the number, the array name, the index, the CHARS word, the plus (+) word, and the
c-store (C!) word.
n xxx i + C! NOT RECOMMENDED. Or store a number (from 0 to 255) in the array's specified
byte block address by using the number, the array name, the index, the plus (+)
word, and the c-store (C!) word.
xxx i CHARS + C@ . Fetch and display the number from the array's specified byte block address with the
array name, the index, the CHARS word, the plus (+) word, the c-fetch (C@) word,
and the dot (.) word.
xxx i + C@ . NOT RECOMMENDED. Or fetch and display the number from the array's
specified byte block address with the array name, the index, the plus (+) word, the c-
fetch (C@) word, and the dot (.) word.
xxx Place the base array address on the stack by using the array name.
xxx -n CHARS ALLOT Remove a number of CHARS from the array with the array name, the negative
number, the CHARS word, and the ALLOT word.
Note that Gforth will not immediately behave as though you have removed the CHARS . The data still exists,
and Gforth will access it if you ask it to. It's your responsibility to be aware that you have done so, because any
new data you create can be overwritten accidentally if you ask Gforth to access the removed CHARS in certain
ways (like erasing them or changing their values, etc.).
ARRAY - CHARS - REMOVING CHARS FROM AN ARRAY - EXAMPLE
VARIABLE xxx Create the xxx variable.
xxx 3 CHARS ALLOT Turn the xxx variable into a 4-block CHARS array.
xxx 4 CHARS ERASE Erase the data in the xxx array's 4 byte blocks.
xxx 4 CHARS DUMP Display the xxx array's 4 byte blocks to make sure that erasure happened.
1 xxx 0 CHARS + C! Store a 1 in the xxx array's first byte block address.
2 xxx 1 CHARS + C! Store a 2 in the xxx array's second byte block address.
3 xxx 2 CHARS + C! Store a 3 in the xxx array's third byte block address.
4 xxx 3 CHARS + C! Store a 4 in the xxx array's fourth byte block address.
xxx 0 CHARS + C@ . Fetch and display the 1 stored in the xxx array's first byte block address.
xxx 1 CHARS + C@ . Fetch and display the 2 stored in the xxx array's second byte block address.
xxx 2 CHARS + C@ . Fetch and display the 3 stored in the xxx array's third byte block address.
xxx 3 CHARS + C@ . Fetch and display the 4 stored in the xxx array's fourth byte block address.
xxx -2 CHARS ALLOT Remove 2 CHARS from the xxx array.
Array - Chars - String Constant Character
ARRAY - BYTE - STRING CONSTANT CHARACTER
VARIABLE xxx Create a variable with the VARIABLE word and a name.
xxx n CHARS ALLOT Turn the variable into a CHARS array by allotting n more memory blocks to
put things into with the variable name, the number, the CHARS word, and
the ALLOT word, for a total of n + 1 8-bit byte blocks.
xxx n CHARS ERASE Erase the total number of byte blocks of data stored at the array's address in
memory with the array name, the number, the CHARS word, and the
ERASE word, to make sure there are no leftovers from when it was a
variable. Note: This erases the array's contents, but the array address is still
on the stack.
xxx n CHARS DUMP Display the array's total number of byte blocks with the array name, the
number, the CHARS word, and the DUMP word, to make sure that erasure
really happened.
S" a" xxx i CHARS + PLACE Store a string constant character in the array's specified 2 byte block
addresses with the s-quote (S") word, a character (represented by a here),
the array name, the index, the CHARS word, the plus (+) word, and the
PLACE word.
S" a" xxx i + PLACE NOT RECOMMENDED. Or store a string constant character in the array's
specified 2 byte block addresses with the s-quote (S") word, a character
(represented by a here), the array name, the index, the plus (+) word, and the
PLACE word.
xxx i CHARS + COUNT TYPE Fetch and display the character code stored in the array's second 2 byte block
addresses with the array name, the index, the CHARS word, the plus (+)
word, the COUNT word, and the TYPE word.
xxx i + COUNT TYPE NOT RECOMMENDED. Or fetch and display the character code stored in
the specified array's second 2 byte block addresses with the array name, the
index, the plus (+) word, the COUNT word, and the TYPE word.
xxx Place the base array address on the stack by using the array name.
Strings of character codes need and use 2 byte block addresses.
ARRAY - CHARS - STRING CONSTANT CHARACTER - EXAMPLE 1
VARIABLE xxx Create the xxx variable.
xxx 3 CHARS ALLOT Turn the xxx variable into a 4-block CHARS array.
xxx 4 CHARS ERASE Erase the data in the xxx array's 4 byte blocks.
xxx 4 CHARS DUMP Display the xxx array's 4 byte blocks to make sure that erasure happened.
S" a" xxx 0 CHARS + PLACE Store the a string constant in the xxx array's first 2 byte block addresses.
xxx 0 + COUNT TYPE Fetch and type the a stored in the xxx array's first 2 byte block addresses.
ARRAY - CHARS - STRING CONSTANT CHARACTER - EXAMPLE 2
VARIABLE xxx Create the xxx variable.
xxx 7 CHARS ALLOT Turn the xxx variable into an 8-block CHARS array.
xxx 8 CHARS ERASE Erase the data in the xxx array's 8 byte blocks.
xxx 8 CHARS DUMP Display the xxx array's 8 byte blocks to make sure that erasure happened.
S" a" xxx 0 CHARS + PLACE Store the a string constant in the xxx array's first 2 byte block addresses.
S" b" xxx 2 CHARS + PLACE Store the b string constant in the xxx array's second 2 byte block addresses.
S" c" xxx 4 CHARS + PLACE Store the c string constant in the xxx array's third 2 byte block addresses.
S" d" xxx 6 CHARS + PLACE Store the d string constant in the xxx array's fourth 2 byte block addresses.
xxx 0 CHARS + COUNT TYPE Fetch and type the a stored in the xxx array's first 2 byte block addresses.
xxx 2 CHARS + COUNT TYPE Fetch and type the b stored in the xxx array's second 2 byte block addresses.
xxx 4 CHARS + COUNT TYPE Fetch and type the c stored in the xxx array's third 2 byte block addresses.
xxx 6 CHARS + COUNT TYPE Fetch and type the d stored in the xxx array's fourth 2 byte block addresses.
Array - Chars - Unicode Character
ARRAY - CHARS - UNICODE CHARACTER
VARIABLE xxx Create a variable with the VARIABLE word and a name.
xxx n CHARS ALLOT Turn the variable into a CHARS array by allotting the specified number of
more memory blocks to put things into with the variable name, the number,
the CHARS word, and the ALLOT word for a total of n + 1 8-bit byte
blocks.
xxx n CHARS ERASE Erase the total number of byte blocks of data stored at the array's address in
memory with the array name, the number, the CHARS word, and the ERASE
word, to make sure there are no leftovers from when it was a variable. Note:
This erases the array's contents, but the array address is still on the stack.
xxx n CHARS DUMP Display the array's total number of byte blocks with the array name, the
number, the CHARS word, and the DUMP word, to make sure that erasure
really happened.
'u xxx i CHARS + W! Store a Unicode character in the array's specified 2 byte block addresses by
using the tick (') word with a Unicode character, the array name, the index,
the CHARS word, the plus (+) word, and the w-store (w!) word.
'uc xxx i + W! NOT RECOMMENDED. Store a Unicode character in the array's specified
2 byte block addresses by using the tick (') word with the Unicode character,
the array name, the index, the plus (+) word, and the w-store (w!) word.
xxx i CHARS + UW@ Fetch the Unicode character stored in the array's specified 2 byte block
addresses with the array name, the index, the CHARS word, the plus (+)
word, and the u-w-fetch (UW@) word.
xxx i + UW@ NOT RECOMMENDED. Fetch the Unicode character stored in the array's
specified 2 byte block addresses with the array name, the index, the plus (+)
word, and the u-w-fetch (UW@) word.
xxx i CHARS + UW@ XEMIT Fetch and display the Unicode character stored in the array's specified 2 byte
block addresses with the array name, the index, the CHARS word, the plus
(+) word, the u-w-fetch (UW@) word, and the XEMIT word.
xxx i + UW@ XEMIT NOT RECOMMENDED. Fetch and display the Unicode character stored in
the array's specified 2 byte block addresses with the array name, the index,
the plus (+) word, the u-w-fetch (UW@) word, and the XEMIT word.
xxx i CHARS + UW@ . Fetch and display the Unicode character decimal numeric code stored in the
array's specified 2 byte block addresses with the array name, the index, the
CHARS word, the plus (+) word, the u-w-fetch (UW@) word, and the dot
(.) word.
xxx i + UW@ . NOT RECOMMENDED. Fetch and display the Unicode character decimal
numeric code stored in the array's specified 2 byte block addresses with the
array name, the index, the plus (+) word, the u-w-fetch (UW@) word, and
the dot (.) word.
xxx Place the base array address on the stack by using the array name.
ARRAY - CHARS - UNICODE CHARACTER - EXAMPLE 1
VARIABLE xxx Create the xxx variable.
xxx 7 CHARS ALLOT Turn the xxx variable into an 8-block CHARS array.
xxx 8 CHARS ERASE Erase the data in the xxx array's 8 byte blocks.
xxx 8 CHARS DUMP Display the xxx array's 8 byte blocks to make sure that erasure happened.
'☺ xxx 0 CHARS + W! Store the '☺ in the xxx array's first 2 byte block addresses.
xxx 0 CHARS + UW@ XEMIT Fetch and display the ☺ stored in the xxx array's first 2 byte block
addresses.
xxx 0 CHARS + UW@ . Fetch and display the 9786 stored in the xxx array's first 2 byte block
addresses.
ARRAY - CHARS - UNICODE CHARACTER - EXAMPLE 2
VARIABLE xxx Create the xxx variable.
xxx 7 CHARS ALLOT Turn the xxx variable into an 8-block CHARS array.
xxx 8 CHARS ERASE Erase the data in the xxx array's 8 byte blocks.
xxx 8 CHARS DUMP Display the xxx array's 8 byte blocks to make sure that erasure happened.
'☺ xxx 0 CHARS + W! Store the '☺ in the xxx array's first 2 byte block addresses.
'☻ xxx 2 CHARS + W! Store the '☻ in the xxx array's second 2 byte block addresses.
'☼ xxx 4 CHARS + W! Store the '☼ in the xxx array's third 2 byte block addresses.
'☽ xxx 6 CHARS + W! Store the '☽ in the xxx array's fourth 2 byte block addresses.
xxx 0 CHARS + UW@ XEMIT Fetch and display the ☺ stored in the xxx array's first 2 byte block addresses.
xxx 2 CHARS + UW@ XEMIT Fetch and display the ☻ stored in the xxx array's second 2 byte block addresses.
xxx 4 CHARS + UW@ XEMIT Fetch and display the ☼ stored in the xxx array's third 2 byte block addresses.
xxx 6 CHARS + UW@ XEMIT Fetch and display the ☽ stored in the xxx array's fourth 2 byte block addresses.
xxx 0 CHARS + UW@ . Fetch and display the 9786 stored in the xxx array's first 2 byte block addresses.
xxx 2 CHARS + UW@ . Fetch and display the 9787 stored in the xxx array's second 2 byte block addresses.
xxx 4 CHARS + UW@ . Fetch and display the 9788 stored in the xxx array's third 2 byte block addresses.
xxx 6 CHARS + UW@ . Fetch and display the 9789 stored in the xxx array's fourth 2 byte block addresses.
Array - Chars - Unicode Character Code
ARRAY - CHARS - UNICODE CHARACTER CODE
CREATE xxx Create a named address with the CREATE word and a name.
xxx n 2* CHARS ALLOT Turn the named address into a CHARS array by allotting the specified
number of 2-byte blocks to put things into with the name, the number, 2*,
the CHARS word, and the ALLOT word, for a total of n 8-bit 2-byte
blocks.
xxx n 2* CHARS ERASE Erase the total number of 2-byte blocks of the possible random data stored at
the array's address in memory with the array name, the number, 2*, the
CHARS word, and the ERASE word. Note: This erases the array's
contents, but the array address is still on the stack.
xxx n 2* CHARS DUMP Display the array's total number of 2-byte blocks with the array name, the
number, 2*, the CHARS word, and the DUMP word, to make sure that
erasure really happened.
u xxx i CHARS + W! Store a Unicode hexadecimal numeric code in the array's specified 2-byte block
addresses with the Unicode character, the array name, the index, the CHARS
word, the plus (+) word, and the w-store (W!) word.
xxx i CHARS + UW@ Fetch the Unicode character stored in the array's specified 2-byte block
addresses with the array name, the index, the CHARS word, the plus (+)
word, and the u-w-fetch (UW@) word.
xxx i CHARS + UW@ XEMIT Fetch and display the Unicode character stored in the array's specified 2-byte
block addresses with the array name, the index, the CHARS word, the plus
(+) word, the u-w-fetch (UW@) word, and the XEMIT word.
xxx i CHARS + UW@ . Fetch and display the Unicode character decimal numeric code stored in the
array's specified 2-byte block addresses with the array name, the index, the
CHARS word, the plus (+) word, the u-w-fetch (UW@) word, and the dot
(.) word.
xxx Place the base array address on the stack by using the array name.
We use W! To store the 16-bit/2-byte Unicode character code into a CHARS array, and UW@ to fetch the
unsigned 16-bit/2-byte Unicode character code from a CHARS array, indexing into the array 2 CHARS for
each character: array 0 CHARS + array 2 CHARS + array 4 CHARS + etc.
ARRAY - CHARS - UNICODE CHARACTER CODE - EXAMPLE 1
CREATE xxx Create the xxx named address.
xxx 4 2* CHARS ALLOT Turn the xxx named address into a 4 2-byte block CHARS array.
xxx 4 2* CHARS ERASE Erase the data in the xxx array's 4 2-byte block addresses.
xxx 4 2* CHARS DUMP Display the xxx array's 4 2-byte block addresses to make sure it's empty.
0x263a xxx 0 CHARS + W! Store the 0x263a hexadecimal numeric Unicode in the xxx array's first 2 2-byte block addresses.
xxx 0 CHARS + UW@ Fetch the ☺ from the xxx array's first 2 2-byte block addresses.
xxx 0 CHARS + UW@ XEMIT Display the ☺stored in the xxx array's first 2 2-byte block addresses.
xxx 0 CHARS + UW@ . Display the 9786 decimal numeric Unicode stored in the xxx array's first 2 2-byte block addresses.
ARRAY - CHARS - UNICODE CHARACTER CODE - EXAMPLE 2
CREATE xxx Create the xxx named address.
xxx 4 2* CHARS ALLOT Turn the xxx named address into a 4 2-byte block CHARS array.
xxx 4 2* CHARS ERASE Erase the data in the xxx array's 4 2-byte blocks.
xxx 4 2* CHARS DUMP Display the xxx array's 4 2-byte blocks to make sure that erasure happened.
0x263a xxx 0 CHARS + W! Store the 0x263a hexadecimal numeric Unicode in the xxx array's first 2 2-byte block addresses.
0x263b xxx 2 CHARS + W! Store the 0x263b hexadecimal numeric Unicode in the xxx array's second 2 2-byte block addresses.
0x263c xxx 4 CHARS + W! Store the 0x263c hexadecimal numeric Unicode in the xxx array's third 2 2-byte block addresses.
0x263d xxx 6 CHARS + W! Store the 0x263d hexadecimal numeric Unicode in the xxx array's fourth 2 2-byte block addresses.
xxx 0 CHARS + UW@ Fetch the ☺ from the xxx array's first 2 2-byte block addresses.
xxx 2 CHARS + UW@ Fetch the ☻ from the xxx array's second 2 2-byte block addresses.
xxx 4 CHARS + UW@ Fetch the ☼ from the xxx array's third 2 2-byte block addresses.
xxx 6 CHARS + UW@ Fetch the ☽ from the xxx array's fourth 2 2-byte block addresses.
xxx 0 CHARS + UW@ XEMIT Fetch and display the ☺ from the xxx array's first 2 2-byte block addresses.
xxx 2 CHARS + UW@ XEMIT Fetch and display the ☻ from the xxx array's second 2 2-byte block addresses.
xxx 4 CHARS + UW@ XEMIT Fetch and display the ☼ from the xxx array's third 2 2-byte block addresses.
xxx 6 CHARS + UW@ XEMIT Fetch and display the ☽ from the xxx array's fourth 2 2-byte block addresses.
xxx 0 CHARS + UW@ . Fetch and display the 9786 from the xxx array's first 2 2-byte block addresses.
xxx 2 CHARS + UW@ . Fetch and display the 9787 from the xxx array's second 2 2-byte block addresses.
xxx 4 CHARS + UW@ . Fetch and display the 9788 from the xxx array's third 2 2-byte block addresses.
xxx 6 CHARS + UW@ . Fetch and display the 9789 from the xxx array's fourth 2 2-byte block addresses.
ARRAY - CHARS - UNICODE CHARACTER - AUDACIOUS KLUDGE
This is an audacious kludge which uses a byte array to save only the low bytes, which are then reconstituted by
adding the high byte before displaying the result.
HEX Put Forth into base 16 (hexadecimal) mode with the HEX word.
VARIABLE xxx Create a variable with the VARIABLE word and a name.
xxx n CHARS ALLOT Turn the variable into a CHARS array by allotting n more memory
blocks to put things into with the variable name, the number, the
CHARS word, and the ALLOT word, for a total of n + 1 8-bit byte
blocks.
xxx n CHARS ERASE Erase the total number of byte blocks of data stored at the array's
address in memory with the array name, the number, the CHARS
word, and the ERASE word, to make sure there are no leftovers from
when it was a variable. Note: This erases the array's contents, but
leaves the array address on the stack.
xxx n CHARS DUMP Display the array's total number of byte blocks with the array name,
the number, the CHARS word, and the DUMP word, to make sure
that erasure really happened.
lowbytes xxx i CHARS + C! Store the low bytes of a Unicode character's hexadecimal numeric
code in the array's specified byte block address by using the low
bytes, the array name, the index, the CHARS word, the plus (+)
word, and the c-store (C!) word.
xxx i CHARS + C@ highbyte + XEMIT Fetch the low bytes from the array's specified byte block address with
the array name, the index, the CHARS word, the plus (+) word, and
the c-fetch (C@) word; then assemble it with the high byte and the
plus (+) word; then display it with the XEMIT word.
xxx Place the base array address on the stack by using the array name.
DECIMAL Put Forth back into base 10 (decimal) mode with the DECIMAL
word.
ARRAY - CHARS - UNICODE CHARACTER - AUDACIOUS KLUDGE - EXAMPLE
This is an audacious kludge which uses a CHARS array to save only the low bytes which are then reconstituted
by adding the high byte before displaying the result.
HEX Put Forth into base 16 (hexadecimal) mode.
VARIABLE xxx Create the xxx variable.
xxx 3 CHARS ALLOT Turn the xxx variable into a 4-block CHARS array.
xxx 4 CHARS ERASE Erase the data in the xxx array's 4 byte blocks.
xxx 4 CHARS DUMP Display the xxx array's 4 byte blocks to make sure that erasure happened.
3a xxx 0 CHARS + C! Store the 3a low bytes in the xxx array's first byte block address.
3b xxx 1 CHARS + C! Store the 3b low bytes in the xxx array's second byte block address.
3c xxx 2 CHARS + C! Store the 3c low bytes in the xxx array's third byte block address.
39 xxx 3 CHARS + C! Store the 39 low bytes in the xxx array's fourth byte block address.
xxx 0 CHARS + C@ 2600 + XEMIT Fetch the ☺ from the xxx array's first byte block address, and assemble and display the ☺.
xxx 1 CHARS + C@ 2600 + XEMIT Fetch the 3b from the xxx array's second byte block address, and assemble and display the ☻.
xxx 2 CHARS + C@ 2600 + XEMIT Fetch the 3c from the xxx array's third byte block address, and assemble and display the ☼.
xxx 3 CHARS + C@ 2600 + XEMIT Fetch the 39 from the xxx array's fourth byte block address, and assemble and display the ☹.
DECIMAL Put Forth back into base 10 (decimal) mode.
Array - Multiple Mixed Array Types
ARRAY - MULTIPLE MIXED ARRAY TYPES - EXAMPLE 1
I like to call this the Charells array because it's a mixture of a CELLS and a CHARS array all in one. It
probably shouldn't work, but it does.
VARIABLE xxx Create the xxx variable.
2 CELLS ALLOT Add 2 CELLS addresses to the xxx variable, turning it into a CELLS
array.
2 CHARS ALLOT Add 2 CHARS (byte block) addresses to the xxx variable, turning it into
a mixed CELLS and CHARS array.
'a xxx 0 CELLS + C! Store the ticked a in the xxx array's first (CELLS) address.
155 xxx 1 CELLS + C! Store 155 in the xxx arrays second (CELLS) address.
'b xxx 2 CHARS + C! Store the ticked b in the xxx array's third (byte block) address.
255 xxx 3 CHARS + C! Store 255 in the xxx array's fourth (byte block) address.
xxx 0 CELLS + C@ EMIT Fetch the a from the xxx array's first (CELLS) address and display it.
xxx 1 CELLS + C@ . Fetch the 155 from the xxx array's first (CELLS) address and display it.
xxx 2 CHARS + C@ EMIT Fetch the b from the xxx array's first (CELLS) address and display it.
xxx 3 CHARS + C@ . Fetch the 255 from the xxx array's first (CELLS) address and display it.
Array Types
ARRAY TYPES - EXPLANATION
UNITS ALLOTS USE
CHARS 1-byte array Unsigned numbers from 0 - 255 and ASCII character codes.
CHARS 2-byte array Unicode character codes.
CELLS 8-byte array Single-precision integers and Unicode character codes.
CELLS 16-byte array Double-precision integers, floating-point numbers, and strings.
• A CHARS array can hold 1-byte numbers, ASCII character codes, and Unicode character codes, and
requires 2 CHARS to hold each Unicode character code.
• A CELLS array can hold floats, integers, strings, and Unicode character codes, and requires 2
CELLS to hold each double-precision integer or string.
Common Errors
COMMON ERRORS
Omitting necessary white space, resulting in an error like Undefined word.
Leaving too many items on the stack.
Not having enough items on the stack.
Not paying attention to the order of the items on the stack.
Not paying attention to the type of items on the stack.
Conditional - Boolean
CONDITIONAL - BOOLEAN (COMPARISON OPERATORS)
AND And.
OR Or.
XOR XOR, which stands for eXclusive OR, performs a bitwise operation where two numbers are
compared, and the resultant number has its bits set only where the two numbers differ.
INVERT Not.
CONDITIONAL - BOOLEAN (COMPARISON OPERATORS) - EXAMPLE
3 4 < 20 30 < AND . Returns -1 (which means true).
3 4 < 20 30 < OR . Returns -1 (which means true).
3 4 < 20 30 < XOR . Returns 0 (which means false).
2 BASE ! 1011 1010 XOR . Returns 1 because the only bit position that satisfies the XOR is the 1 bit - the
right-most binary digit.
3 4 < INVERT . Returns 0 (which means false).
Conditional - Case Statement
CONDITIONAL - CASE STATEMENT
CASE Begin a case statement.
OF Begin test for case.
ENDOF End test for case.
ENDCASE End the case statement.
Note: Case statements must be inside of word definitions.
CONDITIONAL - CASE STATEMENT - EXAMPLE
: pressakey Open a word definition and name it pressakey.
PAGE Clear the screen.
cr ." press any key " Insert a carriage return and display a message.
CR CR Insert two carriage returns.
KEY Read which key was pressed.
CASE Open a case statement.
100 OF ." you pressed the d key" ENDOF Display this message if the d key was pressed.
." you pressed some other key" Otherwise display this message.
ENDCASE Close the case statement.
; Close the word definition.
pressakey Execute the pressakey word.
CR CR Insert two carriage returns.
Note: Pasting all of this code into a terminal window running Gforth will result in an error. If you paste
everything to (and including) the close of the word definition into the terminal window and then type pressakey
to execute the word, it will work fine.
Conditional - Flags
CONDITIONAL - FLAGS
TRUE FALSE Place a true (-1) or false (0) flag on top of the stack (TOS). ( - - flag )
CONDITIONAL - FLAGS - EXAMPLE
TRUE Puts true on the TOS.
. Displays the -1 from the TOS and destroys it.
FALSE Puts false on the TOS.
. Displays the 0 from the TOS and destroys it.
CONDITIONAL - FLAGS (COMPARISON OPERATORS)
nn= Test whether the first number is equal to the second number. ( n n - - flag )
n n <> Test whether the first number is not equal to the second number. ( n n - - flag )
nn< Test whether the first number is less than the second number. ( n n - - flag )
nn> Test whether the first number is greater than the second number. ( n n - - flag )
n n <= Test whether the first number is less than or equal to the second number. ( n n - - flag )
n n >= Test whether the first number is greater than or equal to the second number.. ( n n - - flag )
n n 0= Test whether the first and/or second number is equal to zero. ( n n - - flag )
A flag is a -1 (true) or 0 (false) result left on the stack by any comparison operator, like =, <, >, etc.
CONDITIONAL - FLAGS (COMPARISON OPERATORS) - EXAMPLE
22=. Tests whether 2 and 2 are equal and displays the flag result. Returns -1.
1 0 <= . Tests whether 1 is less than or equal to 0 and displays the flag result. Returns 0.
32>. Tests whether 3 is greater than 2 and displays the flag result. Returns -1.
32<. Tests whether 3 is less than 2 and displays the flag result. Returns 0.
4 5 <> . Tests whether 4 is not equal to 5 and displays the flag result. Returns -1.
Conditional - If Statement
CONDITIONAL - IF STATEMENT
: example Begin a word definition with the colon (:) word and a name for the word.
test Begin a test (represented by test in this example) for a condition, generating a result.
IF Begin IF statement with the IF word to read the test result.
code1 If the test is true, execute the specified code (represented by code1 in this example) that follows IF.
ELSE Begin an alternative result with the ELSE word.
code2 Otherwise, execute the specified code (represented by code2 in this example) that follows ELSE.
THEN End the IF statement with the THEN word (default).
ENDIF End the IF statement with the ENDIF word (optional for those used to other languages).
IF statements can only be used within a colon definition.
CONDITIONAL - IF STATEMENT - EXAMPLE 1
: example Begin the example word definition.
12= Test whether 1 is equal to 2, generating a true or false flag.
IF Begin IF statement to read the test result.
." Yes, it is!" Display this string of character codes if the test is true.
ELSE Begin ELSE statement.
." No, it's not!" Display this string of character codes if the test is false.
THEN End the IF statement.
; End the example word definition and store the word.
example Execute the example word.
A test like a b = generates a true/false flag which IF uses to determine whether or not to execute the contents of
the IF-THEN or IF-ENDIF conditional. For example:
• 1 2 = generates a FALSE or 0 flag
• 1 1 = generates a TRUE or -1 flag .
CONDITIONAL - IF STATEMENT - EXAMPLE 2
: example 0> IF ." Positive Number" ELSE ." A basic colon definition named "example" that uses an IF
Negative Number" THEN ; statement to test if a number is positive or negative with 0>,
and displays the brief message "Positive Number" if true ELSE
"Negative Number" if false THEN.
123 example 123 is tested and displays 123 example Positive Number ok as
the result.
-123 example -123 is tested and displays 123 example Negative Number ok
as the result.
Constants
CONSTANTS - EXPLANATION
Constants are used for values that won’t change. The value of a constant is set during creation.
Constants - ASCII
CONSTANTS - ASCII
code CONSTANT xxx Create a constant with a ticked ASCII character code, the CONSTANT word, and a
name..
xxx XEMIT Fetch and display the character value of the CONSTANT with its name and the
XEMIT word.
xxx . Fetch and display the character code value of the CONSTANT with its name and the
dot (.) word.
CONSTANTS - ASCII - EXAMPLE
'a CONSTANT xxx Create a constant with a ticked ASCII character code, the CONSTANT word, and a
name..
xxx XEMIT Fetch and display the a character value of the CONSTANT.
xxx . Fetch and display the 97 character code value of the CONSTANT.
Constants - Numbers
CONSTANTS - NUMBERS
n CONSTANT xxx Create a constant with a number, the CONSTANT word, and a name..
xxx . Fetch and display the value of the CONSTANT with its name and the dot (.) word.
CONSTANTS - NUMBERS - EXAMPLE
6 CONSTANT xxx Create the xxx CONSTANT with the numerical value of 6.
xxx . Fetch the value of the xxx CONSTANT and display it.
Constants - Numbers - 2constant
CONSTANTS - NUMBERS - 2CONSTANT
dpsi 2CONSTANT Create a 2CONSTANT with double-precision signed integer, the 2CONSTANT word,
xxx and a name.
dpui 2CONSTANT Create a 2CONSTANT with a double-precision unsigned integer, the 2CONSTANT
xxx word, and a name.
xxx D. Fetch and display the value of the 2CONSTANT with its name and the d-dot D. word and
display it..
CONSTANTS - NUMBERS - 2CONSTANT - EXAMPLE
65535 S>D 2CONSTANT xxx Store 65535 in the xxx 2CONSTANT.
xxx D. Fetch the contents of the xxx 2CONSTANT and display them.
Constants - Numbers - Fconstant
CONSTANTS - NUMBERS - FCONSTANT
fpn FCONSTANT Create an FCONSTANT with a Scientific Notation value, the FCONSTANT word, and a
xxx name.
xxx F. Fetch and display the value of the FCONSTANT with its name and the f-dot (F.) word
CONSTANTS - NUMBERS - FCONSTANT - EXAMPLE
1e2 FCONSTANT xxx Create the xxx FCONSTANT with the 1e2 value.
xxx F. Fetch and display the 100. stored in the xxx FCONSTANT.
Constants - Strings
CONSTANTS - STRINGS
S" example" Create a string constant with the specified value.
S" example" TYPE Type the value of the specified string constant with its COUNT at TOS.
A string created with the s-quote (S") word is a constant since it puts its value and length directly on the stack.
CONSTANTS - STRINGS - EXAMPLE
S" example" Create a string constant with the example value.
S" example" TYPE Type the value of the example string constant.
Constants - Strings - 2constant
CONSTANTS - STRINGS - 2CONSTANTS
S" example" 2CONSTANT xxx Create a 2CONSTANT with a string constant value, the 2CONSTANT word,
and a name.
xxx TYPE Fetch and display the value of the 2CONSTANT with its name and the TYPE
word.
CONSTANTS - STRINGS - 2CONSTANTS - EXAMPLE
S" example" 2CONSTANT xxx Create a 2CONSTANT with the example value.
xxx TYPE Fetch and display the example stored in the xxx 2CONSTANT.
Constants - Unicode
CONSTANTS - UNICODE - METHOD 1
u CONSTANT xxx Create a CONSTANT with decimal numeric code, the CONSTANT word, and a
name.
xxx XEMIT Fetch and display the Unicode character value of the CONSTANT with its name and
the XEMIT word.
xxx . Fetch and display the decimal numeric code value of the CONSTANT with its name
and the dot (.) word.
CONSTANTS - UNICODE - METHOD 1 - EXAMPLE
9786 CONSTANT xxx Create a CONSTANT with the 9786 decimal numeric code value.
xxx XEMIT Fetch and display the ☺ stored in the xxx CONSTANT.
xxx . Fetch and display the 9786 stored in the xxx CONSTANT.
CONSTANTS - UNICODE - METHOD 2
HEX Put Forth into base 16 (hexadecimal) mode with the HEX word.
u CONSTANT xxx Create a CONSTANT with hexadecimal numeric code, the CONSTANT word, and a
name.
xxx XEMIT Fetch and display the Unicode character value of the CONSTANT with its name and the
XEMIT word.
xxx . Fetch and display the hexadecimal numeric code value of the CONSTANT with its name
and the dot (.) word.
DECIMAL Put Forth back into base 10 (decimal) mode with the DECIMAL word.
CONSTANTS - UNICODE - METHOD 2 - EXAMPLE
HEX Put Forth into base 16 (hexadecimal) mode.
263a CONSTANT xxx Create a CONSTANT with the 263a hexadecimal numeric code value.
xxx XEMIT Fetch and display the ☺ stored in the xxx CONSTANT.
xxx . Fetch and display the 263a stored in the xxx CONSTANT.
DECIMAL Put Forth back into base 10 (decimal) mode.
Data Types - How To Store And Fetch And Display
DATA TYPES - HOW TO STORE AND FETCH AND DISPLAY
DATA TYPE EXAMPLE STORE FETCH DISPLAY ADDRES ARRAY
VALUE WORD WORD WORD S UNITS TYPE
ASCII character code 'a C! C@ EMIT 1 byte 1 CHARS
Boolean flag 12< ! @ . 8 bytes 1 CELLS
Byte integer (0 - 255 unsigned) 1 C! C@ . 1 byte 1 CHARS
Data stack element 1024 ! SP@ @ . 8 bytes 1 CELLS
Double precision signed integer -65535 s>d 2! @ 2@ D. 16 bytes 2 CELLS
Double precision unsigned integer 65535 s>d 2! @ 2@ D. 16 bytes 2 CELLS
Execution token ' PAGE ! @ . 8 bytes 1 CELLS
Floating point number 1e2 F! @ F@ F. 8 bytes 2 CELLS
Memory address HERE ! @ . 8 bytes 1 CELLS
Return stack element HERE ! >R RP@ @ . R> 8 bytes 1 or 2
CELLS
Single precision signed integer -256 ! @@ . 8 bytes 1 CELLS
Single precision unsigned integer 256 ! @@ . 8 bytes 1 CELLS
String constant S" example" 2! 2@ TYPE 16 bytes 2 CELLS
String constant S" example" PLACE COUNT TYPE 16 bytes 2 CELLS
Unicode character '☺ ! @ XEMIT 2 bytes 1 CELLS
Unicode character code 0x263A ! @ . 2 bytes 1 CELLS
Unicode character '☺ W! UW@ XEMIT 2 bytes 1 CHARS
Unicode character code 0x263A W! UW@ . 2 bytes 1 CHARS
Address arithmetic is based on address units (au), which are 1 byte each on most systems.
If the beginning of the entire fetch and display sequence starts with a 2, then and only then, give the item a 2
CELLS index.
DATA TYPES - HOW TO STORE AND FETCH AND DISPLAY FROM CREATE ARRAYS
DATA TYPE EXAMPLE STORE FETCH DISPLAY ADDRES ARRAY
VALUE WORD WORD WORD S UNITS TYPE
ASCII character code 'a , C@ EMIT 1 byte 1 CHARS
Boolean flag 12< , @ . 8 bytes 1 CELLS
Byte integer (0 - 255 unsigned) 1 , @ . 1 byte 1 CHARS
Data stack element 1024 , SP@ @ . 8 bytes 1 CELLS
Double precision signed integer -65535 s>d 2, @ 2@ D. 16 bytes 2 CELLS
Double precision unsigned integer 65535 s>d 2, @ 2@ D. 16 bytes 2 CELLS
Execution token ' PAGE , @ . 8 bytes 1 CELLS
Floating point number 1e2 , @ F. 8 bytes 2 CELLS
Memory address HERE , @ . 8 bytes 1 CELLS
Return stack element HERE , >R RP@ @ . R> 8 bytes 1 or 2
CELLS
Single precision signed integer -256 , @@ . 8 bytes 1 CELLS
Single precision unsigned integer 256 , @@ . 8 bytes 1 CELLS
String constant S" example" S, COUNT TYPE 16 bytes 2 CELLS
Unicode character '☺ , @ XEMIT 2 bytes 1 CELLS
Unicode character code 0x263A , @ . 2 bytes 1 CELLS
Unicode character '☺ , UW@ XEMIT 2 bytes 1 CHARS
Unicode character code 0x263A , UW@ . 2 bytes 1 CHARS
If the beginning of the entire fetch and display sequence starts with a 2, then and only then, give the item a 2
CELLS index.
File Management - Text Files
FILE MANAGEMENT - TEXT FILES
The file access data types:
• fam file access method
• ior i/o result
• fileid file id
The file access methods:
• bin binary ( fam -- fam )
• r/o read only ( -- fam )
• w/o write only ( -- fam )
• r/w read/write ( -- fam )
S" file1 .txt" R/W CREATE-FILE Create a text file in read/write ( addr u fam -- fileid ior )
mode, putting the fileid and
ior on the stack.
DROP DROP Remove the fileid and the ior
from the stack.
S" file1.txt" S" file2.txt" RENAME-FILE Rename the text file, putting ( addr1 u1 addr2 u2 -- ior )
the ior on the stack.
DROP Remove the ior from the
stack.
S" file2.txt" R/W OPEN-FILE Open the text file in ( addr u fam -- fileid ior )
read/write mode.
DROP Remove the ior from the
stack.
DUP ( duplicate fileid ) 0 0 ROT ( bring fileid Erase the file's contents, if ( u fileid -- ior )
copy to TOS ) RESIZE-FILE any.
DROP Remove the ior from the
stack.
DUP ( duplicate fileid ) S" This is just a test! Write some text to the file. ( addr u fileid -- ior )
\n" ROT ( bring fileid copy to TOS ) WRITE-
FILE
DROP Remove the ior from the
stack.
DUP ( duplicate fileid ) S" This is a new line of Add a new line of text to the ( addr u fileid -- ior )
text." ROT file.
( bring fileid copy to TOS ) WRITE-LINE
DROP Remove the ior from the
stack.
DUP ( duplicate fileid ) FLUSH-FILE Flush the file to complete the ( fileid -- ior )
write operation.
DROP Remove the ior from the
stack.
CLOSE-FILE Close the file. ( fileid -- ior )
DROP Remove the ior from the
stack.
S" file2.txt" SLURP-FILE TYPE Slurp the text file's contents ( addr1 u1 -- addr2 u2 )
without explicitly opening it
(read the contents of the file
into memory).
S" file2.txt" R/O OPEN-FILE Open the text file in read only ( addr u fam -- fileid ior )
mode.
DROP Remove the ior from the
stack.
DUP KEY-FILE CR EMIT DUP KEY-FILE CR Duplicate the fileid and get ( fileid -- char )
EMIT DUP KEY-FILE CR EMIT DUP KEY- characters from the text file
FILE CR EMIT one character at a time.
DUP ( duplicate fileid ) FILE-SIZE Get the file size. ( fileid -- ud ior )
DROP D>S Remove the ior from the stack
and convert the file size from
a double-precision integer to a
single-precision integer.
OVER ( bring fileid to TOS ) 0 0 ( zero double ) Reset the file pointer to the
ROT ( bring fileid copy to TOS ) beginning (since KEY-FILE
REPOSITION-FILE ( ud fileid -- ior ) had read 4 of its characters).
DROP Remove the ior from the
stack.
OVER ( bring fileid to TOS ) HERE 80 ROT Get characters from the text ( addr u1 fileid -- u2 flag ior )
( bring fileid copy to TOS ) READ-LINE file one line at a time.
HERE ROT ( bring count to TOS ) TYPE
DROP DROP Remove the ior and the flag ( ud fileid -- ior )
from the stack.
OVER ( bring fileid to TOS ) 0 0 ( zero double ) Reset the text file pointer to
ROT ( bring fileid copy to TOS ) the beginning (so that output
REPOSITION-FILE can begin from there) since
READ-LINE had read
through it one line at a time.
DROP DROP Remove the ior and the flag ( ud fileid -- ior )
from the stack.
OVER ( bring fileid to TOS ) n 0 ( zero double ) Or reset the text file pointer to
ROT ( bring fileid copy to TOS ) the specified (n) position (so
REPOSITION-FILE that output can begin from
there) since READ-LINE had
read through it one line at a
time.
DROP Remove the ior from the
stack.
HERE SWAP ( switch count and here ) ROT Read the text file contents ( addr u1 fileid -- u2 ior )
( bring fileid to TOS ) READ-FILE into memory.
DROP Remove the ior from the
stack.
HERE SWAP ( switch count and here ) TYPE Display what was read into ( addr u -- )
memory from the text file.
S" file2.txt" DELETE-FILE Delete the text file. ( addr u -- ior )
The two zeros above are double-length numbers. To generate any number for any position in any file, type the
number and execute the single to double converter (S>D) word.
Key Codes
KEY CODES
KEY The key word tests the next key press (or key combination press) and stores the numerical value of the
character it represents on the TOS.
The resulting key code can be used to control what happens when a certain key is pressed.
If you want to preserve what has been captured, move it into a variable, value, or safe address, before the next
execution overwrites it.
KEY CODES - EXAMPLE
KEY Waits for your input, then puts the key code from the key that was
pressed on the stack.
KEY . Waits for your input, puts the key code from the key that was pressed
on the stack, fetches (removes) the key code from the stack, and
displays it .
CR ." Press any key" KEY CR . Displays a carriage return followed by the Press any key message,
waits for your input,puts the key code from the key that was pressed on
the stack, fetches (removes) the key code from the stack, displays a
carriage return, then displays the key code.
CR ." Press any key" KEY DROP CR Displays a carriage return, displays the Press any key message, tests
for a key press, puts the key code from the key that was pressed on the
stack, drops the TOS value that was stored to represent which key was
pressed, and displays a carriage return.
Play interactively here: https://www.w3.org/2002/09/tests/keys.html
Length
LENGTH - FIGURING OUT HOW BIG SOMETHING IS IN FORTH
Word lengths can be determined by the difference between the current word (word2) and the previous word
(word1).
' word2 ' word1 - 8 / Size of word2 in cells
' word2 ' word1 - Size of word2 in bytes
The difference between a word and HERE is the measure of its code size or data allocation size.
HERE CELL - variable - 8 / Size in cells.
HERE CELL - ' value - 8 / Size in cells.
HERE CELL - ' constant - 8 / Size in cells.
HERE CREATE - 8 / Size in cells.
HERE CELL - variable - Size in bytes.
HERE CELL - ' value Size in bytes.
HERE CELL - ' constant Size in bytes.
HERE CREATE - Size in bytes.
LENGTH - FIGURING OUT HOW BIG SOMETHING IS IN FORTH - EXAMPLE 1
: word1 S" tiny " ; Define word1 with the tiny string constant.
: word2 S" humongous " ; Define word2 with the humongous string constant.
' word2 ' word1 - 8 / . Display the length of word2 in cells.
' word2 ' word1 - . Display the length of word2 in bytes.
LENGTH - FIGURING OUT HOW BIG SOMETHING IS IN FORTH - EXAMPLE 2
HERE . Display the address used by HERE.
HERE 1 CHARS + . Display the address used by HERE with 1 CHARS + for a total use of 1 byte.
HERE 1 CELLS + . Display the address used by HERE with 1 CELLS + for a total use of 8 bytes.
PAD . Display the address used by PAD.
PAD 1 CHARS + . Display the address used by PAD with 1 CHARS + for a total use of 1 byte.
PAD 1 CELLS + . Display the address used by PAD with 1 CELLSs + for a total use of 8 bytes, or 1 cell.
LENGTH - FIGURING OUT HOW BIG SOMETHING IS IN FORTH - EXAMPLE 2
If you create a create array and also immediately create a length constant with a similar name, you can later
find out how many bytes you had allocated to the array by subtracting the array from the length constant, or
you can later find out how many cells you had allocated to the array by subtracting the array from the length
constant and dividing the result by 8.
CREATE xxx ," one" ," two" ," three" Create the xxx array with the one, two, and three string character
code values.
HERE CONSTANT xxxlength Create the xxxlength CONSTANT with the address of HERE as its
value.
xxxlength xxx - . Subtract the array from its length CONSTANT and display the result
in bytes.
xxxlength xxx - 8 / . Subtract the array from its length CONSTANT and divide the result
by 8 and display the result in cells.
It's a little different with variable arrays due to the difference in the way the two are created. You have to
subtract 8 bytes, or 1 cell, from HERE to see the same 24 bytes, or 3 cells, as with the create array. Nothing
changes, however, if you're allocating space to the variable for a single-item storage instead of an array.
VARIABLE xxx Create the xxx variable.
3 CELLS ALLOT Turn the xxx variable into a CELLS array and allot 3 CELLS to it.
HERE 8 - CONSTANT xxxlength Subtract 8 from HERE and use the result as the value of the
xxxlength CONSTANT you're creating.
xxxlength xxx - . Subtract the array from its length CONSTANT and display the result
in bytes.
xxxlength xxx - 8 / . Subtract the array from its length CONSTANT and divide the result
by 8 and display the result in cells.
Loops - Begin Again
LOOPS - BEGIN AGAIN
: xxx BEGIN code AGAIN ; Create a word containing a BEGIN AGAIN loop by using the colon (:) word to
open a definition followed by a name for the word, the BEGIN word, the code to
run on each loop, the AGAIN word, and the semi-colon (;) word.
xxx Execute the word, causing an endless loop that executes the specified code until
a break is provided by pressing Ctrl + C or unti the terminal window is closed to
end or exit the loop.
LOOP S- BEGIN AGAIN - EXAMPLE
: endless BEGIN 0 . AGAIN ; 1. Define the endless word.
endless 2. When the endless word is executed:
1. The loop begins.
2. A zero is placed on the stack and TOS is
displayed.
3. The loop goes back to the beginning again.
: endless 0 BEGIN DUP . AGAIN ; 1. Define the endless word.
endless 2. When the endless word is executed:
1. A zero is placed on the stack.
2. The loop begins.
3. TOS is duplicated and displayed.
4. The loop goes back to the beginning again.
: endless 0 BEGIN DUP . 1+ AGAIN ; 1. Define the endless word.
endless 2. When the endless word is executed:
1. A zero is placed on the stack.
2. The loop begins.
3. TOS is duplicated and displayed and 1 is
added to it.
4. The loop goes back to the beginning again.
: endless BEGIN S" hello" TYPE AGAIN ; 1. Define the endless word.
endless 2. When the endless word is executed:
1. The loop begins.
2. The address and length of a string constant
are placed on the stack and used to display
the string of character codes.
3. The loop goes back to the beginning again.
: endless S" hello" BEGIN 2DUP TYPE AGAIN ; 1. Define the endless word.
endless 2. When the endless word is executed:
1. The address and length of a string constant
are placed on the stack.
2. The loop begins.
3. TOS and NOS are duplicated and used to
display the string of character codes.
4. The loop goes back to the beginning again.
Loops - Begin Until
LOOPS - BEGIN UNTIL
: xxx BEGIN code test UNTIL ; Create a word containing a BEGIN UNTIL loop by using the ( flag - - )
colon (:) word to open a definition, a name for the word, the
BEGIN word, the code to run on each loop, the specified test, the
UNTIL word, and the semi-colon (;) word.
xxx Execute the word, causing an endless loop that executes the
specified code and keeps looping until the test is true or until a
break is provided by pressing Ctrl + C or until the terminal
window is closed to end or exit the loop. The code always
executes at least once.
The difference between the BEGIN-UNTIL loop and the BEGIN-WHILE-REPEAT loop is that all of the code
in both loops always executes except for code2 in the BEGIN-WHILE-REPEAT loop, which never executes at
all if the flag is false.
LOOPS - BEGIN UNTIL - EXAMPLE
: code ." hello world" CR ; The words used by the examples below.
: test KEY 32 = ; • The code is a string of character codes followed by a
carriage return, but could be any code.
• The test is for whether the space bar was pressed, but could
be any test.
: example CR BEGIN code test UNTIL ; 1. A carriage return is displayed before the loop begins.
2. The loop begins.
3. The code is executed.
4. A test is done.
5. If the test is false, the loop continues by repeating.
6. If the test is true, the loop exits immediately.
: example CR BEGIN test UNTIL ; 1. A carriage return is displayed before the loop begins.
2. The loop begins.
3. A test is done.
4. If the test is false, the loop continues by repeating.
5. If the test is true, the loop exits immediately.
Loops - Begin While Repeat
LOOPS - BEGIN WHILE REPEAT
: xxx BEGIN code1 test WHILE code2 REPEAT ; Create a word containing a BEGIN WHILE ( flag - - )
REPEAT loop by using the colon (:) word to
open a definition, a name for the word, the
BEGIN word, the first code, the test, the
WHILE word, the second code, the REPEAT
word, and the semi-colon (;) word.
xxx Execute the specified word, causing an endless
loop that executes code 1 and, if the test is true,
executes code2 and keeps looping until the test
is false or until a break is provided by pressing
Ctrl + C or until the terminal window is closed
to end or exit the loop. Note: If you leave out
code1, then code2 only executes if test is true.
Otherwise, the loop exits immediately.
The difference between the BEGIN-WHILE-REPEAT loop and the BEGIN-UNTIL loop is that all of the code
in both loops always executes except for code2 in the BEGIN-WHILE-REPEAT loop, which never executes at
all if the flag is false.
LOOPS - BEGIN WHILE REPEAT - EXAMPLE 1
: code1 ." hello" CR ; The words used by this example:
: code2 ." world" CR ; • code1 is a string of character codes followed
: test KEY 32 <> ; by a carriage return, but could be any code.
• code2 is a string of character codes followed
by a carriage return, but could be any code.
• test determines whether the space bar was not
pressed, but could be any test.
: xxx CR BEGIN code1 test WHILE code2 REPEAT ; 1. A carriage return is displayed before the loop
xxx begins.
2. The loop begins.
3. code1 is executed.
4. A test is done.
5. If the test is true, the loop continues by
executing code2 and repeating.
6. If the test is false, the loop exits immediately
and code2 is not executed.
LOOPS - BEGIN WHILE REPEAT - EXAMPLE 2
: code1 ." hello" CR ; The words used by this example:
: code2 ." world" CR ; • code1 is a string of character codes followed by a
: test KEY 32 <> ; carriage return, but could be any code.
• code2 is a string of character codes followed by a
carriage return, but could be any code.
• test determines whether the space bar was not
pressed, but could be any test.
: xxx CR BEGIN code1 test WHILE REPEAT ; 1. A carriage return is displayed before the loop begins.
xxx 2. The loop begins.
3. code1 is executed.
4. A test is done.
5. If the test is true, the loop continues by repeating.
6. If the test is false, the loop exits immediately.
LOOPS - BEGIN WHILE REPEAT - EXAMPLE 3
: code2 ." world" CR ; The words used by the example below:
: test KEY 32 <> ; • code2 is a string of character codes followed by a
carriage return, but could be any code.
• test determines whether the space bar was not pressed,
but could be any test.
: xxx CR BEGIN test WHILE code2 REPEAT ; 1. A carriage return is displayed before the loop begins.
xxx 2. The loop begins.
3. A test is done.
4. If the test is true, the loop continues by executing
code2 and repeating.
5. If the test is false, the loop exits immediately and code
2 is not executed.
LOOPS - BEGIN WHILE REPEAT - EXAMPLE 4
: test KEY 32 <> ; The word used by the example below:
• The test is for whether the space bar was not pressed,
but could be any test.
: xxx CR BEGIN test WHILE REPEAT ; 1. A carriage return is displayed before the loop begins.
xxx 2. The loop begins.
3. A test is done.
4. If the test is true, the loop continues by repeating.
5. If the test is false, the loop exits immediately.
Loops - Do Loop
LOOPS - DO LOOP
You specify the starting value and the limit + 1 of the loop, and it will loop the specified (limit) number of
times, with the index going from the specified (start) number to the specified (limit - 1) number.
: xxx limit start DO code LOOP ; Create a word comtaining a DO loop by using the colon (:) ( limit start - - )
word to open a definition, a name for the word, the limit
(maximum total number of iterations the loop may run), the
starting value (number of the iteration to begin the loop on),
the DO word, the code to run on each loop, the LOOP
word, and the semi-colon (;) word.
xxx Execute the word with its name, starting a counted loop
with the specified number of iterations having been set by
you providing the limit + 1 (since the count starts at 0) and
the starting value of the loop and the code to be executed
on each iteration.
The DO word doesn't guard against the start and limit being the same, which would result in a runaway loop
that continues until a break is provided by pressing Ctrl + C or until the terminal window is closed to end or
exit the loop.
The ?DO word can be used instead to guard against the start and limit being the same when the loop executes,
preventing the loop from running at all. There's no harm in always using the ?DO word.
With a DO-LOOP you can start with any number, while with a FOR-NEXT you can't specify a starting value.
LOOP - DO LOOP - EXAMPLE
: newword 3 0 DO existingword LOOP; Define a new word that executes an existing word up to a
newword total of 3 times starting at zero.
: xxx 3 1 DO ." HELLO WORLD" LOOP ; Define the xxx word that displays the HELLO WORLD
xxx string of character codes up to a total of 3 times starting
at 1.
: xxx 10 10 ?DO ." HELLO WORLD " LOOP ; Define the xxx word that displays the HELLO WORLD
xxx string of character codes up to a total of 10 times starting
at 10, which causes ?DO to prevent the loop from
running at all.
Loops - For Next
LOOPS - FOR NEXT
You specify the number of times the loop runs, and it will loop the specified number of times, with the index
going from 0 to the specified number (num - 1).
: xxx n FOR code NEXT ; Create a word containing a FOR NEXT loop with the colon (:) word ( n - - )
to open a definition, name for the word, the number of iterations the
loop may run, the FOR word, the code to run on each loop, the NEXT
word, and the semi-colon (;) word.
xxx Execute the word with its name, starting a counted loop with the
specified number of iterations (with the index going from 0 to the
number [n -1]) and the code to be executed on each iteration.
With a DO-LOOP you can start with any number, while with a FOR-NEXT you can't specify a starting value.
LOOPS - FOR NEXT - EXAMPLE
: xxx 9 FOR ." hello world" NEXT ; Define the xxx word that displays the hello world string of character
codes 10 times, with the index going from 0 to 9 (n - 1).
xxx Execute the xxx word.
Memory Access Manipulations
MEMORY ACCESS MANIPULATIONS
@ The fetch word fetches a byte from memory. ( address - - byte )
! The store word stores a byte in memory. ( byte address - - )
+! The plus-store word takes the number at NOS (next on stack after TOS), ( number address -- )
adds it to the value stored at the address at TOS, and saves that sum as the
new value at that address.
ALLOT The allot word allocates memory space for operation. (--)
C@ The character fetch word fetches an 8-bit character from memory. ( address - - chars )
C! The character store word stores an 8-bit character in memory ( chars address - - )
HERE The HERE word puts the next free memory address (the first available byte ( - - address)
above the dictionary) on the stack. This is a word that places the memory
address on the stack of the top of the dictionary, where user definitions are
found growing from low memory toward high memory as new words are
defined, and marking an area where users can put things temporarily. But
beware! It's a place you can play, but an address the system can use when
needed.
MEMORY ACCESS MANIPULATIONS - EXAMPLE
'a HERE C! Store the character code for the letter a at the address HERE. Note: The ' (tick) calls up the
code field address which, for an ASCII character, is its character code.
HERE C@ EMIT Fetch the character code located at the address HERE and EMIT it to see the letter a.
Memory Allotted To Variables And Arrays
MEMORY ALLOTTED TO VARIABLES AND ARRAYS
Creating a variable or array with 1 ALLOT reserves 1 8-bit byte of memory. Not recommended.
Creating a variable or array with 1 CHARS ALLOT reserves 1 8-bit byte of memory.
Creating a variable or array with 1 CELLS ALLOT reserves 8 8-bit bytes of memory.
Looking at that visually:
VARIABLE charvar 1 CHARS ALLOT
VARIABLE cellvar 1 CELLS ALLOT
charvar 1 CHARS DUMP
7FCC07AE2508: 00 - .
cellvar 1 CELLS DUMP
7FCC07AE2540: 00 00 00 00 00 00 00 00 - ........
...the latter of the two is 8 bytes, making up one cell, shown in hexadecimal (base 16) where FF is a byte with
all bits set and 00 is a byte with all bits unset. To the right, following the dash, the dots also represent bytes.
Memory - Reserving And Acting On Memory
MEMORY - RESERVING AND ACTING ON MEMORY
ALLOT n CHARS (also bytes, numbers 0 to 255)
ALLOT n CELLS (blocks of 8 bytes, 64-bits)
n CHARS or CELLS ERASE
character FILL
COUNT TYPE (display as characters)
n CHARS or CELLS DUMP (displays as hex bytes)
Miscellaneous
MISCELLANEOUS
8 EMIT Displays the 8 ASCII character, which is a backspace, deleting what was there (great for
getting rid of unwanted spaces in output).
#! /usr/bin/gforth Start a Forth script with this line to let the interpreter know what kind of file it's working
with.
' The tick (') word calls up the code field address which, for a character, is its numeric
value. Whether a ticked value appears as a decimal or a hexadecimal or a character all
depends on which tool you're using:
• @ Displays as a decimal by default or in whatever number base it's in at the time.
• dump displays as hex bytes
• emit displays as characters
• type displays as characters
See also:
• http://www.ascii-code.com/
• http://unicode-table.com/en/#latin-extended-a
: The colon (:) word starts the compilation of a definition.
; The semicolon (;) word ends the compilation of a definition.
: xxx CR ; Compile the specified word with its definition (example: a carriage return), adding it to
the current dictionary.
: xxx CR CR ; Recompile the existing specified word (example: xxx) with a new definition (example:
two carriage returns), replacing its definition in the current dictionary.
BYE The BYE word quits the Forth interpreter altogether.
cat ~/.gforth-history Check the Forth history in a terminal window. Note that Gforth never trims the size of the
history file, so you should do this periodically, retaining anything you wish.
[CHAR] The bracket-char word is a way to use the CHAR word inside of a colon definition.
EXIT The EXIT word takes you out of the running word/program and back into the Forth
interpreter.
gforth scriptname Run a Gforth script in a terminal window.
MARKER mmm The MARKER word sets a marker in the current dictionary with the specified name
(example: mmm).
mmm Execute the marker by using its name (example: mmm) to remove it and all subsequent
words in the current dictionary and readjust the dictionary pointers (RAM and ROM).
PAGE Clears away all the displayed data, simulating a clear-screen by advancing the terminal
display, leaving ok at the upper right of the blank terminal window. You can still scroll
back to see the old terminal contents.
SEE xxx The SEE word decompiles the specified word (example: xxx) and displays the contents it
was built from.
stub A stub is a temporary definition. It might simply display a message to let us know it's been
executed or it may do nothing at all except resolve the reference to its name in the high-
level definition.
TIB The terminal input buffer. Also the location which the PLACE word takes as a string
constant's address. You can execute the TIB word directly to get the current address of the
terminal input buffer.
Note: TIB is deprecated and has allegedly been replaced by SOURCE, but if you do
SEE TIB and SEE SOURCE, they aren't the same, so it might be a good idea to keep
TIB in your toolbox.
xxx Execute the specified word (example: xxx).
xxx yyy Execute more than one word (example: xxx and yyy).
Forth is NOT case sensitive. You can type commands and names in any case.
It is recommended to always use a dimension word: 1 CHARS or 1 CELLS, so there's no confusion.
MISCELLANEOUS - EXAMPLE 1
CHAR a . Display the character code of the letter a at the Forth interpreter command line.
: example [CHAR] a . ; Define the example word to display the character code of the letter a.
example Execute the example word.
CHAR test EMIT Display the first character of the test string of character codes at the Forth
interpreter command line.
: example [CHAR] test EMIT ; Define the example word to display the first character of the test string of character codes.
example Execute the example word.
Numbers - About Types Of Numbers
NUMBERS - ABOUT TYPES OF NUMBERS - EXPLANATION
Forth has five types of numbers and all the related operators and converters that go with them:
1. Single precision unsigned integers.
2. Single precision signed integers.
3. Double precision unsigned integers.
4. Double precision signed integers.
5. Floating point numbers.
Single precision integers, which occupy 1 cell that is 8 bytes or 64 bits in length, are used for most non-
calculating purposes:
• Unsigned 1-cell single-precision integers ranging from 0 to 18,446,744,073,709,551,615.
• Signed 1-cell single-precision integers ranging from -9,223,372,036,854,775,808 to
9,223,372,036,854,775,807.
Double precision integers, which occupy 2 cells, each of which is 8 bytes or 64 bits in length for a total of 16
bytes or 128 bits in length, are used for calculating large results:
• Unsigned 2-cell double-precision integers ranging from 0 to
340,282,366,920,938,463,463,374,607,431,768,211,455.
• Signed 2-cell double-precision integers ranging from
−170,141,183,460,469,231,731,687,303,715,884,105,728 to
170,141,183,460,469,231,731,687,303,715,884,105,727.
Floating point numbers, which occupy 2 cells, each of which is 8 bytes or 64 bits in length, for a total of 16
bytes or 128 bits in length, are used for calculations that require Scientific Notation. For example: 1.2e1 2.3e1
F* F. where 12 (1.2e1) multiplied by (F*) 23 (2.3e1) equals (F.) 276.
Note: the trailing dot in the result (276.) denotes a floating point answer.
Note: The exponent (the e or E) in Scientific Notation is powers of 10 (e1=10, e2=100, e3=1000 etc.) which,
when multiplied by the "mantissa" (1.2 and 2.3 in our example), produces the number (12 and 23 in our
example).
Signed 2-cell double-precision floating-point number values:
• Decimal minimum: -1.79769313486231E308
• Decimal maximum: +1.79769313486231E308
• Decimal range: +-1.79769313486231E308
• Binary minimum: Can't be represented in binary.
• Binary maximum: Can't be represented in binary.
• 15 digits precision in the mantissa: 1.79769313486231
• Largest exponent: 308
• You have to enter the floating point numbers in Scientific Notation (e.g.: 1.2e1 not 12).
Numbers - Bases - Numeric Prefixes
NUMBERS - BASES - NUMERIC PREFIXES
Gforth lets you override the current base by using a prefix before an integer to define its base. If the compiler
supports prefixes, they should be used whenever possible so there's no doubt which kind of value is intended. If
the compiler doesn't support prefixes, always prefix hexadecimal values with a zero.
& Decimal - Use the & (ampersand) prefix.
# Decimal - Use the # (hash) prefix.
% Binary - Use the % (percent) prefix.
$ Hexadecimal - Use the $ (dollar) prefix.
0x Hexadecimal (if the current base is less than 33) - Use the 0x (zero x) prefix.
' Numeric value (ASCII code, Unicode) - Use the ' (tick) prefix.
NUMBERS - BASES - NUMERIC PREFIXES - EXAMPLE
&10 . Use the & (ampersand) prefix with 10 and the dot (.) word to read (interpret) the
value as a decimal and display its value in the current base (displays 10 in the default
decimal base).
#10 . Use the # (hash) prefix with 10 and the dot (.) word to read (interpret) the value as a
decimal and display its value in the current base (displays 10 in the default decimal
base).
%10 . Use the % (percent) prefix with 10 and the dot (.) word to read (interpret) the value as
a binary and display its value in the current base ( displays 2 in the default decimal
base).
$263a XEMIT Use the $ (dollar) prefix with 263a and the XEMIT word to read (interpret) the value
as a hexadecimal and display its value in the current base ( displays ☺in the default
decimal base).
0x263a XEMIT Use the 0x (zero x) prefix with 263a and the XEMIT word to read (interpret) the value
as a hexadecimal and display its value in the current base (displays ☺ in the default
decimal base) if the current base is less than 33.
'a XEMIT Use the ' (tick) prefix with a and the XEMIT word to read (interpret) the value as
decimal numeric code (ASCII code) and display its value in the current base (displays
a in the default decimal base).
You can change the base for the display value by specifying a new base before the prefix or before the dot (.)
word.
: BINARY 2 BASE ! ; Define the BINARY word.
BINARY #10 . Execute the BINARY word and use the # (hash) prefix with 10 to read (interpret) the
value as a decimal and display its value with the dot (.) word in the current base
(displays 1010 since BINARY was specified).
: BINARY 2 BASE ! ; Define the BINARY word.
#10 BINARY . Use the # (hash) prefix with 10 to read (interpret) the value as a decimal and specify
the current base with the BINARY word and display the prefixed number's value with
the dot (.) word in the current base (displays 1010 since BINARY was specified).
NUMBERS - BASES - NUMERIC PREFIXES - EXPLANATION
To get the decimal value of a binary integer:
%1111111111111111 .
%0111111111111111 .
The results:
65535
32767
To get the binary value of a decimal integer:
: BINARY 2 BASE ! ;
BINARY
#2 .
#1000 .
DECIMAL
The result:
10
1111101000
When changing number bases, it can be important to be aware of which number base Forth is currently using so
that you don't get unexpected results when working with numbers. The BASES word represents the current
number base.
Use the BASES ? command (the BASES word with the question (?) word) to display the current number base.
• If Forth returns 1010 it's using the BINARY number base.
• If Forth returns 10 it's using the DECIMAL number base.
• If Forth returns A it's using the HEXADECIMAL number base.
• If Forth returns 12 it's using the OCTAL number base.
You're in hex mode from the first time you execute the HEX word and until you execute the DECIMAL word
or leave Gforth. There's no harm in typing DECIMAL if you're already in decimal mode (but it's unnecessary).
BASE is a write-only system variable, but you can execute BASES ? at any time to check which mode you're
in. You could even automate that:
DECIMAL ok
BASES @ 10 = . -1 ok
HEX ok
BASES @ 10 = . 0 ok
BASES @ a = . -1 ok
...where your code checks BASES and either stays in what it sees or goes into an alternate mode with, for
example, 8 BASE ! so you can enter stuff like 12 when you "mean" 10.
Your Forth system already has a number of words defined by default. The DECIMAL, HEX, and OCTAL (if
your system has it) words are provided for you.
Their definitions are:
: DECIMAL 10 BASE ! ;
: HEX 16 BASE ! ;
: OCTAL 8 BASE ! ;
Each of them uses the BASE and store (!) words to set the number base and store it in the dictionary. You can
define your own words using the BASE word to set the number base you wish to work in. For example, the
BINARY word isn't provided for you, but you can define it this way:
: BINARY 2 BASE ! ;
Forth uses the DECIMAL number base by default, but you can work in any of these number bases by
executing their words. For example, if you execute the HEX word, Forth will use the HEXADECIMAL
number base for everything that follows until you execute the DECIMAL word or close the interpreter or
terminal window.
You can work in any additional number base by creating a new word and storing the number in BASE inside
the word by using the store (!) word in the same way that 10, 16, and 8 were stored into the BASE word in the
DECIMAL, HEX, and OCTAL words above.
You can work in any number base (e.g., 2, 8, 10, 16, 36) by storing the number in BASE the same way the
numbers are stored in the DECIMAL and HEX words. For example:
10 BASE !
16 BASE !
Numbers - Converting And Displaying
NUMBERS - CONVERTING AND DISPLAYING
. Display a single-precision signed integer.
U. Display a single-precision unsigned integer.
S>D Convert a single-precision integer to a double-precision integer.
D. Display a double-precision signed integer.
UD. Display an double-precision unsigned integer.
D>S Convert a double-precision integer to a single-precision integer.
NUMBERS - CONVERTING AND DISPLAYING - EXAMPLE
%1111111111111111111111111111111111111111111111111111111111111111 .
%0111111111111111111111111111111111111111111111111111111111111111 .
%1111111111111111111111111111111111111111111111111111111111111111 u.
%1111111111111111111111111111111111111111111111111111111111111111 s>d ud.
Numbers - Formatted Numeric Output
NUMBERS - FORMATTED NUMERIC OUTPUT
Gforth supports several types of numerical formatting that allow the display of numbers in ways that are
different from the . and U. and D. and UD. and F. print words. They are .R and U.R and D.R and UD.R and
F.RDP. First, we will take a quick look at .R and single-precision signed integers.
Expression: Output: Comment:
123 5 .R 456 5 .R 123 Each 5 paired with each number with .R causes the pairs to
456 be right justified in a field 5 characters wide. This is useful
for outputting a group of numbers as a table
: test CR 7 1 DO i 5 .R i 3 MOD 1 2 3 The test definition is a DO loop that goes from 1 to 6 (7-1)
0= IF CR THEN LOOP ; 4 5 6 printing the index (i) in a field 5 characters wide (5 .R)
inserting a CR after each 3 numbers (i 3 MOD 0= IF CR
THEN).
Gforth also supports formatted numerical output where the digits of a double-precision number can be
accessed individually and interspersed with non-numerical characters. This capability is useful for printing
currency, time, dates, accounting, etc. We will take a quick look at two examples, and leave it to the reader to
explore the others.
54321 0 <# # # '. HOLD #S '$ $543.21 The formatting proceeds from right to left, starting with
HOLD #> TYPE (#>), a dollar sign ('$ HOLD), the remaining unused digits
(#S), a decimal point ('. HOLD), and two cents digits (# #),
and ending with (<#).
TIME&DATE 9/6/2016 Executing the Gforth TIME&DATE word puts the bits of
SWAP S>D <# 47 HOLD #S #> the current time and date unformatted on the stack.
PAD PLACE ( DAY AND /) (The current Formatting then assembles them into the dd/m/yyyy form
SWAP S>D <# 47 HOLD #S #> date at time by moving them into the correct order on the stack with the
PAD +PLACE ( MONTH AND /) of execution) SWAP word, converting them to double-precision integers
S>D <# #S #> with the S>D word, following each bit with the / character
PAD +PLACE ( YEAR) (<# 47 HOLD #S #>), and placing each formatted bit at the
scratch (PAD) following the first (PLACE) with the
PAD COUNT TYPE (+PLACE) append, which assembles the day/month/year.
The result is output by (PAD COUNT TYPE) and could
be stored in a variable.
The print normal words mentioned above have these actions:
• . prints single-length signed integers
• U. prints single-length unsigned integers
• D. prints double-length signed integers
• UD. prints double-length unsigned integers
• F. prints floating-point numbers
The print formatted words mentioned above have these corresponding actions:
• R. prints single-length signed integers
• U.R prints single-length unsigned integers
• D.R prints double-length signed integers
• UD.R prints double-length unsigned integers
• F.RDP prints floating-point numbers, with the latter being more complex as it supports all the
characteristics of floating point numbers.
Examples: Output: Comment:
1234 5 U.R 1234 Single-length unsigned, width 5.
-1234 S>D 5 D.R -1234 Double-length signed, width 5.
1234 S>D 5 UD.R 1234 Double-length unsigned, width 5.
1.234E3 7 3 4 F.RDP 1.234E3 Floating point, width 7, digits after the decimal point 3, and
minimum number of significant digits 4.
Numbers - Signed Integers
NUMBERS - SIGNED INTEGERS - EXPLANATION
About signed integers:
• You can use a signed integer for positive or negative values (but not zero).
Note: When you go from -1 and add 1, the binary number "rolls over" to
0000000000000000000000000000000000000000000000000000000000000000 which, technically, is
an unsigned value due to the left-most or sign bit being 0.
• You need a signed integer for negative values.
• You need a - on the left to indicate that the value is a signed negative integer.
• You don't need to do anything to indicate that the value is a signed positive value.
• When there is no minus to the left of an integer in decimal or when the sign bit is set to 0 in binary,
the integer is positive.
• When there is a minus to the left of an integer in decimal or when the sign bit is set to 1 in binary, the
integer is negative.
Only 63 bits contribute to the value of a 64-bit signed single-precision 1-cell integer (the left- most bit
contributes the sign).
• Minimum decimal value: -9,223,372,036,854,775,808
• Maximum decimal value: 9,223,372,036,854,775,807
• Minimum binary value:
1000000000000000000000000000000000000000000000000000000000000000
• Maximum binary value:
• 0111111111111111111111111111111111111111111111111111111111111111
Only 127 bits contribute to the value of a 128-bit signed double-precision (2-cell) integer (the left- most bit
contributes the sign).
• Minimum decimal value: −170,141,183,460,469,231,731,687,303,715,884,105,728
• Maximum decimal value: 170,141,183,460,469,231,731,687,303,715,884,105,727
• Minimum binary value:
10000000000000000000000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000
• Maximum binary value:
11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
11111111111111111111111111111111111111
Numbers - Unsigned Integers
NUMBERS - UNSIGNED INTEGERS - EXPLANATION
About unsigned integers:
• You can use an unsigned integer only for non-negative (zero or positive) values.
• You need an unsigned integer for positive values over 9,223,372,036,854,775,807. Otherwise, a signed
integer would do just as well.
• You don't need to do anything to indicate that the value is an unsigned positive value.
All 64 bits contribute to the value of an unsigned single-precision 1-cell integer:
• Minimum decimal value: 0
• Maximum decimal value: 18,446,744,073,709,551,615
• Minimum binary value:
0000000000000000000000000000000000000000000000000000000000000000
• Maximum binary value: 1111111111111111111111111111111111111111111111111111111111111111
All 128 bits contribute to the value of an unsigned double-precision (2-cell) integer :
• Minimum decimal value: 0
• Maximum decimal value: 340,282,366,920,938,463,463,374,607,431,768,211,455
• Minimum binary value:
00000000000000000000000000000000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000
• Maximum binary value:
11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
111111111111111111111111111111111111111
Parsing content from the input buffer
PARSE
HERE PARSE input Get the specified input from the input stream and store its address here with the HERE
word, the PARSE word, and the input text.
CR TYPE Display a carriage return followed by the input text stored here with the CR word
followed by the TYPE word.
If you want to preserve what has been captured, move it into a variable, value, or safe address, before the next
execution overwrites it.
PARSE - EXAMPLE
HERE PARSE hello world Get hello world from the input stream and store its address here.
CR TYPE Display a carriage return followed by hello world.
PARSE-NAME
CREATE xxx Create the xxx variable with the CREATE word and the specified variable name (xxx
in this example).
S" hello" Declare the specified string of character codes (hello in this example) and place its
address and length onto the stack.
xxx PLACE Put the specified variable's (xxx in this example) address onto the stack. Take the
address and length of the string from the stack along with the address of the variable
and place them into the variable with the variable name and the PLACE word.
Note: PLACE expects the source address, source length, and destination address to be
on the stack in that order.
xxx COUNT TYPE Put the specified variable's (xxx in this example) address onto the stack, put the length
of the variable's contents (the string of character codes in this example) onto the stack
and display the specified string of character codes (hello in this example) from its
address and length with the specified variable's name (xxx in this example), the
COUNT word, and the TYPE word.
PARSE-NAME world Capture the specified string of character codes (world in this example) address and
length from the input buffer and put them onto TOS.
xxx PLACE Put the specified variable's (xxx in this example) address onto the stack. Take the
address and length of the string from the stack along with the address of the variable
and place them into the variable with the variable name and the PLACE word.
Note that this replaces the string of character codes that was stored in the variable
previously.
Note: PLACE expects the source address, source length, and destination address to be
on the stack in that order.
xxx COUNT TYPE Put the specified variable's (xxx in this example) address onto the stack, put the length
of the variable's contents (the string of character codes in this example) onto the stack
and display the specified string of character codes (world in this example) from its
address and length with the specified variable's name (xxx in this example), the
COUNT word, and the TYPE word.
Random
RANDOM
INCLUDE random.fs Use this command before using the RANDOM word to include (–)
random words in Gforth.
S" random.fs" INCLUDED Or use this command before using the RANDOM word to include (–)
random words in Gforth.
n RANDOM The RANDOM word takes a number off of TOS and generates a ( n1 – n2 )
random number between zero and that number.
RANDOM - EXAMPLE
INCLUDE random.fs Include the random words in Gforth.
6 RANDOM Use the RANDOM word to take 6 off of TOS and put a random number from 0
to 5 onto the TOS.
. Use the dot (.) word to remove the random number from TOS and display it.
RND
INCLUDE random.fs Use this command before using the RND word to (–)
include the random words in Gforth.
S" random.fs" INCLUDED Or use this command before using the RND word to (–)
include the random words in Gforth.
RND The RND word generates huge positive and negative (–n)
numbers that you can prune as desired.
RND - EXAMPLE
INCLUDE random.fs Include the random words in Gforth.
RND Use the RND word to generate a huge positive or negative number and put it on TOS.
. Use the dot (.) word to remove the random number from TOS and display it.
RND - EXPLANATION
SEE RND : rnd seed @ 272958469 um* drop 1+ dup seed ! ;
Explanation 1. Fetch the contents of seed from its address on the stack.
2. Unsigned multiply that by 272858569 and drop the high byte of that result.
3. Add 1 to the remaining low byte and store the result back into seed.
Why? This word ensures that, upon each execution, you get a number as close to truly mathematically
random as possible.
Refill
REFILL - NUMBERS
REFILL xxx Fill the input buffer with the user's numeric input with the REFILL word, a temporary name for
the input buffer, a press of the Enter key, input from the user, and another press of the Enter key.
. Display the result with the dot (.) word.
If you want to preserve what has been captured, move it into a constant, variable, value, or safe address, before
the next execution overwrites it.
REFILL - NUMBERS - EXAMPLE
REFILL xxx Fill the xxx input buffer with 6 (not visible - must be typed in manually).
. Remove the 6 from the input buffer and display it.
REFILL - STRINGS
: xxx CR ." Type something and press Define a word with the carriage return (CR) word, a string of
the Enter key: " REFILL WORD CR ." character codes, the RFILL word, the WORD word, the carriage
You typed: " COUNT TYPE ; return (CR) word, another string of character codes, the COUNT
word, the TYPE word, the semi-colon (;) word.
xxx Execute the xxx word, press the Enter key, type in some input, and
press the Enter key to fill the input buffer with the specified string
input and display the result.
Note: The REFILL word needs some help from the WORD word so it can capture the input as a string:
• REFILL fills the input buffer from the source (the WORD word in this example).
• WORD parses the string and puts its c-addr (address) on the stack.
• COUNT gets the length of the string from its address on the stack.
• TYPE displays the string.
REFILL - STRINGS - EXAMPLE
: xxx CR ." Type something and press Fill the xxx input buffer with 6 (not visible - must be typed in
the Enter key: " REFILL WORD CR ." manually).
You typed: " COUNT TYPE ;
xxx Display the 6.
Stack - Add To The Stack
STACK - ADD TO THE STACK
n Put the specified number (n in this example) on top of the (–n)
stack.
n1 n2 Put the specified number (n1 in this example) on TOS (top of ( – n1 n2 )
stack) and then the next specified number (n2 in this
example) on TOS, making the first number NOS (Next On
Stack).
S" Starting word for putting a string of character codes on top of
the stack as two values - first the address where it is stored in
memory and then its length.
" Closing character for a string of character codes (no space is
needed before it unless you want a space in the string of
character codes).
S" hello" Put the hello string of character codes on the top of the stack ( – addr len )
(as two values - see S" above).
S" hello" S" world" Put the hello string of character codes and the world string of ( – addr1 len1 addr2 len2 )
character codes on the top of the stack as 2 sets of 2 values
each (see S" above).
STACK - ADD TO THE STACK - EXAMPLE 1
1 Put the number 1 on top of the stack.
STACK - ADD TO THE STACK - EXAMPLE 2
12 Put the number 1 on TOS (top of stack) and then the number 2 on TOS, making the number 1 NOS (Next
On Stack).
Stack - Addresses
STACK - ADDRESSES
DEPTH Return the number of items on the stack. ( – +n )
DEPTH . Return the number of items on the stack and display the result. ( – +n )
SP@ Fetch the address at the top of the stack. ( -- addr )
SP@ . Fetch the address at the top of the stack and display it. ( -- addr )
SP@ @ . Fetch the item at the top of the stack and display it. ( -- n )
SP@ ? Fetch the item at the top of the stack and display it directly. ( -- n )
SP0 Fetch the address of the next cell below the empty stack cell. ( -- addr )
SP0 . Fetch the address of the next cell below the empty stack cell and display it. ( -- addr )
SP0 @ Fetch the address of the next cell below the empty stack cell. ( -- addr )
SP0 @ . Fetch the address of the next cell below the empty stack cell and display it. ( -- addr )
SP0 ? Fetch the address of the next cell below the empty stack cell and display it. ( -- addr )
The top of the stack word was created with s p at and the bottom of the stack word was created with s p zero.
Stack - Clear/Drop/Delete/Remove Stack Items
STACK - CLEAR/DROP/DELETE/REMOVE STACK ITEMS
DROP Drops the top of stack value off of the stack. (a--)
2DROP Drops the top of stack set of values (address and length for strings of (ab--)
character codes, the two cells for double length integers) off of the
stack.
CLEARSTACK Clears everything off of the stack. ( …- - )
NIP Drops the second value off of the stack. (ab--b)
2NIP Drops the second set of values (address and length for strings of (a b c d -- c d )
character codes, the two cells for double length integers) off of the
stack.
Note: Many words, like the dot (.) word, remove a value from the TOS, displaying it to the screen.
STACK - CLEAR/DROP/DELETE/REMOVE STACK ITEMS - EXAMPLE 1
123 Put 1 and 2 and 3 on the stack.
.S Display the contents of the stack.
DROP Destructively remove the TOS item.
.S Display the contents of the stack.
STACK - CLEAR/DROP/DELETE/REMOVE STACK ITEMS - EXAMPLE 2
123 Put 1 and 2 and 3 on the stack.
.S Display the contents of the stack.
CLEARSTACK Destructively remove everything from the data stack.
.S Display the contents of the stack.
Stack - Copy/Duplicate Stack Items
STACK - COPY/DUPLICATE STACK ITEMS
DUP Duplicates the top value (top of stack or TOS), putting the duplicate on top. (a--aa)
2DUP Duplicates the TOS set of values (address and length for strings of character (ab--abab)
codes, the two cells for double length integers), putting the duplicates on
TOS.
?DUP Conditional DUP if the stack isn't empty. (a--aa)
OVER Copies the second value (next on stack or NOS) to TOS. (ab--aba)
2OVER Copies the second set of values (address and length for strings of character (a b c d - - a b c d a b )
codes, the two cells for double length integers) to TOS.
n PICK Copies the value in the specified stack position to TOS (with the number
indicating the stack position of the value to be copied, and with 0 copying
the TOS value to TOS, 1 copying the NOS value to TOS, and so on).
TUCK Copies the TOS value to the third position on the stack. (abc--acbc)
2TUCK Copies the TOS set of values (address and length or double integer cells) to ( a b c d -- c d a b c d )
the third position on the stack.
STACK - COPY/DUPLICATE STACK ITEMS - EXAMPLE 1
123 Put 1 and 2 and 3 on the stack.
.S Display the contents of the stack.
DUP Copy TOS to TOS.
.S Display the contents of the stack.
STACK - COPY/DUPLICATE STACK ITEMS - EXAMPLE 2
123 Put 1 and 2 and 3 on the stack.
.S Display the contents of the stack.
OVER Copy NOS to TOS.
.S Display the contents of the stack.
STACK - COPY/DUPLICATE STACK ITEMS - EXAMPLE 3
123 Put 1 and 2 and 3 on the stack.
.S Display the contents of the stack.
0 PICK Copy TOS to TOS.
.S Display the contents of the stack.
STACK - COPY/DUPLICATE STACK ITEMS - EXAMPLE 3
123 Put 1 and 2 and 3 on the stack.
.S Display the contents of the stack.
2 PICK Copy the third value on the stack to TOS.
.S Display the contents of the stack.
Stack - Display The Stack
STACK - DISPLAY THE STACK
. Removes and displays the TOS item on the data (parameter) stack. (n–)
.S Displays the data (parameter) stack count and contents. ( ... – ... )
. CR Removes and displays the TOS item followed by a carriage return. ( n -- )
CR . Displays a carriage return followed by removing and displaying the ( n -- )
TOS item.
CR . CR Displays a carriage return followed by removing and displaying the (n–)
TOS item followed by displaying a carriage return.
CR TYPE Displayss a carriage return and removes and processes the 2 TOS ( n1 n2 – )
values (numbers) that make up a string of character codes as an
address and length, displaying the result as characters.
CR TYPE CR Displays a carriage and removes and processes the 2 TOS values ( n1 n2 – )
(numbers) that make up a string of character codes as an address and
length, displaying the result as characters, and displays another
carriage return.
F. Removes and displays the TOS item on the floating point stack. ( fn – )
F.S Displays the floating point stack count and contents. ( ... – ... )
TYPE Removes and processes the 2 TOS values (numbers) that make up a ( n1 n2 – )
string of character codes as an address and length, displaying the
result as characters. The TYPE word expects the string of character
codes address and character count/length to be on the stack.
TYPE CR Removes and processes the 2 TOS values (numbers) that make up a ( n1 n2 – )
string of character codes as an address and length, displaying the
result as characters, and displays a carriage return.
." Starting word for displaying a string of character codes (displays what (see the next word)
follows).
" Ending word for displaying a string of character codes. (see the previous word)
8 EMIT Displays a backspace, deleting the character before it.
9 EMIT Displays a tab.
Stack - Math With The Stack
STACK - MATH WITH THE STACK
+. Removes the TOS and NOS values, adds them together and puts the ( n1 n2 – )
result on top of the stack (TOS), and removes and displays the TOS
value.
OVER SWAP + + . Copies the NOS value to TOS, swaps the TOS and NOS ( n1 n2 – )
values,removes the TOS and NOS values and adds them together and
puts the result on the stack, removes the TOS and NOS values and
adds them together and puts the result on the stack, and removes and
displays the TOS value.
-. Removes the TOS and NOS values, subtracts the TOS value from the ( n1 n2 – )
NOS value and puts the result on TOS, and removes and displays the
TOS value.
OVER SWAP - - . Copies the NOS value to TOS, swaps the TOS and NOS values, ( n1 n2 – )
removes the TOS and NOS values, subtracts the TOS value from the
TOS value and puts the result on the stack, subtracts the TOS value
from the TOS value and puts the result on the stack, and removes and
displays the TOS value.
*. Removes the TOS and NOS values, multiplies the TOS value with the ( n1 n2 – )
NOS value and puts the result on the stack, and removes and displays
the TOS value.
OVER SWAP * * . Copies the NOS value to TOS, swaps the TOS and NOS ( n1 n2 – )
values,removes the TOS and NOS values and multiplies them and
puts the result on the stack, removes the TOS and NOS values and
multiplies them and puts the result on the stack, and removes and
displays the TOS value.
/. Removes the TOS and NOS values, divides the NOS value by the ( n1 n2 – )
TOS value and puts the result on the stack, and removes and displays
the TOS value.
OVER SWAP / / . Copies the NOS value to TOS, swaps the TOS and NOS ( n1 n2 – )
values,removes the TOS and NOS values and divides the NOS value
by the TOS value and puts the result on the stack, removes the TOS
and NOS values and divides the NOS value by the TOS value and
puts the result on the stack, and removes and displays the TOS value.
MOD Removes the TOS and NOS values, divides the NOS value by the ( n1 n2 – n3 )
TOS value, returns the remainder from the division and puts it on the
stack.
/MOD Removes the TOS and NOS values, divides the NOS value by the ( n1 n2 – n3 n4)
TOS value, returns the remainder and quotient from the division and
puts them on the stack.
ABS Removes the signed number off of the TOS, gets its absolute value, ( -n – n )
and puts it on the stack.
NEGATE Removes the unsigned number off of the TOS, changes it to a ( n – -n )
negative, and puts it on the stack.
UM* Removes the TOS and NOS values, unsigned multiplies the NOS ( n1 n2 - - n3 0 )
value by the TOS value, and puts the result and a zero on the stack
(replaces the TOS value with a zero and the NOS value with the
result).
1+ Removes the TOS value, adds 1 to it, and puts the result on the stack. ( n1 -- n2 )
STACK - MATH WITH THE STACK - EXAMPLE 1
12+3*. Adds 1 plus 2, multiplies the result by 3, and displays the result.
The above example is the equivalent of (1 + 2) * 3 which is not the same as 1 + (2 * 3).
Conventional Notation, also known as infix, places the operator between the operands as in 1 + 2 = 3, where
parentheses are needed and greatly affect the outcome. Forth uses Reverse Polish Notation, also known as
postfix, where the operands precede the operator, and parentheses aren't used or needed.
STACK - MATH WITH THE STACK - EXAMPLE 2
-123 ABS . Removes -123 from the stack, gets its absolute value (123) and puts it on the
stack, removes the TOS value and displays it.
STACK - MATH WITH THE STACK - EXAMPLE 2
123 NEGATE . Removes 123 from the stack, changes it to a negative value (-123) and puts it on
the stack, removes the TOS value and displays it.
Stack - Move Stack Items Around
STACK - MOVE STACK ITEMS AROUND
1 ROLL Swaps TOS with NOS. (ab--ba)
2 ROLL Moves the third stack value to TOS. (abc--bca)
ROT Moves the third stack value to TOS. (abc--bca)
2ROT Moves the third set of values (address ( a b c d e f - - c d e f a b )
and length or double integer cells) to
TOS and NOS.
SWAP Swaps the TOS value with NOS. (ab--ba)
2SWAP Swaps the top set of values (address (abcd--cdab)
and length or double integer cells)
with the next set of values (address
and length or double integer cells).
: revstack DEPTH 0 DO i ROLL LOOP ; Reverses the order of all the stack ( a b c d -- d c b a )
items (not a default word, but an
example of how Forth may be
extended by writing words useful to a
task at hand).
Stack - Return Stack Manipulatives
STACK - RETURN STACK MANIPULATIVES
n Puts a numeric value on the data stack.
R> Moves the TOS return stack item to the top of the data stack.
2R> Copy all double value items from return stack to data stack.
>R Moves the TOS item from the data stack to the return stack.
2>R Move all double value items from data stack to return stack.
RDROP Drop item from return stack.
2RDROP Drop double value item from return stack.
R@ Fetches a copy of the TOS return stack item, putting it on the top of the data stack.
2R@ Fetch all double value items from return stack.
RP@ Return the address of the return stack pointer.
R@ is the equivalent of RP@ @ which means these two lines do the same thing:
R@
RP@ @
R@ fetches all items from the return stack, and RP@ @ returns the address of the return stack pointer and
fetches everything from it.
RETURN STACK AND DATA STACK - DISPLAY - EXAMPLE
1234 Puts a numeric value on the data stack.
>R R@ . R> >R moves the TOS data stack item to the return stack, R@ fetches a copy of the TOS item from
the return stack to the top of the data stack, . removes and displays the TOS item from the data
stack, and R> moves the TOS item from the return stack back to the data stack.
. Removes and displays the TOS data stack item.
Stack - TOS And NOS
STACK - TOS AND NOS - EXPLANATION
TOS Top Of Stack, which is to the right when the stack is displayed or in stack comments.
NOS Next On Stack, which is after (to the left of) TOS.
Stack - Types
STACK - TYPES - EXPLANATION
The data stack (or parameter stack) holds values (numbers, addresses, etc.). This is what Forth programmers
usually mean when they refer to "the stack".
The floating point stack holds floating point numbers. These can be viewed with the F.S word and displayed
with the f-dot (F.) word.
The locals stack holds local variables used in expressions that are not available to words outside those
expressions.
Use of local variables permits the same variable name to be used in multiple expressions inside colon
definitions without conflict. The values of these variables stay within their expressions. Local variables are
declared between curly braces {}.
Example of two defined words, each with the same-named local variables, without conflict between them :
: def1 { n1 n2 } n1 n2 max . ; ok
: def2 { n1 n2 } n1 n2 min . ; ok
55 66 def1 66 ok
55 66 def2 55 ok
The return stack keeps track of the twists and turns, loops, program pointers, (what would be called
subroutines in other languages), etc, that Forth needs to know to "return" from side trips, diversions,
digressions, etc. This can be VERY carefully used by the programmer. You don't want to have a value you
placed on the return stack still be there when it's time to exit a loop because the program will NEVER run until
you take off what you left abandoned on the return stack! Forth programmers often temporarily place things on
the return stack for safekeeping, BUT have to be very careful to remove it or them before the next step in the
definition or program occurs or else Forth will not know how to get back on track or continue on the track on
which it was headed! For more information on the return stack, see:
https://www.complang.tuwien.ac.at/forth/gforth/Docs-html/Return-Stack-Tutorial.html
STACK TYPES - FLOATING POINT - EXAMPLE
1e2 Put the value of 100. on the floating point stack as a floating point number.
f.s Display the floating point stack without destroying it (<1> 1.000000000000E2 in this example).
f. Display the value of the TOS floating point stack item (100. in this example).
fs. Display the contents of the TOS floating point stack item, destroying the item (1.00000000000000E2
in this example).
Strings - Array - Defined Words
STRINGS - ARRAY - DEFINED WORDS
: str! 2 * CELLS + 2! ; Define a string store word. ( addr1 u1 addr2 u2 -- )
: str@ 2 * CELLS + 2@ ; Define a string fetch word. ( addr1 u1 -- addr2 u2 )
: str. str@ TYPE ; Define a string display word. ( addr u -- )
Usage str!: on stack is str address addr1 and count u1 and array address addr2 and index u2 --
Usage str@: on stack is array address addr1 and index u1 -- string address addr2 and count u2
Usage str.: on stack is array address addr and index u -- empty
Usage array index becomes 0, 2, 4, etc. when you type 0, 1, 2, etc., which is provided by the 2 * in the
definitions.
STRINGS - ARRAY - DEFINED WORDS - EXAMPLE
: str! 2 * CELLS + 2! ; Define a string store word.
: str@ 2 * CELLS + 2@ ; Define a string fetch word.
: str. str@ type ; Define a string display word.
VARIABLE str 2 CELLS ALLOT Create a variable with room for 1 string-count pair.
CREATE array 6 CELLS ALLOT Create an array with room for 3 string-count pairs.
S" string1" str PLACE Place the "string1" string into the str variable.
str COUNT array 0 str! Store the string variable into the array 0 position.
S" string2" array 1 str! Store the "string2" string constant into the array 1 position.
S" string3" array 2 str! Store the "string3" string constant into the array 2 position.
array 0 str@ String fetch the string address and count at array position 0.
array 1 str@ String fetch the string address and count at array position 1.
array 2 str@ String fetch the string address and count at array position 2.
array 0 str. CR String display the string contents at array position 0.
array 1 str. CR String display the string contents at array position 1.
array 2 str. CR String display the string contents at array position 2.
This is a 6-cell array where each of the 3 pairs of cells holds the string variable's and string constant's address
and count stored by the str! word.
To retrieve the strings of character codes, you index into the array of pairs with 0, 1, 2, and, using the str@
word, retrieve the address and count.
To display the strings of character codes, you index into the array of pairs with 0, 1, 2, and, using the str. word,
display the string of character codes contents.
STRINGS - ARRAY - DEFINED WORDS - EXAMPLE - MY STRING DEFINITIONS
With address-count pair strings of character codes.
: str! 2 * cells + 2! ; Define a string store word.
: str@ 2 * cells + 2@ ; Define string fetch word.
: str. str@ type ; Define string display word.
variable str 2 cells allot Create a variable with room for 1 string-count pair.
create array 4 cells allot Create an array with room for 2 string-count pairs.
s" string1" str place Place the "string1" string into the str variable.
str count array 0 str! Store the variable into the array 0 position.
s" string2" array 1 str! Store the "string2" string constant into the array 1 position.
array 0 str. cr String display the string contents at array position 0.
array 1 str. cr String display the string contents at array position 1.
Usage str!: on stack is str address addr1 and count u1 and array address addr2 and index u2 --
Usage str@: on stack is array address addr1 and index u1 -- string address addr2 and count u2
Usage array index goes 0 2 4 6 etc., which is provided by the 2 * in the definitions
Strings - Defined Words
STRINGS - DEFINED WORDS - EXAMPLE - UPPER FOR STRINGS (INVENTED BY FRANK)
: upper 0 DO DUP I + DUP C@ TOUPPER SWAP C! LOOP DROP ; Define the upper word that will convert lower case
characters to upper case.
S" example" 2DUP upper Use it to change the specified string of character
codes to upper case.
S" example" 2DUP upper TYPE Use it to change the specified string of character
codes to upper case and display it.
The 2DUP is necessary since the TOS was consumed and needed to be there for upper and TYPE.
Strings - Fun With Strings
STRINGS - FUN WITH STRINGS - EXAMPLE
VARIABLE test1 Create the test1 variable.
VARIABLE test2 Create the test2 variable.
S" example" test1 PLACE Store the example string of character codes in the test2 variable.
test1 DUP Put the address of the string of character codes in the test1 variable on the stack
and duplicate it, putting the duplicate on the top of the stack (TOS).
COUNT Get the count of the TOS item and put the count on TOS.
1+ Add 1 to the TOS item and put the result on TOS.
SWAP DROP Swap the TOS item with the NOS item and drop the TOS item off the stack,
leaving the address of the string of character codes in the test1 variable and its
count plus 1 on the stack.
test2 SWAP Put the address of the string of character codes in the test2 array on TOS and swap
it with the test1 count plus 1.
CMOVE Use the source address, destination address, and string of character codes length
that are now on the stack to copy the "example" string of character codes from the
test1 variable to the test2 variable.
test2 COUNT TYPE Display the contents of the test2 variable.
The CMOVE word copies the "example" string of character codes from the "test1" variable to the "test2"
variable, expecting the source address, destination address, and string of character codes length to be on the
stack, where that 1+ jumps over the count byte that is stored at the start of each variable, and that DUP SWAP
DROP SWAP bit of code leaves the correct addresses in the correct position for the CMOVE word to do its
thing.
Strings - Having 2 Stack Values
STRINGS - HAVING 2 STACK VALUES - EXPLANATION
The DUP and SWAP and OVER and ROT and NIP and TUCK words all have the 2-value counterparts of
2DUP and 2SWAP and 2OVER and 2ROT and 2NIP and 2TUCK, that are meant largely for working with
strings of character codes, files, etc., which place 2 values on the stack.
There are also double precision numbers that occur as 2 values on the stack that use those 2-value words and
that have other d-operators:
D. and D+ and D- and DNEGATE and DMAX and DMIN and DABS
There are also single precision converters that leave 2 values on the stack and that use those 2-value words:
double precision to single precision (D>S) and single precision to double precision (S>D)
Strings - Spaces
STRINGS - SPACES
SPACE The SPACE word inserts one space.
SPACES The SPACES word takes the TOS number off of the stack and uses it to determine how many
spaces to insert.
n SPACES An n (a number) followed by the SPACES word puts the specified number onto the stack and uses
it to determine the number of spaces to insert.
STRINGS - SPACES - EXAMPLE
." test" SPACE ." test" Insert 1 space between two test strings of character codes.
." test" SPACE SPACE SPACE SPACE SPACE SPACE ." test" Insert 6 spaces between two test strings of character codes.
." test" 6 spaces ." test" Insert 6 spaces between two test strings of character codes.
Strings - Types
STRINGS - TYPES
." example" • Parses the string of character codes.
• Displays the string of character codes immediately if it's not in a definition.
• Displays the string of character codes on execution of the word if it's in a
definition.
.( example) • Parses the string of character codes.
• Displays the string of character codes immediately if it's not in a definition.
• Displays the string of character codes immediately if it's in a definition.
• Does not display the string of character codes on execution of the word if it's in a
definition.
S" example" • Parses the string of character codes.
• Puts the string of character codes starting address and length on the stack as 2
values, making it a constant.
• Allocates the string constant in Gforth, meaning it stores the string constant's
address and length and prevents it from being overwritten (by creating more of
them, for instance), unlike some Forth systems.
• Displays the string of character codes immediately if it's not in a definition.
• Does not display the string of character codes on execution of the word if it's in a
definition, requiring the definition name and the TYPE word to display the string
of character codes.
• Note: 2-value-stack words like 2DUP 2SWAP 2DROP can be used to manipulate
the 2 values, and the word TYPE takes the 2 values from TOS, grabs the whole
length of the string of character codes from its address, and displays it.
C" example" • Parses the string of character codes.
• Puts the string of character codes length on the stack.
• Displays the string of character codes on execution of the word if it's in a
definition. This counted string of character codes MUST be compiled into a
definition.
• A string of character codes created with the s-quote (S") word is a constant since it puts its value and
length directly on the stack (without you needing to execute the COUNT word to put it there).
• A string variable may be assigned a string constant value with the PLACE word. The variable name
can then be used to put its address on the stack, and the COUNT word can be used to put its value on
the stack.
• The starting address of a string of character codes is where it's stored in memory, and the length of a
string of character codes is the number of characters it uses.
• For more information on string constants, see: https://www.complang.tuwien.ac.at/forth/gforth/Docs-
html/Characters-and-Strings-Tutorial.html#Characters-and-Strings-Tutorial
STRINGS - TYPES - EXAMPLE 1
." hello" Create the hello string of character codes and display its value.
: example ." hello" ; Create the example word with the hello string of character codes as its value and display
its value.
example Execute the example word to display its value.
STRINGS - TYPES - EXAMPLE 2
.( hello) Create the hello string of character codes and display its value.
: example .( hello) ; Create the example word with the hello string of character codes as its value and display
its value.
example Execute the example word. Note that this won't display the string of character codes.
STRINGS - TYPES - EXAMPLE 3
S" hello" Create the hello string of character codes.
: example S" hello" ; Create the example word with the hello string of character codes as its value.
example TYPE Execute the example word and the TYPE word to display its value.
STRINGS - TYPES - EXAMPLE 4
: example C" hello" ; Create the example word with the hello string of character codes as its value.
example Execute the example word to display its value.
Unicode Characters - Displaying
UNICODE CHARACTERS - DISPLAYING - EXAMPLE
9786 XEMIT ☺ Display a white smiling (happy) face using decimal numeric code.
HEX 263a XEMIT ☺ Display a white smiling (happy) face using hexadecimal numeric code.
9787 XEMIT ☻ Display a black smiling (happy) face using decimal numeric code.
HEX 263b XEMIT ☻ Display a black smiling (happy) face using hexadecimal numeric code.
9785 XEMIT ☹ Display a white frowning (sad) face using decimal numeric code.
HEX 2639 XEMIT ☹ Display a white frowning (sad) face using hexadecimal numeric code.
Note: You can also create these by pressing Ctrl + Shift + u followed by the hexadecimal numeric code
(example: 263a) followed by the space key.
See also: Unicode: http://www.unicode.org/
Values
VALUES
A VALUE is a "hybrid" in as much as it's like a constant that places its contents directly on the stack, but like a
variable that can have its contents reassigned with the TO word.
See also: https://www.complang.tuwien.ac.at/forth/gforth/Docs-html/Values.html
Values - ASCII
VALUES - ASCII
'code1 VALUE xxx Create a named value with a ticked ASCII character code, the VALUE word, and a name.
xxx EMIT Place the value of the named VALUE on TOS with the VALUE's name and then fetch and
display it with the EMIT word.
xxx . Place the value of the named VALUE on TOS with the VALUE's name and then fetch and
display its ASCII character code with the dot (.) word.
'code2 TO xxx Change the value of the named value to the new specified value with a ticked ASCII
character code, the TO word, and the value's name
xxx EMIT Place the value of the named VALUE on TOS with the VALUE's name and then fetch and
displayit with the EMIT word.
xxx . Place the value of the named VALUE on TOS with the VALUE's name and then fetch and
display its ASCII character code with the dot (.) word.
VALUES - ASCII - EXAMPLE
'a VALUE xxx Create the xxx value with a value of 'a.
xxx EMIT Place the value of the xxx VALUE on TOS and then fetch and display it.
xxx . Place the value of the xxx VALUE on TOS and then fetch and display its ASCII character
code.
'b TO xxx Change the value of the xxx value to 'b.
xxx EMIT Place the value of the xxx VALUE on TOS and then fetch and display it.
xxx . Place the value of the xxx VALUE on TOS and then fetch and display its ASCII character
code.
Values - Number
VALUES - NUMBER
n VALUE xxx Create a named value with a number, the VALUE word, and a name.
xxx . Place the value of the named VALUE on TOS with the VALUE's name and then fetch and
displayit with the dot (.) word.
n TO xxx Change the value of the named value to the new specified value with a number, the TO word,
and the value's name
xxx . Place the value of the named VALUE on TOS with the VALUE's name and then fetch and
displayit with the dot (.) word.
VALUES - NUMBER - EXAMPLE
2 VALUE xxx Create the xxx value with a value of 2.
xxx . Place the value of the xxx VALUE on TOS and then fetch and display it.
4 TO xxx Change the value of the xxx value to 4.
xxx . Place the value of the xxx VALUE on TOS and then fetch and display it.
Values - String
VALUES - STRING
str1 VALUE xxx Create a named value with a string, the VALUE word, and a name.
xxx TYPE Place the value of the named VALUE on TOS with the VALUE's name and then fetch and
displayit with the TYPE word.
str2 TO xxx Change the value of the named value to the new specified value with a string, the TO word,
and the value's name
xxx TYPE Place the value of the named VALUE on TOS with the VALUE's name and then fetch and
displayit with the TYPE word.
VALUES - STRING - EXAMPLE
S" hello" VALUE xxx Create the xxx value with a value of hello.
xxx TYPE Place the value of the xxx VALUE on TOS and then fetch and display it.
S" world" TO xxx Change the value of the xxx value to world.
xxx TYPE Place the value of the xxx VALUE on TOS and then fetch and display it.
Values - Unicode
VALUES - UNICODE - METHOD 1
u1 VALUE xxx Create a named value with a decimal numeric code, the VALUE word, and a name.
xxx XEMIT Place the value of the named VALUE on TOS with the VALUE's name and then fetch and
displayit with the XEMIT word.
xxx . Place the value of the named VALUE on TOS with the VALUE's name and then fetch and
display its decimal numeric code with the dot (.) word.
u2 TO xxx Change the value of the named value to the new specified value with a decimal numeric code,
the TO word, and the value's name
xxx XEMIT Place the value of the named VALUE on TOS with the VALUE's name and then fetch and
displayit with the XEMIT word.
xxx . Place the value of the named VALUE on TOS with the VALUE's name and then fetch and
display its decimal numeric code with the dot (.) word.
VALUES - UNICODE - METHOD 1 - EXAMPLE
9786 VALUE xxx Create the xxx value with a value of 9786.
xxx XEMIT Place the value of the xxx VALUE on TOS and then fetch and display it.
xxx . Place the value of the xxx VALUE on TOS and then fetch and display its decimal numeric
code.
9787 TO xxx Change the value of the xxx value to 9787.
xxx XEMIT Place the value of the xxx VALUE on TOS and then fetch and display it.
xxx . Place the value of the xxx VALUE on TOS and then fetch and display its decimal numeric
code.
VALUES - UNICODE - METHOD 2
HEX Put Forth into base 16 (hexadecimal) mode with the HEX word.
u1 VALUE xxx Create a named value with a hexadecimal numeric code, the VALUE (u–)
word, and a name.
xxx XEMIT Place the value of the named VALUE on TOS with the VALUE's name (u–)
and then fetch and displayit with the XEMIT word.
xxx . Place the value of the named VALUE on TOS with the VALUE's name
and then fetch and display its hexadecimal numeric code with the dot (.)
word.
u2 TO xxx Change the value of the named value to the new specified value with a (u–)
hexadecimal numeric code, the TO word, and the value's name
xxx XEMIT Place the value of the named VALUE on TOS with the VALUE's name (u–)
and then fetch and displayit with the XEMIT word.
xxx . Place the value of the named VALUE on TOS with the VALUE's name
and then fetch and display its hexadecimal numeric code with the dot (.)
word.
DECIMAL Put Forth back into base 10 (decimal) mode with the DECIMAL word.
VALUES - UNICODE - METHOD 2 - EXAMPLE
HEX Put Forth into base 16 (hexadecimal) mode.
263a VALUE xxx Create the xxx value with a value of 263a.
xxx XEMIT Place the value of the xxx VALUE on TOS and then fetch and display it.
xxx . Place the value of the xxx VALUE on TOS and then fetch and display its hexadecimal
numeric code.
263b TO xxx Change the value of the xxx value to 263b.
xxx XEMIT Place the value of the xxx VALUE on TOS and then fetch and display it.
xxx . Place the value of the xxx VALUE on TOS and then fetch and display its hexadecimal
numeric code.
DECIMAL Put Forth back into base 10 (decimal) mode.
Variables
VARIABLES - EXPLANATION
Variables are used for values that may need to change at any time.
Variables - 2variables
VARIABLES - 2VARIABLES
2VARIABLE xxx Create a 2-CELLS variable with the 2VARIABLE word and a name.
dpsi xxx 2! Store a double precision signed integer value into the 2VARIABLE with the integer, the
2VARIABLE name, and the two-store (2!) word.
dpui xxx 2! Or store a double precision unsigned integer value into the 2VARIABLE with the integer,
the 2VARIABLE name, and the two-store (2!) word.
str xxx 2! Or store a string constant value into the 2VARIABLE with the string constant, the
2VARIABLE name, and the two-store (2!) word.
xxx 2@ D. Fetch the contents (the double precision signed integer) of the 2VARIABLE and display
them with the 2VARIABLE name, the two-fetch (2@) word, and the d-dot (D.) word.
xxx 2@ D. Or fetch the contents (the double precision unsigned integer) of the 2VARIABLE and
display them with the 2VARIABLE name, the two-fetch (2@) word, and the d-dot (D.)
word.
xxx 2@ TYPE Or fetch the contents (a string of character codes) of the specified 2VARIABLE and display
them with the 2VARIABLE name, the two-fetch (2@) word, and the TYPE word.
VARIABLES - 2VARIABLES - EXAMPLE 1
2VARIABLE xxx Create the xxx 2VARIABLE.
-65535 S>D xxx 2! Store the -65535 double precision signed integer in the xxx 2VARIABLE.
xxx 2@ D. Display the -65535 stored in the two CELLS of the xxx 2VARIABLE.
VARIABLES - 2VARIABLES - EXAMPLE 2
2VARIABLE xxx Create the xxx 2VARIABLE.
65535 S>D xxx 2! Store the 65535 double precision unsigned integer in the xxx 2VARIABLE.
xxx 2@ D. Display the 65535 stored in the two CELLS of the xxx 2VARIABLE.
VARIABLES - 2VARIABLES - EXAMPLE 3
2VARIABLE xxx Create the xxx 2VARIABLE.
S" example" xxx 2! Store the example string constant in the xxx 2VARIABLE.
xxx 2@ TYPE Display the string of character codes stored in the two CELLS of the xxx 2VARIABLE.
Variables - ASCII
VARIABLES - ASCII
VARIABLE xxx Create a VARIABLE with the VARIABLE word and a name.
'code xxx C! Store a ticked ASCII character code in the VARIABLE with the code, the VARIABLE
name, and the c-store (C!) word.
xxx C@ XEMIT Fetch the contents of the VARIABLE with the VARIABLE name and the c-fetch (C@)
word, and display them with the XEMIT word.
xxx C@ . Fetch the contents of the VARIABLE with the VARIABLE name and the c-fetch (C@)
word, and display them with the dot (.) word.
VARIABLES - ASCII
VARIABLE xxx Create the xxx VARIABLE.
'a xxx C! Store the ticked ASCII character code in the xxx VARIABLE.
xxx C@ XEMIT Fetch the ASCII character code stored in the xxx VARIABLE and display the a character.
xxx C@ . Fetch the ASCII character code stored in the xxx VARIABLE and display the code.
Variables - Fvariables
VARIABLES - FVARIABLES
FVARIABLE xxx Create an FVARIABLE with the FVARIABLE word and a name.
fpn xxx F! Store a floating point number in the FVARIABLE with the number, the FVARIABLE
name, and the f-store (F!) word.
xxx F@ F. Fetch the contents of the FVARIABLE with the FVARIABLE name and the f-fetch (F@)
word, and display them with the f-dot (F.) word.
VARIABLES - FVARIABLES
FVARIABLE xxx Create the xxx FVARIABLE.
1e2 xxx F! Store the 1e2 floating point number in the xxx FVARIABLE.
xxx F@ F. Fetch the 100. stored in the xxx FVARIABLE and display it.
Variables - Number
VARIABLES - NUMBER
VARIABLE xxx Create a variable with the VARIABLE word and a name. ( -- )
xxx Execute the variable with its name to return its address ( -- addr )
xxx . Execute the variable with its name to return its address and use the ( addr – )
dot (.) word to display it. from the . point of
view
n1 xxx ! Store a number in the variable's memory address with the number ( n addr -- )
and the store (!) word.
xxx @ Fetch the number from the variable's memory address and put it on ( addr -- n )
the TOS with the variable's name and the fetch (@) word.
xxx @ . Fetch the number from the variable's memory address with the (n–)
variable name and the fetch (@) word and put it on the TOS and from the . point of
remove it from the TOS and display it (followed by one space) with view
the dot (.) word.
xxx ? Fetch and display the number (followed by one space) from the ( addr -- )
variable's memory address in one step with the variable name and
the question (?) word.
n2 xxx ! Change/replace the value of the variable and store the new value into ( n addr – )
its memory address with a number and the store (!) word the same from the ! point of
way you originally stored it. view
+! The plus-store (+!) word takes the TOS or specified number, adds it ( n addr -- )
to the value at the specified address and saves that sum as the new
value for that address.
n xxx +! Change the value of the variable by adding a number to it with the (n addr – )
number, the variable name, and the plus-store (+!) word.
VARIABLES - NUMBER - EXAMPLE 1
6 xxx ! Gives the xxx variable the value of 6.
xxx @ . Fetch the 6 from the xxx variable and display it.
xxx . Fetch the address of the xxx variable and display it.
VARIABLES - NUMBER - EXAMPLE 2
6 xxx +! Take the 6 off the stack, add it to the value at the xxx address, and save that sum back to the xxx
address.
Variables - String
VARIABLES - STRING
VARIABLE xxx Create a variable with the VARIABLE word and a name. (–)
xxx Execute the variable with its name to return its address. ( -- addr )
xxx . Execute the variable with its name to return its address and ( addr -- addr )
use the dot (.) word to display its contents.
str1 xxx PLACE Store a string constant value's address and COUNT in the ( addr -- addr )
variable's memory address with the string constant, the
variable name, and the PLACE word.
xxx i CHARS + C@ . Fetch and display the value stored in the variable's first byte ( addr -- addr )
block address with the variable name, the index, the
CHARS word, the plus (+) word, the c-fetch (C@) word,
and the dot (.) word. Returns the COUNT at the specified
byte.
xxx i CHARS + C@ EMIT Fetch and display the specified character of the string of ( addr -- addr )
character codes stored in the variable's specified byte block
address with the variable name, the index, the CHARS
word, the plus (+) word, the c-fetch (C@) word, and the
EMIT word. Returns the specified character of the string of
character codes.
xxx COUNT TYPE Display the contents of the variable with the variable name, ( addr -- addr )
the COUNT word, and the TYPE word.
str2 xxx PLACE Change/replace the value of the contents of the variable and ( addr -- addr )
store the new value into its memory address with a new
string constant, the variable name, and the PLACE word.
xxx COUNT TYPE Display the contents of the variable with the variable name, ( addr -- addr )
the COUNT word, and the TYPE word.
VARIABLES - STRING - EXAMPLE
VARIABLE xxx Create the xxx variable.
xxx Execute the xxx variable.
xxx . Execute the xxx variable and display its contents.
S" hello" xxx PLACE Store the hello string constant value's address and COUNT in the xxx variable's
memory address.
xxx 1 CHARS - C@ . Fetch and display the value stored in the variable's previous byte block address
with the variable name, the index, the CHARS word, the minus (-) word, the c-
fetch (C@) word, and the dot (.) word. Returns zero, as we've fallen backwards
off of the string of character codes into the nothingness that precedes it. This
example is here just to demonstrate attempting to fetch using an incorrect index.
xxx 0 CHARS + C@ . Fetch and display the COUNT stored in the xxx variable's first byte block
address. Returns the COUNT at the first byte.
xxx 1 CHARS + C@ EMIT Fetch and display the first character of the string of character codes stored in the
xxx variable's second byte block address. Returns the first character of the string
of character codes. 2 CHARS + would return the next character, etc.
xxx COUNT TYPE Display the contents of the xxx variable (the string of character codes).
S" world" xxx PLACE Replace the hello string of character codes in the xxx variable with the world
string constant and store the new value into its memory address.
xxx COUNT TYPE Display the contents of the xxx variable (the string of character codes).
Variables - Unicode
VARIABLES - UNICODE
HEX Put Forth into base 16 (hexadecimal) mode with the HEX word.
VARIABLE xxx Create a variable with the VARIABLE word and a name.
xxx Execute the variable with its name to return its address.
xxx . Execute the variable with its name to return its address and use the dot (.) word to display the
address.
code1 xxx ! Store some hexadecimal code in the variable's memory address with the code, the variable
name, and the store (!) word.
xxx @ . Display the hexadecimal code stored at the variable's memory address with the variable's
name, the fetch (@) word, and the dot (.) word.
xxx ? Display the hexadecimal code stored at the variable's memory address with the variable's
name and the question (?) word.
xxx @ XEMIT Display the Unicode character stored at the variable's memory address with the variable's
name, the fetch (@) word, and the XEMIT word.
code2 xxx ! Change/replace the value of the variable and store a new value into its memory address with
the code, the variable's name, and the store (!) word, the same way you originally stored it.
DECIMAL Put Forth back into base 10 (decimal) mode with the DECIMAL word.
VARIABLES - UNICODE - EXAMPLE
HEX Put Forth into base 16 (hexadecimal) mode.
VARIABLE xxx Create the xxx variable.
263a xxx ! Store the 263a hexadecimal code in the xxx variable's memory address.
xxx @ . Display the hexadecimal code stored in the xxx variable's memory address.
xxx ? Display the hexadecimal code stored in the xxx variable's memory address.
xxx @ XEMIT Display the Unicode character stored in the xxx variable's memory address.
263b xxx ! Replace the 263a hexadecimal code in the xxx variable's memory address with 263b.
xxx @ . Display the hexadecimal code stored in the xxx variable's memory address.
xxx ? Display the hexadecimal code stored in the xxx variable's memory address.
xxx XEMIT Display the Unicode character stored in the xxx variable's memory address.
DECIMAL Put Forth back into base 10 (decimal) mode.
Vocabulary
VOCABULARY
VOCABULARY xxx Create your own dictionary/vocabulary with the VOCABULARY word and a
name. You can have multiple vocabularies to organize the words you write.
ALSO xxx Add a dictionary/vocabulary to the search order with the ALSO word and a
dictionary name.
xxx DEFINITIONS Or add a dictionary/vocabulary to the search order and make it the compilation
word list (changing the context to it) with a name and the DEFINITIONS word.
PREVIOUS DEFINITIONS Return to the Forth dictionary/vocabulary, making it the compilation word list
(changing the context to it) with the PREVIOUS word and the DEFINITIONS
word.
WORDS Display a list of the words in the current vocabulary with the WORDS word.
CONTEXT FORTH Exit your vocabulary and return to the main Forth vocabulary with the
CONTEXT word and the FORTH word.
CONTEXT xxx Exit the main Forth vocabulary and return to your vocabulary with the
CONTEXT word and the name of your vocabulary.
ORDER Display the path the interpreter/executor will use to search for a word to execute it
with the ORDER word.
VOCABULARY - EXAMPLE
VOCABULARY self Create the new word list named self. ( name – )
Words
WORDS
WORDS Display all the words defined in the current CONTEXT with the WORDS word. (–)
WORDS - EXAMPLE 1
WORDS Display all the words in the current CONTEXT.
WORDS - EXAMPLE 2
: xxx S" hello world " ; Create the xxx word, defining its value with the hello world string constant.
xxx TYPE Execute the xxx word and display its value.
Further Reading
• ANS/ISO Forth standard: http://dl.forth.com/sitedocs/dpans94.pdf
• Fizz Buzz: https://skilldrick.github.io/easyforth/
• Forth 20xx: http://www.forth200x.org/
• Forth 2012 standard: http://www.forth200x.org/documents/forth-2012.pdf
• Gforth official website: https://www.gnu.org/software/gforth/
• Gforth home: http://www.complang.tuwien.ac.at/forth/gforth/
• Gforth snapshots: http://www.complang.tuwien.ac.at/forth/gforth/Snapshots/
• Gforth 0.7.3 User Manual: http://www.complang.tuwien.ac.at/forth/gforth/Docs-html/
• Gforth 0.7.9 User Manual: https://bernd-paysan.de/gforth-manual/
• Gforth 0.7.9 notation: https://bernd-paysan.de/gforth-manual/Notation.html#Notation
• Gforth word index: https://www.complang.tuwien.ac.at/forth/gforth/Docs-html/Word-Index.html
• Linux Goodies: http://www.linuxgoodies.com/review_gforth.html
• Unicode: http://www.unicode.org/
Version
This document is version 87 and was saved on 10-29-16.
To check for a more recent version, visit the https://mostlylinux.wordpress.com/software/gforth-cheat-sheet/
page.