Program Layout

A BASIC ASM program consists of 3 main parts: declaration statements, main code, and function code. This organization structure is rather similar to that found in C, and provides a measure of order not in pure BASIC or ASM code. To illustrate each of these sections, I will proceed to dissect the program you just compiled line by line.

Once again, to refresh your memory...

Sample Program:
#include <asmlib.h>

STRING mes = "Hello World !!"

START
cls
PRINTF 0 0 mes
END

Declarations
Since BASIC ASM is a function-based language, it is considered a high-level language, or at least midlevel, which necessitates the declaration of functions and variables so that the compiler (and eventually the CPU) can understand what these functions and variables mean. A function may be a ROM call, a built-in BASIC ASM function, or a user-defined function. See BASIC ASM Commands for the built-in BASIC ASM functions and their syntax. Variables may be strings or numbers. Additionally, other files containing code or definitions can be included in the source file.

So, back to our program. Let's take this one step at a time, beginning with the #include command.

#include tells BZC to use <file_name> as a header (include) file in this program. The asmlib.h file is essentially a master header file, consisting of tios.h, which contains the standard definitions for ROM calls and system variables, and other ASM routines. Note that it is different from the ti83plus.inc and the two files CANNOT be used interchangably; BZC uses asmlib.h (or, simply tios.h) and NOT ti83plus.inc.

STRING defines a constant string; it cannot be changed during program execution (this is not entirely true). As you can see, our string is later passed as a function to PRINTF.

Of course, there are a number of other declaration statements that we haven't covered yet, including function declarations. But that will wait for the next lesson, which is all about declarations...

Main Code
This section is where the actual execution of the program begins. Denoted by START, the main code section continues until the keyword END is reached, signifying the end of the program. When the calculator comes to this point, the program terminates, returning to the OS or the calling program. In our program, the functions to clear the screen, and print our message at specific coordinates are called from this block of code.

Since I promised I'd dissect this program, I will go ahead and do that next. cls is an extremely simple function that calls the TI-OS ROM call _ClrLCDFull, to clear the screen. PRINTF is quite a bit more complicated, but soooo useful! Its first two arguments are the coordinates on the home screen where you want to begin displaying something, and the third argument is, of course, what you want to display. PRINTF automatically detects the type of variable you pass to it (string or number) and adjusts accordingly.

One final note: you may have noticed that I've typed both the functions we just discussed in uppercase. Generally, in BASIC ASM, built-in functions are almost always REQUIRED to be in uppercase. On to the function code section!

Function Code
The third and final main section of the program is the function code. Here, code is assigned to the functions declared above in the declarations section. In our program, this section is not needed because we are using built-in BASIC ASM functions. In general, function code is assigned to a function prototype by the use of FSTART and FEND (with code between the two keywords); more information on this in the Functions lesson.

Now that you know the general layout of a BASIC ASM program, let's go to Declarations to learn more about declarations!