CREATE DOES>
CREATE
The word CREATE can be used alone:
CREATE DATAS ( --- addr) 25 c, 32 c, 44 c, 17 c,
The word after CREATE is created in the dictionary, here DATAS. The execution
of the word thus created deposits on the data stack the memory address of the parameter zone. In this example,
we have compiled 4 8-bit values. To recover them, it will be necessary to increment the address stacked with the value
shifting the data to be recovered. In the example of DATAS, to get the value 44, we write:
DATAS 2 + C@ \ empile 44
Specific Flash Forth
With FlashForth, write explicitly to EEPROM when
we usecreate:
: defPIN: ( PORTx mask --- <word> | <word> --- mask port) create , , \ compile PORT and min mask does> dup @ \ push pin mask swap 2+ @ \ push PORT ; \ définition LED.xx flash PORTB $80 defPIN: LED.red PORTB $40 defPIN: LED.yellow PORTB $20 defPIN: LED.green ram
We execute the word flash before using the word defPIN:
DOES>
The word CREATE can be used in a new word creation word...
Associated with DOES>, we can define words that say how a word is created
then executed.
Example, on ARDUINO board, a "pin" is defined by the address of the port to which it is attached and
the position of the bit in this register. We can thus define a word defPin as follows:
\ PORTB 37 constant PORTB \ Port B Data Register 36 constant DDRB \ Port B Data Direction Register 35 constant PINB \ Port B Input Pins : defPin: ( PORTx mask --- <word> | <word> --- mask port) create c, c, \ compile PORT et masque du pin à définir does> dup c@ \ empile masque du pin swap 1+ c@ \ empile PORT du pin ; eeprom \ specific FLASH FORTH PORTB %00000001 defPin: pin19 PORTB %00000010 defPin: pin20 PORTB %00000100 defPin: pin21 PORTB %00001000 defPin: pin22 PORTB %00010000 defPin: pin23 PORTB %00100000 defPin: pin24 PORTB %01000000 defPin: pin25 PORTB %10000000 defPin: pin26
Avec le mot defPin on a créé les huits mots pin19 à
pin26. Chacun de ces mots va ensuite empiler l'adresse du registre
PORTB du port B et le masque binaire qui détermine la position du pin dans ce registre.