Buffalo Lang

Moving the pointer

The pointer is probably the hardest concept to understand in Buffalo and so that is where we begin our tutorial.

Because only one memory address value can be manipulated at any time in Buffalo, we use a pointer to keep track of the currently active address. This pointer can then move either left or right allowing the programmer to change the value stored at neighbouring memory addresses.


Moving the pointer to the right

As we have already seen this is what our buffer looks like when we first execute a Buffalo program. All values are initialized to zero and our pointer (^) is initialized pointing at address 0.

 0  1  2  3  4  5  ... 255
[0][0][0][0][0][0][...][0]
 ^

We will then execute the following command.

buffalo Buffalo

This is what our buffer now looks like:

 0  1  2  3  4  5  ... 255
[0][0][0][0][0][0][...][0]
    ^

See how the pointer now points to the next address in memory (1).

Lets move it two more times to the right with the following command.

buffalo Buffalo buffalo Buffalo

Our pointer is now positioned at address 3.

 0  1  2  3  4  5  ... 255
[0][0][0][0][0][0][...][0]
          ^

Moving the pointer to the left

Following on from above we can now move the pointer back to the left by executing the opposite command.

Buffalo buffalo

This is what our buffer looks like now:

 0  1  2  3  4  5  ... 255
[0][0][0][0][0][0][...][0]
       ^

Our pointer has shifted to the left by one memory address (2):

Lets move it all the way back to where it started at address 0 with this command.

Buffalo buffalo Buffalo buffalo

This will shift out pointer twice to the left.

 0  1  2  3  4  5  ... 255
[0][0][0][0][0][0][...][0]
 ^

It doesn't matter how many times we shift it to the left, it will never go beyond address 0 (or address 255 when moving it to the right).