fignition‎ > ‎Documentation‎ > ‎Code It‎ > ‎



In the last tutorial we looked at various means of repetition, now we're going to look at memory. We're all used to computers having many hundreds of Megabytes or Gigabytes of RAM memory. In turn these Mega/Giga bytes just refer to millions or billions of bytes and each byte is a circuit that hold 8-bits: a tiny box that holds a number from 0 to 255.

A computer knows where all this data is held because every byte circuit is given a numeric location called an address, which is just a number, like a tag attached to the box and there are other circuits which route data to exactly the right box according to a given tag value. Your FIGnition probably only has 8192 bytes, and their locations start at -32768 and count up to -24577. Strange eh, but the numbers are just tags, I could have designed FIGnition to make them start somewhere else.

In Forth we can reserve space for some bytes of memory for us to store data of our own choosing. Try typing:

24 var x  OK

This reserves space for a 16-bit number and tags it with the symbol 'x'. It also initialises these 16-bits of memory to 24. We can find out what the location of x is inside ram:

x . -32630  OK ( in my case)

Like it was said earlier, x is just a tag for a memory location from -32768 upwards, so -32630 is somewhere in RAM.

We can find out what's stored at x by typing x @ . ( @ is SW5, then SW1+SW3).

x @ . 24  OK

We can store a different value at x by typing number x ! ( ! is SW2+SW4). number of course can be a calculation:

63 21 * x !  OK

Forth stores the number and removes it from the stack, so if we did:

9999 63 21 * x ! . 9999 OK

And if we now did:

x @ . 1323  OK