8085 Simulator IDE
BASIC Compiler Reference Manual


Table Of Contents:

General info
Show Warnings, Do Not Compile Unused Code, Initialize Variables On Declaration, Optimize Variables Declaration,

About variables
Dim, As, Boolean, Short, Integer, True, False, Const, ASM, IncludeASM,

Mathematical and logical operations
Mod, Not, And, Or, Xor, Nand, Nor, Nxor,

Standard Basic language elements
Goto, For, To, Step, Next, Exit For, While, Wend, If, Then, Else, Endif,

Memory access
Poke, Peek,

Subroutines
End, Gosub, Return,

Bit-oriented language elements
SetBit, ResetBit,

Communication with I/O ports
Get, Put, Print, Qt, CrLf, Lf,

Structured language support (procedures and functions)
Proc, End Proc, Call, Exit, Function, End Function, Include,


General info

Basic compiler editor is composed of editor panel (for user program editing) and source explorer (for easy navigation through all elements of user program - variables, symbols, constants, subroutines, procedures and functions). Editor formats and colorizes entered lines of user program, that simplifies the debugging process.

The primary output of the compiler is an assembler source file. However, with an appropriate command from the menu it can be assembled and even loaded in the simulator with a single click. Menu commands and options are rich, as well as the commands from the right-click popup menus for the editor and source explorer. Basic compiler's assembler output contains many useful comment lines, that makes it very helpful for educational purposes, also.

Show Warnings
If Show Warnings option is enabled, in the Warnings window Basic compiler will show information about unused declarations, subroutines, procedures and functions in the user basic program.

Do Not Compile Unused Code
If this option is enabled, Basic compiler will not compile unused declarations, subroutines, procedures and functions, in order to save memory resources.

Initialize Variables On Declaration
If this option is enabled, Basic compiler will reset to zero all memory locations allocated for variables, at the position of their declaration in the basic program. This option is useful for beginners, because RAM memory is filled with random values at device power-up, and it is easy to make a mistake to assume that all variables are reset to zero at power-up. Experienced users can save some program memory, by disabling this option and taking control of variable initial values by user program where necessary.

Optimize Variables Declaration
This option will turn on the compiler internal routine that will optimize the variables declaration order based on the usage frequency of the variables. In this way, the most frequently used variables will be stored in higher RAM memory locations, resulting in possibly smaller size of the generated code.

About variables

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 can be global (declared in the main program, before the End statement) or local (declared in subroutines, procedures and functions). Variable name used for a variable with global scope can be used again for local variable names. The compiler will reserve separate memory locations for them. There are no other limits for the total number of variables, but 64K RAM memory. Variables are declared using DIM statement:
   Dim a As Boolean
   Dim b As Short
   Dim c As Integer

It is possible to use one-dimensional arrays for all variable types. For example:
   Dim a(100) As Integer
declares an array of 100 Integer variables with array index in the range [0-99].

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 or leading $ notation (or with H at the end) and in binary system with leading % mark (or with B at the end). ASCII value of a character can be expressed in string format (e.g. "A"). 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
   c = "C"

Constants can be assigned to symbolic names using CONST directive. Constants can be global or local. One example:
   Dim a As Integer
   Const high = 1023
   a = high

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.

Lines of assembler source code may be placed anywhere in basic source program and must begin with ASM: prefix. If labels are used, no space should be left between the ASM: prefix and the label. For example:
   ASM:        NOP
   ASM:LABEL1: LDAX B

Symbolic names of all variables and constants (global and local) can be used as arguments of assembler statements. The compiler will replace that symbolic name with the proper variable address or constant value:
   Dim varname As Short
   varname = 0
   ASM:        MVI A,55H
   ASM:        STA VARNAME

If large amount of assembler code should be used, it can be loaded from an external assembler file and included to the current program by using IncludeASM directive. Its only argument is a string containing the path to the external .ASM file. This can be the full path or only the file name, if the external file is located in the same folder as the current basic program file. During the compilation process the external assembler code will be appended to the current program at its end, and not at the position of the directive. Multiple files can be included with separate IncludeASM directives. External assembler files should not contain ASM: prefix used for inline assembler code. It is also strongly suggested not to use ORG directives in the external assembler code.

Mathematical and logical operations

Five arithmetic operations (+, -, *, /, MOD) are available for integer data types. The compiler is able to compile all possible complex arithmetic expressions, including those containing math functions and user defined functions. Arithmetic operations are allowed only in assignment statements and all variables in one such statement must be of the same data type. For example:
   Dim a As Integer
   Dim b As Integer
   Dim c As Integer
   a = 123
   b = 234
   b = a * b
   c = a * 100 - (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:
Example 1:
   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

Example 2:
   Dim a As Short
   a = 0x55
   a = Not a

Standard Basic language elements

Unconditional jumps are performed by GOTO statement. It uses line label name as argument. Line labels can be global or local. Line labels must be followed by colon mark ':'. Here is one 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:
Example 1:
   Dim a As Integer
   Dim b(100) As Integer
   For a = 0 To 99
      b(a) = a
   Next a

Example 2:
   Dim a As Integer
   a = 10000
   While a > 0
      a = a - 1
   Wend

Example 3:
   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

For statement will accept all available variable types for the running variable. Exit For statement provides a way to exit a For-Next loop. It transfers control to the statement following the Next statement.

After IF-THEN statement in the same line can be placed almost every other possible statement and then ENDIF is not used. Six standard comparison operators are available: =, <>, >, >=, <, <=. There are no limits for the number of nested statements of any kind.

Memory access

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

Subroutines

Structured programs can be written using subroutine calls with GOSUB statements that use line label names as arguments. Return from a subroutine is performed by a RETURN statement. Users need to take care that the program structure is consistent. When using subroutines, the main routine must end with an END statement. The END statement is compiled as a HLT instruction. Here is an example:
   Dim a As Integer
   Dim b As Integer

   b = 100
   Gosub fillmemory
   b = 101
   Gosub fillmemory
   End

   fillmemory:
   For a = 20000 To 21000
      Poke a, b
   Next a
   Return

Bit-oriented language elements

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

Communication with I/O ports

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 to send string constants and decimal string representations of any supported data type variables to the specified port.
String constants should begin and end with the opening and closing double quotation mark. There are three symbolic string constants available: Qt (or """") for the double quotation mark (ASCII code 34), CrLf for the carriage return - line feed sequence (ASCII codes 13-10) and Lf for the line feed character (ASCII code 10).
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 language support (procedures and functions)

Procedures can be declared with PROC statement. They can contain up to 5 arguments (comma separated list) and all available data types can be used for argument variables. Argument variables are declared locally, so they do not need to have unique names in relation to the rest of user basic program, that makes very easy to re-use once written procedures in other basic programs. The procedures can be exited with EXIT statement. They must be ended with END PROC statement and must be placed after the END statement in program. Calls to procedures are implemented with CALL statement. The list of passed arguments can contain both variables and numeric constants. For example:
   Dim x As Integer
   For x = 0 To 255
      Call port_display(x)
   Next x
   End

   Proc port_display(arg1 As Integer)
   Print 10, "THE NUMBER IS ", arg1, CrLf
   End Proc

All facts stated for procedures are valid for functions, also. Functions can be declared with FUNCTION statement. They can contain up to 5 arguments and argument variables are declared locally. Functions can be exited with EXIT statement and must be ended with END FUNCTION. The name of the function is declared as a global variable, so if the function is called with CALL statement, after its execution the function variable will contain the result. Standard way of function calls in assignment statements can be used, also. One simple example:
   Dim x As Integer
   Dim y As Integer
   For x = 0 To 100
      y = square(x)
   Next x
   End

   Function square(arg1 As Integer) As Integer
   square = arg1 * arg1
   End Function

Basic source code from an external file can be included to the current program by using INCLUDE directive. Its only argument is a string containing the path to the external .BAS file. This can be the full path or only the file name, if the external file is located in the same folder as the current basic program file. During the compilation process the external basic source will be appended to the current program. Multiple files can be included with separate INCLUDE directives. To maintain the overall basic code structure, it is strongly suggested that the external file contains global declarations, subroutines, procedures and functions, only. Here is one very simple example for the demonstration:
main.bas:
   Dim i As Integer
   Dim j As Integer

   Include "inc1.bas"
   Include "inc2.bas"

   For i = 1 To 10
      j = func1(i, 100)
      Call proc1(j)
   Next i
   End

inc1.bas:
   Dim total As Integer

   Proc proc1(i As Integer)
   total = total + i
   End Proc

inc2.bas:
   Function func1(i As Integer, j As Integer) As Integer
   func1 = i + j
   End Function