Time for your first actual lesson!
Go back to your AHELLO
source (it's in the introduction if you've deleted it already) and change the line Disp Str1
to Disp Str1+7
. No, it's not going to give you a syntax error. Just do it, then compile and run.
Now that's new, isn't it? Or maybe it wasn't, depending on how much you already know. [Holds raz0r up to person's throat.]
So what was that? How could you add a number to a string? Well, that's the point of this lesson (no pun intended—you'll see). In Axe, Str1
isn't a string. It's just a plain old number. A number that points to a string.
To clear this up, let's go all the way down, to the basic structure of your calculator's memory. What does it look like? What makes a string a string, a list a list, and a matrix a convoluted two-dimensional list? For the most part, it's nothing. It's exactly the same at this level: a jumble of data that you can interpret as whatever you want to see. In the words of Sean McLoughlin's famous assembly tutorial:
“Data is whatever you define it to be.”
— Learn TI-83 Plus Assembly in 28 Days (2004)
I won't bother repeating it again, though I probably should.
To the calculator, it's all the same. One particular chunk of data might look like this:
01001000 | 01100101 | 01101100 | 01101100 | 01101111 | 00101100 | 00100000 | 01110111 | 01101111 | 01110010 | 01101100 | 01100100 | 00100001 |
If you prefer decimal, you might convert all the binary to base 10 (more on bases coming up in the next lesson):
72 | 101 | 108 | 108 | 111 | 44 | 32 | 119 | 111 | 114 | 108 | 100 | 33 |
Or you might even convert each byte to their character equivalents, from the TI-83 Plus character set:
H | e | l | l | o | , | w | o | r | l | d | ! |
What you see is what you want to see, but it's all the same to the calculator. The RAM on the TI-83 Plus is essentially a long train of these data bytes—32,768 bytes long.
Now here's the problem: If every byte of data looks just like all the others, how do you tell them apart? How do you know that this byte holds the number your game character's x-position, while that one might be a high score? That's where pointers come in, and that's why they're such an important concept for programming in Axe.
Let's think of it in real-life terms: Say you've got 32,768 houses lined up in a row that look exactly identical. What really matters is what's in each house, which could be a number from 0 to 255. How would you tell them apart? By using addresses. In the case of RAM on a TI-83 Plus, each address is a number between 32,768 and 65,535, and they all point to a distinct hou— er, byte. Hence addresses are also called pointers. For example, one particular string might start at address 50,062 and run to 50,064 (three bytes total). The pointer that points to the string would be the number 50,062. If our example above started at address 40,377, it would look like this:
40,377 | 40,378 | 40,379 | 40,380 | 40,381 | 40,382 | 40,383 | 40,384 | 40,385 | 40,386 | 40,387 | 40,388 | 40,389 |
---|---|---|---|---|---|---|---|---|---|---|---|---|
H | e | l | l | o | , | w | o | r | l | d | ! |
In our example program, the line "Hello, world!"→Str1
was a directive to the compiler to store the string Hello, world!
to the end of the program's own memory, after the program's actual code, then assign the string's pointer to the static variable Str1. It's not an actual executed command like Pt-On(
or DispGraph
, as we'll see later. To the program, the table above is now the same as this:
Str1 | Str1+1 | Str1+2 | Str1+3 | Str1+4 | Str1+5 | Str1+6 | Str1+7 | Str1+8 | Str1+9 | Str1+10 | Str1+11 | Str1+12 |
---|---|---|---|---|---|---|---|---|---|---|---|---|
H | e | l | l | o | , | w | o | r | l | d | ! |
The "string," "pic," and "GDB" tokens (Str1
, Pic92
, GDB3D
, etc.) are called static because they're assigned values during compilation and can't be changed afterward. (Try it yourself—put "Hi again!"→Str1
after the line above and Axe will throw an error.) Once static variables are defined, they can be used just like a number. You can add, subtract, multiply, and divide them just like any other constant number in Axe. Str0−2*9
is a valid computation, but it probably doesn't mean too much.
We'll come back to Axe variables soon enough; instead, let's deal with all these numbers.
« | Table of contents | » |
---|