3.4 The Integer Segment

Wonder where all these variables are created? Or where that infamous stack really is? I bet you do. Well, when you define a variable, memory is allocated in the Integer Segment. When you define another one, space is allocated after the first variable. That means that if you go beyond the boundaries of the first variable, you'll end up in the space allocated to the second variable.

After the second variable there is a void. If you end up there your program will end with an error-message. However, if you define an 'ARRAY', a single variable is created with a number of additional cells. You can only access these additional by referring to the array itself.

And what about the space before the first variable? There are other variables and they are not defined by you. Well, take a look at this diagram:

Integer Segment

Lower memory is at the bottom. The user variables are the variables you defined yourself. The application variables can differ from host program to host program. Refer to your documentation on that subject. You have already seen the 4tH variables, which are 'BASE' and '>IN'. All these variables are located in the Variable Area.

There is also a Stack Area, which contain the datastack and the returnstack. If you enter a number like "5", it is thrown on the datastack. Most words in 4tH take or put numbers on the datastack. It is very heavily used. We'll come to the returnstack later on.

The datastack and the returnstack share the same memoryspace. The datastack grows upward and the returnstack downward. If they clash the stack is full and 4tH will issue an error-message.