|
Token Code
Index Glossary of I/O commands
Glossary of 'Avise2.4' general commands:
mit Ergänzungen von H.H. (updated 22 Apr 2002) In the versions for the AT90S4433 some functions are missing due to lack of code memory. Enter WORDS to get a list of functions of your specific version. Differences between different hardware versions are outlined where necessary $( -- ) token code = DD
Switches number interpreter and console output to HEXADECIMAL format (is
default after INIT and ABORT).
%( -- ) token code = DC
Switches number interpreter and console output to DECIMAL format.
Comment on validity range of $ and %: During compiling state, $ and
% are compiled and further more immediately executed. Immediate execution
is necessary in this case to convert number strings correctly into their
binary value. Compilation of the $ or % token is necessary to get correct
number output at runtime.
*( x1 x2 -- x3 ) token code =B4 Unsigned multiplication 16x16bit to 16 bit: x3 = x1 * x2
Wenn man ein größeres Ergebnis erwartet als es einer 16-Bit-Zahl
entspricht, muss *D verwendet werden.
*/( x1 x2 x3 -- xQL xQH ) token code =B7 (not available for AT90S4433)
Combined scaling function: Unsigned multiplication x1*x2 (16x16bit) into
a 32 bit intermediate result- this is divided by 16 bit value x3 to get the
resulting quotient xQH xQL in 32 bit format (note:this is differing from
standard Forth behaviour).
Ein wichtiger Befehl, wenn man Messwerte skalieren möchte: A7 AIN 5 400 */ . . bzw. 7 AIN 5 400 */ . . Mit A7 AIN wird ein Analog-Messwert über PORT A,7 bestimmt. Da dem Maximalwert 5 V der AD-Wandler-Wert 1024 dez = 400 hex entspricht, wird mit 5/1024 multipliziert, um die gemessenen "Millivolt" zu erhalten. Da der Prozessor aber keine Brüche kennt, muss erst mit 5 multipliziert und dann durch 1024 dividiert werden. Auf dem Stack wird dann 0 liegen, darunter der gemessene (ganzzahlige) Wert in Millivolt.
*/MOD( x1 x2 x3 -- xR xQL xQH ) token code =B8 (not available for AT90S4433)
Combined scaling function: Unsigned multiplication x1*x2 (16x16bit) into
a 32 bit intermediate result- this is divided by 16 bit value x3 to get the
resulting quotient xQH xQL in 32 bit format (note:this is differing from
standard Forth behaviour) and the remainder of the division xR in 16 bit
format.
+( x1 x2 -- x3 ) token code = A4
16 bit addition: x3 = x1 + x2
-( x1 x2 -- x3 ) token code = A7
16 bit subtraction: x3 = x1 - x2
-ROT(x1 x2 x3 -- x3 x1 x2) token code = A2
Rotates the top of stack down to the 3rd stack position.
.( x -- ) token code = DA Transmits the top of stack data via serial interface in its ASCII representation and acitve number base (default=hex, may be set to decimal) plus one leading space. See EMIT, too.
."( -- ;<text> ) - I - token code = DB (not available for AT90S4433)
Compile time behaviour: First compiles the DOSTR token. Next, it compiles
the following ASCII text until next " quotation.
.S( -- ) token code = F2 Simple debugging or system monitoring tool. Emits (non destructive) the contents of data stack and variables V0 to V7 (AT90S4433 versions) rsp. the first 8 user defined variables in order of definition (other versions with larger SRAM) via serial interface. This function is called by the single step debugger, too. But when .S is called out of the debugger, execution is not halted.
/( x1 x2 -- x3 ) token code =B5
Unsigned division 16/16bit to 16 bit x3 = x1/ x2
Ø=( x -- TRUE|FALSE ) token code = BB Returns TRUE on the stack, if x is equal to zero. Can be used as inverter for boolean flags.
:( -- ; <name> ) - I - token code = E4
The Colon command does start the definition of a new user word (function,
command) with the name, wich is picked from the terminal input next after
the colon separated by spaces. The colon command does switch 'Avise' into
the compiling state. I.e. all words entered beween the name word and the
final semicolon will not be executed but compiled into the new word. The
length of the name must be limitied to 12 characters or less. Number strings
and names of kernel words must be avoided. Earlier user functions can be
overridden.
;( -- ) - C - I - token code = E6 The semicolon command does finish a user compiled word. Now the new word is linked into the actual symbol table of ''Avise'' and the engine returns into interpreting state.
<( x1 x2 -- TRUE|FALSE ) token code = BF
Returns TRUE on the stack, if x1 is smaller than x2, else FALSE.
<=( x1 x2 -- TRUE|FALSE ) token code = C1
Returns TRUE on the stack, if x1 is smaller than or equal to x2, else
FALSE.
<>( x1x2 -- TRUE|FALSE ) token code = BA Returns TRUE on the stack, if x1 is not equal to x2.
=( x1 x2 -- TRUE|FALSE ) token code = B9 Returns TRUE on the stack, if x1 is equal to x2.
>( x1 x2 -- TRUE|FALSE ) token code = BC
Returns TRUE on the stack, if x1 is greater than x2.
>=( x1 x2 -- TRUE|FALSE ) token code = BE
Returns TRUE on the stack, ifx1 is greater than or equal to x2.
1+( x -- x+1 ) token code = A5 Increase top of stack by one. Same effect as 1<SPACE>+, but more compact and faster. Cyclic behaviour.
1-( x -- x-1 ) token code = A8 Decrease top of stack by one. Same effect as 1<SPACE>-, but more compact and faster. Cyclic behaviour.
ABORTCompiling state: ( -- ) token code = CB
The ABORT token is compiled into the function beeing defined. There it will
be executed at runtime.
ABS(x -- |x| ) token code = AA Interpret x as signed number and return its absolute value. I.e.: if bit 15 of x is set, the two's complement of x is returned.
AND(x1 x2 -- bx3 ) token code = B0 Bitwise 16 bit logical AND.
AUTOEXE( b -- ) token code = EB
Puts the numeric code b of any token into an autostarting function, which
is automatically executed after INIT or hardware reset, before control of
'Avise' is handled to the operator terminal. You can leave the AUTOEXE function
at every time by sending a tilde character ~ =0xFE via serial interface.
This is catched directly in the serial interrupt handler at very low system
level and will immediately throw 'Avise' to its error handler. Putting FF
AUTOEXE <RETURN> will disable the autofunction at system start and
instantly give access to the operator terminal.
BEGIN( -- ) - C - I - token code = D1
Mark the beginning of an uncounted "open" loop
BREAK( -- ) - C - token code = F3 (not available for AT90S4433) Sets a breakpoint into the code of a user programmed function. When the breakpoint is executed, the display of .S is transmitted to the terminal display, then program execution is halted. Program flow will continue, when the TAB byte (0x09) is received via serial interface. By default, breakpoints are generally deactivated. They can be activated (and subsequently deactivated) with the DEBUG command interactively or during program operation.
CALL(not available for AT90S4433) ( addr -- ) token code = C8 Call a user programmed piece of machine code put into the AVR flash memory Introduction of user programs to be called by CALL is performed as follows: 'Avise' kernel is supplied as Intel hex object code. Assemble your own code into the free part of memory (using the ORG assembly directive. Merge the Intel hex files with a plain ASCII text editor: As all records have different address fields, put the new part after the kernel records, except the terminator record, which must stay the last. Use of C or Basic compilers is not recommended, as these tools make complex use of register and SRAM resources and might destroy the memory setup of the calling 'Avise' kernel. Keep in mind, that ''Avise'' internally makes use of all 32 machine registers of the AVR controller. The following registers can be used without loss of data and without the need of restoration: r0, r3, r4, r22, r23, r24, r25, r30, r31. SREG needs not to be saved. NEVER use r2, r5, r6, r7, r16, r17, r20, r21, r28, r29 in your own programs. You must save each register else before use and restore it when you return to the kernel. The register pair XL,XH (r26, r27) is the '''Avise''' data stack pointer. Register pair r18=TOSL and r19=TOSH is used as TOS ("top of stack"). This feature is appropriate to handle data into user functions and vice versa. Example, how the DUP and the W command (write to SRAM) are implemented within 'Avise 2.4':
DUP: st -X,TOSH st -X,TOSL ret WRITE: ; if address lower 0x060 then write single byte ; else write word. mov ZL,TOSL mov ZH,TOSH ;address ld TOSL,X+ ;pop data from stack ld TOSH,X+ tst ZH brne WR10 cpi ZL,0x61 brcs WR20 WR10: std Z+1,TOSH WR20: st Z,TOSL ld TOSL,X+ ;pop data from stack ld TOSH,X+ ret
CARRY?( -- TRUE|FALSE ) token code = AB (not available for AT90S4433)
Reflects if the last executed one of the following functions did cause an
overflow (carry or borrow): + , 1+ , +W , - , 1- , -W. This can be a great
help in 32 bit arithmetics.
DEBUG( TRUE|FALSE -- ) token code = F4 (not available for AT90S4433)
If the stack parameter is "TRUE", i.e. not equal zero, the single step debugger
is started. That means: after any compiled BREAK command, line by line ''Avise''
does put out the system state (details see .S). Then it does halt until the
TAB key on the user terminal is pressed.
DOCompile time: ( -- addr ) - C - I - token code = D3 (not available for AT90S4433 with external EEPROM)
Does put the loopback address on the stack, later consumed by LOOP. Details
not important for user.
DODO( xstart xstop addr -- ) - C - P - token code = FC (not available for AT90S4433 with external EEPROM)
Runtime primitive, which is compiled by DO to perform its runtime actions:
DOELSE( -- ) - C - P - token code = F8
Runtime primitive to perform an absolute unconditional jump to the code address,
which is compiled just following the DOELSE token. DOELSE is not directly applicable to the user. The compiler does insert it to do the runtime action of the word ELSE. It is listed here only for understanding output of SEE.
DOIF( x -- ) - C - P - token code = F9
Runtime primitive to manage a conditional FORWARD jump in the program flow.
DOLIT( -- x ) - C - P - token code = FB Runtime primitive, which puts a compiled data word on the data stack. The data value is compiled directly following the DOLIT token. There are 2 bytes compiled following the DOLIT token. The first one is the high byte of x, the following one is the low byte of x. DOLIT is always compiled in context with input of numbers in compiling state. Internal control operation, not directly user applicable. Listed here only as reference for SEE output.
DOLOOP( -- ) - C - P - token code = FD (not available for AT90S4433 with external EEPROM)
Runtime primitive, which is compiled by LOOP to perform its runtime
actions:
DOSTR( x -- ) - C - P - token code = F6 (not available for AT90S4433 with external EEPROM)
Runtime primitive, which EMITs the following text bytes until NULL byte.
DOUNTIL( x -- ) - C - P - token code = FA
Runtime primitive to manage a conditional BACKWARD jump in the program
flow.
DOVAR( x -- ) - C - P - token code = F7 (available only in versions with external EEPROM except AT90S4433)
Runtime primitive which puts the next two bytes on the data stack - which
represent the address of a variable parameter field .
DROP(x -- ) token code =9D Deletes the top of the stack and pops all stack entries up by one position.
DUP(x -- x x ) token code = 9E Duplicates the top op the stack and pushes all stack entries down by one position.
ELSE
( -- ) - C - I - token code = D0
ENDIF( -- ) - C - I - token code = CF
Does finish a conditional branch structure beginning with IF.
EMIT( b -- ) token code = D8 Transmits the lower byte of TOS as a raw 8 bit data via the serial interface . No check if the data is printable.
EOC( -- ) token code = FE End of Code compiled by ; (semicolon). Same runtime function as EXIT, but has a signalling effect on some internal process. Not directly applicable by user.
EXIT( -- ) - C - token code = CA Finishes the execution of a secondary word and returns to a higher nesting level of program flow. Is implied by ; (semicolon), but can be explicitely used for side-exits within a word definition, too.
FORGET( -- ;<namestring> ) - I - token code = EA Deletes the user-compiled word <namestring> and all words, which are compiled later. Resets the compile memory pointer, accordingly. FORGET may only be called interactively, it must not be compiled into user words!
FREQ Das frühere FREQ Wort zur Erzeugung eines Rechtecksignals im 40 kHz-Bereich ist entfallen. Ersatz lässt sich nach Herrn Schemmert leicht programmieren:
Folgendes funktioniert: Timer1: : 40KHZ1 D5 PBLO 0 4B W 64 4A W 40 4F W 9 4E W ; PBLO schaltet den Port erstmal auf Ausgang Dann wird OCR1A mit hex64=dez 100 beschrieben -- hier Frequenz variierbar Dann wird in TCCR1A die OC1A Leitung auf Toggle bei Compare Match geschaltet Zuletzt wird Timer 1 mit Prescaler = 1 und Clear bei Compare Match gestartet. Entsprechend verhält sich ein neu zu programmierendes Wort FREQ: : FREQ D5 PBLO 0 4B W 4A W 40 4F W 9 4E W ; Es erwartet auf dem Stack einen Teiler b (1 Byte !), der die Frequenz bestimmt nach der Formel: f = 8 000 kHz / (2.b+1) ( 2 wahrscheinlich falsch) b = 64hex = 100dezimal liefert demnach recht genau 40 kHz über PORT D,5. Ersetzt man D5 durch D4, kommt das Signal über PORT D,4. 9 bestimmt u.a. den Vorteiler der Frequenz. Eingestellt ist der Vorteiler 1. Ersetzt man 9 durch A = 10, so setzt man den Vorteiler 8. Dann gilt die Frequenzformel: f = 1 000 kHz / (2.b+1), bei VT 256 (also 9 durch 12 ersetzt): f = 15625 Hz /(2.b+1) Timer2: : 40KHZ2 D7 PBLO 64 43 W 19 45 W ;
Frequenzvarianten können durch Variation des hexadezimalen Wertes 64 erprobt werden. Mit 19 kann man andere Vorteiler einstellen. : FREQ2 D7 PBLO 43 W 19 45 W ; Dieses Wort für den TIMER2 erwartet den Teiler auf dem Stack.64 FREQ2 (64 Hexadezimal) gibt über D7 ein 40 kHz-Signal aus. Mit 6A FREQ2 erhalten Sie ein 38 kHz-Signal für den Infrarot-Entfernungssensor. Bei Timer 1 können Sie auch asymmetrische Wellenformen einstellen: 64 WAVELO C8 WAVE 9 4E W Während sich beiden ersten Funktionen die CPU ohne Programmbelastung selber steuern, benötigt der für WAVE benötigte Interrupt bei der hohen Frequenz erhebliche CPU Zeit. Bei sehr kleinen Vorgaben von WAVELO und WAVE wird auch der UART-Interrupt nicht mehr bedient und das Teil hängt sich gnadenlos auf.
IF Compile time:( -- addr ) - C - I - token code = CE
Does compile a conditional jump to the respective ENDIF or ELSE. Details
are not important for user.
INIT( -- ) token code = CC Unconditional cold start of ''Avise'' will be executed. I.e. a microcontroller reset is forced, all memory and I/O will be reninitalized. If set, an AUTO funciton will be executed before the command interpreter can be reached by the user. See AUTOEXE.
KEY( -- b ) token code = D6
Returns a byte from the input buffer of the serial interface. If the buffer
is empty, KEY does wait until a byte arrives.
KEY?( -- b +TRUE | FALSE ) token code = D7
Checks if data are in the input buffer of the serial interface.
LEAVE( -- ) - C - token code = D5 (not available for AT90S4433 with external EEPROM) Immediately leaves the innermost DO ... LOOP structure and continues execution behind the respective DOLOOP token. Loop parameters are removed from stack. The variable, which holds the actual loop counter, is left unchanged.
LOOP( addr -- ) - C - I - token code = D4 (not available for AT90S4433 with external EEPROM)
Returning point of a DO-LOOP structure: The compiler does substitute the
LOOP token by its runtime primitive DOLOOP and compiles the LEAVE destination
behind DODO. Details are not important for user.
LSHIFT( x n -- x' ) token code = AC Shift left the bits of the 2nd stack entry "x" by "n" positions.
MEM( -- ) - I - token code = EC (not available for AT90S4433 with external EEPROM) Display of the actual values of compile memory pointers in internal and external EEPROM as well as the VAR assignment pointer.
MOD( x1 x2 -- x3 ) token code =B6 Remainder of unsigned division 16/16bit to 16 bit x3 = MOD( x1 / x2)
MS( x -- ) token code = C2
Does trigger an internal countdown with duration of x time steps of ONE
microsecond (Millisekunde?) each. The AVR microcontroller's
timer #0 is used and during this time it
is not available for lowlevel user action. Else no direct action is performed,
program flow is going on after starting the timer. Further evaluation of
timing action see TIME and
WAIT.
NOT( x1 -- x2 ) token code = B3 Every bit of x1 is inverted to its logical complement ("one's complement").
OR( x1 x2 -- x3 ) token code = B1 Bitwise 16 bit logical OR.
OVER( x1 x2 -- x1 x2 x1 ) token code =9F Copy the second stack element over the top of the stack. Now it will be the top of the stack and all other entries are pushed down by one position.
ROL( b n -- b' ) token code = AE (not available for AT90S4433)
Rotate left the bits of the 2nd stack entry "b" by "n" positions. No intermediate
storage in a carry flag.
ROR( b n -- b' ) token code = AF (not available for AT90S4433)
Rotate right the bits of the 2nd stack entry "b" by "n" positions.
ROT(x1 x2 x3 -- x2 x3 bx1 ) token code = A1
Rotate the upper three elements of the data stack. The third element will
be rotated to the top of the stack. The previous two top elements are pushed
down by one position.
ROT4( x1 x2 x3 x4 -- x2 x3 x4 x1 ) token code = A3 (not available for AT90S4433) Rotate the upper four elements of the data stack. The fourth element will be rotated to the top of the stack. The previous three top elements are pushed down by one position. This word is useful for construction of stack operations with word length of more than 8 resp.16 bit.
RSHIFT( x n -- x' ) token code = AD Shift right the bits of the 2nd stack entry "x" by "n" positions.
SEE( -- ; <name>) - I - token code = F1
Simple decompiler for user-compiled words. Emits the content of the word
<name> via serial interface to the terminal display. Differing from
other Forth decompilers, it doesn't list the words by name, but by token
codes. The compiled code is differing from source code - especially in
conditional structures and loops. SEE is not comfortable in any way, but
in case of problems it gives a straight view into the code. Before work with
SEE, call WORDS and print a screenshot to list the token codes in numeric
order. SEE can only be called interactively, it must not be compiled into user words!
SWAP( x1 x2 -- x2 x1 ) token code = A0 Does exchange the upper two data stack entries. (swaps data words, to be distinguished from the AVR machine command "SWAP"!)
SYS( -- ) token code = C6 (not available for AT90S4433) Reset the internal watchdog timer. Sometimes necessary in very long user functions. Can be used as a dummy NOP code, too.
TIME( -- x ) token code = C4 Puts the actual value of timer countdown on the stack. Time scale and start value were set by MS. User can decide what to do with this information. TIMER 0 !
U<( x1 x2 -- TRUE|FALSE ) token code = C0
Returns TRUE on the stack, if x1 is smaller than x2, else FALSE.
U>( x1 x2 -- TRUE|FALSE ) token code = BD (not available for AT90S4433 with external EEPROM)
Returns TRUE on the stack, if x1 is greater than x2.
UNTIL( TRUE|FALSE -- ) - C - I - token code = D2
Finishes a loop structure started with BEGIN. Will be replaced by the compiler
with a DOUNTIL token.
VAR( -- ;<namestring> ) - I - token code = E7 (available only in versions with external EEPROM except AT90S4433)
Immediate function for declaration of variables, which reserves a
parameter field in the CPU SRAM. Variable is initialised with zero value.
Furthermore, updates pointer to empty variable parameter fields. VAR PARAMETER PARAMETER . \ prints the address where the value of the variable is stored 234 PARAMETER W \sets the variable PARAMETER R . \ prints the actual value of the variable
WAIT( -- ) token code = C5 May be used after a MS call to pause execution until the timer countdown is reached. No exit out of this delay is possible except entering the tilde character ~ = 0xFE via serial interface, which will initiate a warm start! timer #0 !
WORDS( -- ) token code = F5
Displays a list of all currently available words (functions, commands) of
'Avise'. Each word name is followed by its token code in hexadecimal
notation.
XOR(x1 x2 -- x3 ) token code = B2 Bitwise 16 bit logical EXCLUSIVE OR.
Z:( -- ; <name> ) - I - token code = E5 (available only in versions with external EEPROM)
The Z: command does start the definition of a new user word (function, command)
with the name, wich is picked from the terminal input next after the "Z:"
string separated by spaces.
\( -- ;<string delimited by backslash or by CR>)- C - I - token code = E9
Opens a comment. The backslash must be separated by spaces from preceeding
and following text. Normally the rest of the line until CR is regarded as
a comment now. Alternatively, a second Backslash (separated by spaces, too)
will finish the comment. In standard Forth systems, normal brackets ( ) are
used to "comment out" parts of code temporarily for test or optimization
purpose. This useful feature is available in ''Avise'' with a set of two
backslashes.
|