In FlashForth, 16-bit numbers are fetched from memory to the stack by the word @
(fetch)
and stored from TOS to memory by the word !
(store).
@
expects an address on the stack and replaces the address by its contents.
!
expects a number (NOS) and an address (TOS) to store it in.
It places the number in the memory location referred to by the address,
consuming both parameters in the process.
Unsigned numbers that represent 8-bit (byte) values can be placed in character-sized cells
of memory using c@
and c!
.
This is convenient for operations with strings of text, but is especially useful
for handling the microcontroller's peripheral devices via their special-function
file registers.
For example, data-latch register for port B digital input-output
is located at address $ff8a
and the corresponding tristate-control register at address $ff93
.
We can set pin RB0 as an output pin by setting the corresponding bit in the
tristate control register to zero.
%11111110 $ff93 c!
ok<$,ram>
and then set the pin to a digital-high value by writing a 1 to the port's latch register
1 $ff8a c!
ok<$,ram>
If we had a light-emitting diode attached to this pin, via a current-limiting resistor,
we should now see it light up as in the companion hardware tutorial[1].
Here is what the gtkterm window contains after turning the LED on and off a couple of times.
FlashForth V3.8 %11111110 $ff93 c! ok<$,ram> 1 $ff8a c! ok<$,ram> 0 $ff8a c! ok<$,ram> 1 $ff8a c! ok<$,ram> 0 $ff8a c! ok<$,ram>FlashForth allows you to very easily play with the hardware.