BASIC09's multipass compiler produces a compressed and optimized low-level I-code for execution. Compared to other BASIC languages, BASIC09 greatly decreases both the storage space required for program code and the execution speed of programs.
Because BASIC09 produces I-code at a powerful level, it can handle numerous MPU (micro processor unit) instructions with a single interpretation. Therefore, for complex programs, there is little performance difference between the execution of I-code and pure machine-language instructions.
Most BASIC languages have to compile from text as they run, or search tables of tokens in order to execute code. Instead, BASIC09 I-code instructions contain direct references to variables, statements, and labels. BASIC09 fully utilizes the power of the 6809 instruction set, as well, which is optimized for efficient execution of compiler-produced code.
Because BASIC09 interprets I-code, you have a variety of entrytime and run-time tests and development aids. The editor reports syntax errors immediately when they are entered. The debugger lets you debug using original program source statements and names. The I-code interpreter performs run-time error checking of array structures and BASIC09 functions.
The following notes apply to the use of BASIC09 numeric data types:
BASIC09 includes several different numeric representations (real, integer, byte), and performs automatic type conversions between them. This means that without care, your code might contain expressions or loops that take more than ten times longer to execute than is necessary.
Some BASIC09 numeric operators, such as + ,-,*, and /, and some BASIC09 control structures include versions for both real and integer values. Integer versions execute much faster and can have slightly different properties. Fbr instance, integer division discards any remainder.
Integer operations are faster because they use corresponding 6809 instructions. Using integers increases speed and decreases storage requirements. Integer operations use the same symbols as real operations, but BASIC09 automatically selects the integer operations when when all operands of an expression are of byte or integer type.
Type conversion takes time. Using expressions with operands and operators of the same kind is most efficient.
0 BASIC09's real (floating point) math provides excellent performance. It includes a 40-bit binary floating point representation and uses the CORDIC technique to derive all transcendental functions. This integer shift-and-add technique is faster and more consistent than the common series-expansion approximations.
At times, you can obtain similar or identical results in a number of different ways and at different execution speeds. Fbr example, if the variable Value is an integer, then va 1 u e * 2 is a fast integer operation. However, if the expression is v a 1 u e * 2 . 0 , 2 .0 is represented as a real number and the operation requires real multiplication. BASIC09 must transform the integer Value into a real value. If the result of the expression is assigned to an integer type variable, BASIC09 must transform the result back to an integer type. The decimal point can slow the operation by about ten times.
Referring to the previous table can help you in your programming. For instance, notice that it is quicker to add a value to itself rather than multiplying it by 2. Similarly, multiplying a value by itself or using SQ on a value is much faster than raising a value to the power of 2.
Notice that a real divide takes 3870 cycles, while a real multiplication takes only 990 cycles. Multiplying a value by 0.5 is four times quicker than dividing the value by 2.
BASIC09 has two versions of FOR/NEXT loops, one for integer loop counter variables and one for real loop counter variables. It automatically uses the appropriate version. Integer FOR/NEXT loops are much faster than real FOR/NEXT loops.
Other kinds of loops also run faster if you use integer type variables for the loop counters. When writing program loops, remember that statements inside the loop can execute many times for each execution outside the loop. Whenever possible, compute values before entering loops.
The internal workings of BASIC09 use integer numbers to index arrays and complex data structures. This means that BASIC09 must convert real type variable or expression subscripts before it can handle them. Using integer expressions for subscripts increases execution speed.
Using the assignment statement LET to copy identically sized data structures is much faster than copying arrays or structures element-by-element inside a loop.
PACK causes a second compilation of a specified procedure. Depending on such variables as the number of procedure comments and the inclusion of line numbers, packed procedures execute from 10 to 30 percent faster. Line numbers cause unpacked procedures to run slower.
For maximum execution speed, precalculate constant expressions. For instance, x = x ; 5 produces the same result as x = x · s q r t c 7 0 e ) / 2 . However, the first expression requires approximately 150 MPU cycles while the second expression requires 11,650 MPU cycles. If you use such an expression inside a loop, the additional execution time is enormous.
Accessing data one line or record at a time is much faster than accessing it one character at a time. Also, the GET and PUT statements are much faster than READ and WRITE statements when accessing disk files. This is because GET and PUT use the same binary format as BASIC09's internal operations. READ, WRITE, PRINT, and INPUT must perform binary-to-ASCII or ASCII-to-binary conversions, which take more time.