![]() |
VOOZH | about |
A variable is a chunk of RAM, set aside to hold some information for a specific purpose, e.g. the score or position of the player in a game, the current horizontal position of the cursor in a text editing application or an street information in a database.
In high-level programming languages such as the Commodore BASIC V2 built into the C64, variables are also assigned a name: Everywhere the program needs to access a particular variable, the high-level program text makes a reference to the variable's name.
In machine language, implementing a variable implies setting aside one or more bytes to hold the required information. Assemblers provide a means to assign a name, in this case called symbol, to the memory addresses in question, serving much the same purpose as the names of variables in "high-level" languages.
Commodore BASIC V2 supports three types of variables:
A=1.234A%, NO%, AB%=1000NA$, P$, BA$="TEXT"All three types are valid in BASIC's support for arrays as well.
SCREEN = 53281 for the memory address of the background color. It is not allowed to use BASIC keywords (tokens, see article C64-Commands or BASIC V2), also system variables ( ST (STATUS), TI (TIME) and TI$ (TIME$) or FN ), as variable names or a part of it. If you used tokens the BASIC error messsage ?SYNTAX ERROR appears.Examples of not allowed variable names: BASIC keywords are bold marked! SINUS% STAR BEFORE1$ F3FN2
The variable names are used together without conflicts: AB, AB% and AB$, because the interpreter used also the type information.
It is wise to use only variable names with max. 2 chars.
Example for a conflict of similair variable names: 10 A$="1" 20 AA$="2" 30 AAA$="3" 40 PRINT A$, AA$, AAA$ Display: 1 3 3
With the following methods can get a variable datas (values or strings):
LET A = 123.A = 123.B = A + 1.With the following methods can you get the datas (values or strings) from a variable:
Operators are used to perform operations or logical comparisons on the values of two or more variables of the same type. Operators are grouped into three types: numeric, logical and string. Some operators are only a single character ( +, -, *, /, ↑, <, >, =, . ), while others are keywords (AND, OR and NOT). By using brackets can changed the rank hierarchy. First, the contents of the innermost bracket is calculated. The maximum depth of nested brackets is 10 levels. If more levels are used, the BASIC error message appears.
The rank hierarchy of the operators is on the C64, that the operator with the highest priority firstly is calculated:
| Rank | Operator | Remark |
|---|---|---|
| 1 | ↑ | exponentiation |
| 2 | + - |
prefix |
| 3 | * / |
multiplication division |
| 4 | + - |
addition and string concatenation subtraction |
| 5 | < <= = >= > <> |
comparison |
| 6 | NOT | logical NOT |
| 7 | AND | logical AND |
| 8 | OR | logical OR |
The logical operators AND, OR and NOT can also used for bitwise adding of numbers (max. 16 bit).
Examples:
C=A+BC=A-BC=A*BC=A/B ?DIVISION BY ZERO appears.C=-B or C=2-(-4)C=2↑2C=A+1E+6C=D*π10 ON (X AND Y)+2 GOTO 100, 200 99 REM X, Y: 0 | -1 ... FALSe | TRUE 100 PRINT "TRUE":END 200 PRINT "FALSE":END
REM SET BIT 6 OF A MEMORY ADDRESS: POKE 53269, PEEK(53269) OR 64
C$ = A$ + B$A variable independent of the type used 7 bytes in the memory: 2 bytes for the variable name and the type and 5 bytes reserved for stored data:
Array or field variables are used the memory save. With the command DIM is used for each variable (cell) only the datas for the variable type: 5 bytes (real), 2 bytes (integer) and 3 bytes (string)
| 👁 Image |
Wikipedia: Variable_(computer_science) |
| 👁 Image |
Wikipedia: Significand |