Special Operators
Previous  Next

Special Operators help to make math operations faster and are generally quicker to type out as well. There are currently 4 special operators supported in Second BASIC:

Here are some common uses of each of the operators:

Increment Operator: The increment operator will increment a long or integer data type by 1. Instead of using a = a + 1, you can do a++

Using the method of a = a + 1, the compiler will generate the following assembly code:

     clr.l d0
     move.w (__INTEGER_a), d0
     add.w #1, d0;
     move.w d0, (__INTEGER_a)

Using the increment operator, the compiler generates the following assembly code:

     addq.w #1, (__INTEGER_a)

Decrement Operator: The decrement operator functions exactly like the increment operator, except instead of adding 1, it subtracts 1.

Self Referencing Addition Operator: The self referencing operators will add or subtract the expression from the variable without having to reference it in the expression. For example, a = a + 3 * b would look like a+=3*b.

Using the first method, the assembly output is:

     clr.l d0
     move.w (__INTEGER_a), d0
     add.w #3, d0;
     mulu  (__INTEGER_b), d0
     move.w d0, (__INTEGER_a)

The self referencing operator outputs the following assembly code:

     move.l #3, d0
     mulu  (__INTEGER_b), d0
     add.w d0, (__INTEGER_a)

Self Referencing Subtraction Operator: The self referencing subtraction operator acts just like the self referencing addition operator, except it will subtract the expression instead of adding.