Variables

A variable is a named location in memory that can store a number, such as the intermediate result of a calculation, off the stack. For example,


variable x \fbox{$\hookleftarrow$} ok<$,ram>


creates a named storage location, x, which executes by leaving the address of its storage location as TOS:


x \fbox{$\hookleftarrow$} ok<$,ram>f170


We can then fetch from or store to this address as described in the previous section.
FlashForth V3.8

marker -play  ok<$,ram>
variable x  ok<$,ram>
3 x !  ok<$,ram>
x @ . 3  ok<$,ram>
For FlashForth, the dictionary entry, x, is in the Flash memory of the microcontroller but the storage location for the number is in static RAM (in this instance).


FlashForth provides the words ram, flash and eeprom to change the memory context of the storage location. Being able to conveniently handle data spaces in different memory types is a major feature of FlashForth. To make another variable in EEPROM, try


eeprom variable y \fbox{$\hookleftarrow$} ok<$,eeprom>


We can access this new (nonvolatile) variable as we did for the RAM variable x, but y retains its value, even when we turn off and on the power to the microcontroller.

4 y !  ok<$,eeprom>
y @ . 4  ok<$,eeprom>
x @ . 3  ok<$,eeprom>
FlashForth V3.8

y @  ok<$,ram>4 
x @  ok<$,ram>4 0


Peter Jacobs 2013-06-12