Topic : The GFA-Basic Compendium Author : GFA Systemtechnik GmbH Version : GFABasic.HYP v2.98 (12/31/2023) Subject : Documentation/Programming Nodes : 899 Index Size : 28056 HCP-Version : 3 Compiled on : Atari @charset : atarist @lang : @default : Document not found @help : Help @options : +g -i -s +z @width : 75 @hostname : STRNGSRV @hostname : CAB @hostname : HIGHWIRE @hostname : THING View Ref-FileThe Atari ST's processor, the Motorola 68000, has instructions to process integer numbers. BASIC lines which simply carry out arithmetic operations on integer variables can be translated into a few assembler instructions as long as these lines are not too complex. Operations on floating point variables require far more assembler instructions, and this is reflected in the processing time taken. Adding two integer values to each other is about five to six times faster than the addition of two floating point values. The first question to be discussed here is: When does the compiler use the faster integer arithmetic and when does use floating point arithmetic? The statements a%=b%+c% and a%=ADD(b%,c%) are processed by the interpreter at different speeds. The compiler, however, simply generates the same code from both: move.l -$7ff8(a5),d0 add.l -$7ffc(a5),d0 move.l d0,-$8000(a5) The addresses -$xxxx(a5) depend on which variables are used in the program. The variables can be found from -$8000(a5) onwards. If you have used two-byte variables, for instance a&=b&+c&, the compiler will generate the following instructions: move.w -$7ffc(a5),d0 add.w -$7ffe(a5),d0 move.w d0,-$8000(a5) With one-byte variables (a|=b|+x|) you get: moveq.l #$0,d0 move.b -$7ffe(a5),d0 move.b -$7fff(a5),d1 add.l d1,d0 move.b d0,-$8000(a5) However, a program line such as a=b+c uses floating-point variables. To perform a floating point addition, the compiler program will contain an appropriate subroutine. In the disassembled listing of a program with a symbol table you find: lea.l -$7ff0(a5),a0 lea.l -$7ff8(a5),a1 bsr VVFADD lea.l -$8000(a5),a0 move.l d0,(a0)+ move.w d1,(a0)+ move.w d2,(a0)+ This listing contains the line bsr VVFADD. This line branches to the floating point addition routine, which is processed far more slowly than the instructions generated by, for example, a%=b%+c%. The code produced by two-byte additions can be processed most quickly by the computer. The next fastest is the one-byte addition code, then the four-byte addition and finally, a long way behind, the floating point addition code. The following table gives some examples for the different timings for the different variable types in a simple addition in both the interpreter and the compiler. A loop with 5000 runs was used, with the time taken by the loop commands eliminated. Type Interpreter Compiler Statement Byte 11.715 0.31 a|=b|+c| Word 11.715 0.255 a&=b&+c& Long 11.355 0.335 a%=b%+c% Float 6.23 1.925 a=b+c Similar timings apply to subtraction.