home *** CD-ROM | disk | FTP | other *** search
- PEEKs, POKEs, and SYSes -- Part 25
-
- "VARIABLES"
-
- Next we'll cover strings. Strings
-
- are relatively easy, but can get a bit
-
- confusing. Strings variables, just
-
- like the other types, each use seven
-
- bytes of variable space. The first
-
- two bytes represent the name. The
-
- high bit is set in only the second
-
- byte of a string variable's name. The
-
- third byte is the actual length of the
-
- string. The fourth and fifth bytes
-
- are the pointer to the string.
-
- (Remember our talk about envelopes?)
-
- This pointer contains the address of
-
- the actual contents of the string.
-
- The string pointer is stored in the
-
- usual format of low byte/high byte.
-
- By looking at the address pointed to
-
- to by the string pointer, you can get
-
- a look at the actual string.
-
- In the case of C$="TRY AGAIN.." it
-
- would all look something like this:
-
- The contents of the variable table:
- 067, 128, 011, 245, 159, 000, 000
- < name > <len> <pointer> <unused>
-
- So, CHR$(67) = "C", the name.
-
- "TRY AGAIN.." is 11 characters long,
-
- and found in memory at 40949 (245 +
-
- 159*256 = 40949) like this:
-
- The contents of the string, itself:
- 40949,50, 1, 2, 3, 4, 5, 6, 7, 8, 9
- "T R Y A G A I N . ."
- - - - - - - - - - - - - - - - - - - -
-
- Last but not least are the REALS.
-
- They are the hardest to understand
-
- because of the way in which they are
-
- stored. Real variables also take up
-
- seven bytes of storage. Again, the
-
- first two represent the name. Neither
-
- byte has its high-bit set. After that
-
- is where the trouble starts. Since
-
- reals are floating-point numbers, they
-
- are stored in floating-point form.
-
- This means the 3rd byte is the
-
- exponent and the next four bytes
-
- represent the mantissa. Since
-
- floating-point notation is so darn
-
- confusing (WE sure don't understand
-
- it), we use a built-in ROM routine to
-
- convert them to usable numbers (thank
-
- goodness for ROM). You can't really
-
- use that routine at all as a BASIC
-
- SYS.
- - - - - - - - - - - - - - - - - - - -
-
- The locations 47 and 48 point to the
-
- beginning of array storage. The start
-
- of arrays "floats" on top of the
-
- simple variable table. This means
-
- that the simple variables start at the
-
- location pointed to by 45 and 46 and
-
- end at the location pointed to by 47
-
- and 48.
-
- Now that you're totally confused,
-
- I'll tell you the good news. To make
-
- some use out of all this gobbledygook,
-
- I have included a program on Side 2
-
- of this disk. It is a relatively
-
- small machine-language routine which
-
- prints the value(s) of all of your
-
- simple BASIC variables. (It doesn't
-
- print any of the array variables.) I
-
- have included the source file as well
-
- for those of you who want to see just
-
- how it is done. It was coded using
-
- BASM. The routine is saved under the
-
- name of 'VARPRINT'. The source file
-
- is saved under the name of
-
- 'VARPRINT.SRC'.
-
- To use the routine simply do the
-
- following before you start any
-
- programming:
-
-
- 1. LOAD"VARPRINT",8,1
-
- 2. Type NEW
-
-
- Then you can go about doing whatever
-
- you want, including writing and
-
- running a BASIC program. Whenever you
-
- want a list of all your variables,
-
- simply type:
-
-
- SYS 49664
-
-
- If you want the list sent to your
-
- printer, try this:
-
- OPEN4,4,7
- SYS 49664
- PRINT#4
- CLOSE4
-
- This will send a list of all your
-
- simple variables to the printer.
-
- I hope that this program will help
-
- you in your programming efforts.
-
- ----------<end of article>------------
-