Positron Compiler Documentation

Using Include files to tidy up your code

Positron8 · Revision 4.0.6.5 · PDF pages 450–451

If the include file contains assembler subroutines on a standard 14-bit core device, then it must always be placed at the beginning of the program. This allows the subroutine/s to be placed within the first bank of memory (0..2048), thus avoiding any bank boundary errors. Placing the include file at the beginning of the program also allows all of the variables used by the routines held within it to be pre-declared. This again makes for a tidier program, as a long list of variables is not present in the main program.

There are some considerations that must be taken into account when writing code for an include file, these are: -

1). Always jump over standard subroutines.

When the include file is placed at the top of the program this is the first place that the compiler starts, therefore, it will run the subroutine/s first and the Return command will be pointing to a random place within the code. To overcome this, place a GoTo statement just before the subroutine starts. Note. If procedures are placed in the Include file, then there is no need to jump over them.

View original PDF page 450Open page in PDFOriginal PDF page 450

For example: -

  GoTo Over_This_Subroutine ' Jump over the subroutine
' The subroutine is placed here

Over_This_Subroutine:        ' Jump to here first

2). Variable, Procedure and Label names should be as meaningful as possible.

For example. Instead of naming a variable MyLoop, change it to ISub_MyLoop. This will help eliminate any possible duplication errors, caused by the main program trying to use the same variable or label name. However, try not to make them too obscure as your code will be harder to read and understand, it might make sense at the time of writing, but come back to it after a few weeks and it will be meaningless.

3). Comment, Comment, and Comment some more.

This cannot be emphasised enough. Always place a plethora of remarks and comments. The purpose of the subroutine/s within the include file should be clearly explained at the top of the program, also, add comments after virtually every command line, and clearly explain the purpose of all variables and constants used. This will allow the subroutine to be used many weeks or months after its conception. A rule of thumb that I use is that I can understand what is going on within the code by reading only the comments to the right of the command lines.

View original PDF page 451Open page in PDFOriginal PDF page 451