8085 Basic Compiler Reference Manual
 
 

The list of all Basic compiler keywords:
DIM, AS, BOOLEAN, SHORT, INTEGER, TRUE, FALSE, CONST, MOD, NOT, AND, OR, XOR, NAND, NOR, NXOR, GOTO, FOR, TO, STEP, NEXT, WHILE, WEND, IF, THEN, ELSE, ENDIF, POKE, PEEK, SETBIT, RESETBIT, GET, PUT, PRINT, LF, CRLF, END, GOSUB, RETURN
 

Default extension for basic source files is BAS. The compiler output is assembler source file (with ASM extension) that can be translated to binary code using integrated assembler. Smart editor marks all reserved keywords in different color, that simplifies debugging process.

Three data types are supported:
- Boolean (1-byte, True or False)
- Short (1-byte integers in the range -128 to 127)
- Integer (2-byte integers in the range -32,768 to 32,767)

Variables are declared using DIM statement:
DIM A AS BOOLEAN
DIM B AS SHORT
DIM C AS INTEGER

Declarations may be placed anywhere in the program. There are no other limits for the total number of variables, but 64K memory.

It is also possible to use one-dimensional arrays. For example:
DIM A(100) AS INTEGER

declares an array of 100 integers with array index in the range [0-99]. When using variable index in statements, it must be Integer data type.

It is possible to make conversions between Short and Integer data type by simple assignment statements:
DIM A AS SHORT
DIM B AS INTEGER
A = 123
B = A

This will result in variable B holding integer value 123.

Constants can be used in decimal number system with no special marks, in hexadecimal number system with leading 0x notation (or with H at the end) and in binary system with leading % mark (or with B at the end). Keywords True and False are also available for Boolean type constants. For example:
DIM A AS BOOLEAN
DIM B AS SHORT
DIM C AS INTEGER
A = TRUE
B = %01010101
C = 0x55AA

Constants can also be assigned to symbolic names using CONST directive:
DIM A AS INTEGER
CONST HIGH = 1023
A = HIGH

Five arithmetic operations (+, -, *, /, MOD) are supported. It is possible to make only one arithmetic operation in one single statement. Arithmetic operations are allowed only in assignment statements and all variables in one such statement must be the same data type. For example:
DIM A AS INTEGER
DIM B AS INTEGER
A = 123
B = 234
B = A * B

For Boolean and Short data type variables seven basic logical operations are supported. It is possible to make only one logical operation in one single statement. Logical operations are allowed only in assignment statements. For example:
DIM A AS BOOLEAN
DIM B AS BOOLEAN
DIM C AS BOOLEAN
A = TRUE
B = FALSE
C = NOT A
C = A AND B
C = A OR B
C = A XOR B
C = A NAND B
C = A NOR B
C = A NXOR B


DIM A AS SHORT
A = 0x55
A = NOT A

The GOTO statement uses line label name as argument. Line labels must be followed by colon mark ":". For example:
DIM A AS INTEGER
A = 0
loop: A = A + 1
GOTO loop

Three standard BASIC statements are supported: FOR-TO-STEP-NEXT, WHILE-WEND and IF-THEN-ELSE-ENDIF. In FOR-TO-STEP-NEXT statement all variables must be Integer data type. Here are several examples:
DIM A AS INTEGER
DIM B(100) AS INTEGER
FOR A = 0 TO 99
B(A) = A
NEXT A


DIM A AS INTEGER
A = 10000
WHILE A > 0
   A = A - 1
WEND


DIM A AS INTEGER
DIM B AS INTEGER
FOR A = 0 TO 10000
IF A < 1000 THEN
   B = A
ELSE
   B = 1000
ENDIF
NEXT A

IF statements that are not used for conditional branching must always be used in connection with ENDIF, even if there is only one statement to be executed if the condition is satisfied. If there are statements following THEN in the same line an error is generated. Only GOTO statement (or just line label name) may be placed in the same line after THEN statement. There are no limits for the number of nested statements of any kind.

Standard BASIC elements for accessing memory are available: POKE statement and PEEK function. They can be used with integer constants and also with variables of Short or Integer data type. For example:
DIM A AS INTEGER
DIM B AS INTEGER
DIM C AS INTEGER
FOR A = 0 TO 15
B = PEEK(A)
C = 240 + A
POKE C, B
NEXT A

SETBIT and RESETBIT statements can be used to set or reset the individual bits in Short data type variables. The first argument is a Short variable that will be the target of the operation, and the second argument is target bit number and it must be a constant in the range 0-7.
DIM A AS SHORT
A = 0xF0
SETBIT A, 0
RESETBIT A, 7

The communication with the outside world is done using GET function and PUT and PRINT statements. The argument of the GET function is port number and must be a constant value in the range [0-255]. It can be used to assign the value received on the port to a variable of Short or Integer data type. For example:
DIM A AS INTEGER
A = GET(10)

PUT statement can be used to send data to the specified port. The data can be a constant value in the range [0-255] or contained in a variable of Short or Integer data type. Only the lowest byte of the variable is sent to the port. For example:
DIM A AS INTEGER
A = 200
PUT 10, A

PRINT statement can be used in three different ways. It is possible to use it to send a constant string , to send a variable of any supported data type or to send the LF (Line Feed) character or CRLF (Carriage Return - Line Feed) sequence to the specified port. Here is an example:
DIM A AS INTEGER
A = 12345
PRINT 10, "THE NUMBER IS "
PRINT 10, A
PRINT 10, CRLF

This can also be done using only one PRINT statement:
PRINT 10, "THE NUMBER IS ", A, CRLF

Structured programs can be written using subroutine calls with GOSUB statement that uses line label name as argument. Return from a subroutine is performed by RETURN statement. User need to take care that the program structure is consistent. When using subroutines, main routine need to be ended with END statement. Here is an example:
DIM A AS INTEGER
A = 12345
GOSUB printroutine
A = -12345
GOSUB printroutine
END
printroutine:
PRINT 10, A
PRINT 10, CRLF
RETURN

It is possible to use comments in basic source programs. The comments must begin with single quote symbol (') and may be placed anywhere in the program.

BASIC compiler has no optimization abilities. Although it can be used for development projects, its main purpose is educational. Its assembler output has all necessary comment lines, that will help user understand how high-level BASIC statements are compiled to low-level assembly language, ready for execution by 8085 CPU.