Amos Professional Manual  Contents  Index

Machine Code


The slightest error made in your address calculations will crash AMOS Professional, so it is vital to save your programs before attempting to change your variables in this way.

With machine code programs, VARPTR can also be used to manipulate entire strings or arrays directly. Each type of variable is stored in its own individual format, as listed below.

Integers are held as a simple group of four bytes. They can be read from your Basic program using LEEK, and altered by LOKE. Here is an example of this (dangerous) method:

E> ANSWER=43 : Rem Load a variable
   AN=Varptr(ANSWER) : Rem Find address of variable
   Loke AN,LEEK(AN)-1 : Rem Equivalent to ANSWER=ANSWER-1
   Print ANSWER

Floating point numbers are stored as four bytes, using the special Fast-Floating point format. However, if DOUBLE PRECISION is being used, floating point numbers are held as a group of eight bytes in IEEE double precision format.

Strings are stored' as a series of characters in standard Ascii format. The address given by VARPTR points to the first character in the string, and this can be examined with PEEK or replaced using POKE. Note that the length of the string is contained in two bytes immediately before the string. This means that it can be loaded into Basic using a line like this:

X> Print Deek(Varptr(A$)-2) : Rem Equivalent to Print Len(A$)

One application of this function is to return the Ascii value of a single character in an AMOS Professional string. The standard method is to make use of the ASC and M1D$ functions, like this:

X> A=Asc(Mid$(A$),C,1) : Rem Return Ascii code of character C in A$

Using VARPTR, that could be replaced by the following line:

X> A=Peek(Varptr(A$)+C)

To avoid danger, special precautions must be taken before new values are poked into a string. During the course of a program, the address of a string may change many times, so it is vital to load the current address of a string using VARPTR immediately before that string is used.

AMOS Professional regularly reorganises all strings in memory, using a "garbage collection" process. This frees valuable space needed for variables, and is essential for the smooth running of the system. But if you wish to pass the address of a string as a procedure garbage collection can play havoc. The obvious solution is to collect the garbage before the address is calculated, using a simple line like this:

X> X=Free
Back    Next
14.A.07