Working Notes: a commonplace notebook for recording & exploring ideas.
Home. Site Map. Subscribe. More at expLog.
— Kunal
: for new definitionsword defined command: STAR 42 EMIT;CR carriage return; EMIT emit ascii char; SPACES, SPACE tsia0 DO ... LOOPCompiling translates definitions to dictionary formINTERPRET scans input for characters separated by whitespacesEXECUTENUMBER, which stores in temporary location for numbers." (dot-quote) for strings inside definitions
. removes and prints numbers from the stackStack underflow on trying to pop too muchGlossary list of newly created words / meanings+ ( n1 n2 -- sum )+, -, *, /: INCH ;/MOD ( n1 n2 – rem quot )MOD ( n1 n2 – rem )SWAP switches top two stack itemsDUP duplicates it, OVER copies second item to topROT rotates third item to top, DROP drops top item.S non destructive stack print2SWAP, 2DUP, 2OVER, 2DROP
FORGET removes most recent definition of wordMARKER <label> retains current system state
INCLUDE <filename> to grab a fileUSE <filename> sets up a block( ... ) act as comments, everything between () is ignoredLIST lists a disk block, LOAD loads a disk block1 BLOCK copies block 1 of open file into systemBlock division of disk memory with up to 1024 charsBuffer temporary storage area<CONDITION> IF <IF-TRUE> ELSE <IF-FALSE> THEN <ALWAYS EXECUTED>
?CHECK=, <>, 0=, 0>, 0<, <, >
INVERT is the not used after conditionalsOR, AND?DUP
ABORT"
PAGE clear terminal screenABS absolute value, NEGATE, MIN, MAX>R moves value from parameter to return stackR> moves value from return to parameter stackR@ copies top item from return stack to parameter stack*/ ( n1 n2 n3 – n4 ) n1 * n2 / n3 with a double length intermediate result*/MOD similar<LIMIT> <INDEX> DO...LOOP
I copies loop index onto stack; J next outer loop indexU.R unsigned number print, right justifiedDO ... <INC> +LOOP uses a custom increment
ABORT, which also clears all stacksBEGIN ... <flag> UNTILBEGIN ... AGAIN
BEGIN ... <f> WHILE ... REPEAT
LEAVE causes loops to immediately endQUIT removes ok at end of executionNIP drop first item below stack2* arithmetic left shift, 2/ arithmetic right shift., prints stack value as signed numberU. prints it as unsignedUM*, UM/MOD, U< – single length unsigned opsHEX, OCTAL, DECIMAL change basen BASE ! ; Change baseD. print double length number<# #S #> TYPE ;
<# bracket-number#> number-bracket#S “numbers”
HOLD inserts character at current position<# ... #> converts double length unsigned values to strings<# ... ROT SIGN #> double length signed value etc. etc.M+ double length + single lengthSM/REM d1 / n1, returning n2 and n3FM/MOD, M*, M*/VARIABLE DATE, creating variables;
12 DATE ! ! == storeDATE @ @ == fetch onto stackDATE ? == DATE @ .+! increment stored value<VALUE> CONSTANT <NAME>
2VARIABLE, 2CONSTANT, 2!, 2@VARIABLE <name> <x> CELLS ALLOT
<val> <name> <index> CELLS + <ops>FILL (addr n char -- ) fills n bytesERASE (addr n -- ) zeroes out n bytesaddr count DUMP to print out arraysC! ( char addr - ), C@ ( addr - )CREATE name <value1> , <value2> , <value3> ... ,
CREATE Puts a new name in the dictionary, takes a number from the stack and puts it into the arrayC, for creating byte arrays' Identifies location in memory from dictionary, returns execution tokenEXECUTE executes token on stackDUMP shows raw contents' prefix, eg. 'aloha['] goes to the next word in the definition>BODY gets beginning of data fieldEXIT returns execution to next higher level definition, return from subroutineQUIT is the outermost loop, INTERPRET s and prints oks.CP points to the next cell in dictionaryHERE puts CP on the stack, can be used to estimate size of stackSP provides address of top stack locationS0 contains address of cell below the empty stackTIB, #TIB, BASE, H, >INUSEREMIT ASCII re on the stack and prints itTYPE prints entire string given starting address in memory