The ZBasic language was designed to be highly compatible with Microsoft's Visual Basic (VB6)
and with NetMedia's BasicX; it is a subset of the former and a superset of the latter.
The fundamental capabilities of these languages are augmented with carefully chosen extensions.
The result is a powerful and easy-to-use language for microcontroller programming.
If you're an experienced programmer, you'll find ZBasic a snap to pick up.
And, if you've never written a computer program before you'll likely
be pleased with how quick and easy it is to learn.
ZBasic has all the elements of a modern, strongly typed, procedural programming language including:
- true block structure with local, module and global variables
- modern control structures - if/then, do while, for/next, select case
- parameterized function and subroutine invocation (pass "by value" or "by reference")
- wide spectrum of standard data types including boolean, signed and unsigned integral, real, string
- user-defined enumerated types
The features described above make it easier and faster to write correct programs as compared
with outdated non-procedural languages like PBasic (used for the Parallax Basic Stamp).
To create an even more powerful programming language, extensions were added such as:
ZBasic offers many improvements over BasicX beyond the extensions listed above such as:
- sub-byte data types (bit and nibble)
- polymorphic data access (aliases and based variables)
- exception handling
- conditional compilation
- "include" capability
- user-defined types (structures and unions)
- more efficient and higher capacity string data type
- support for arrays of strings, structures, unions
- more efficient call/return protocol
- more versatile Select Case statement
- data items with local scope but static lifetime
- wider variety of persistent and program memory data types
- in-line definition of program memory data item content
The optional ZBasic object-oriented extensions allow you to construct object-oriented (O-O) solutions
for your projects. Although ZBasic is largely modeled after Visual Basic, we chose to implement
a much more powerful object model than VB provides, incorporating ideas from Java, C++ and other
object-oriented languages. Because the O-O extensions are optional, you may implement your
application entirely using the more familiar procedural model or you may choose to design
your application using O-O concepts from the outset.
The ZBasic object model is fully documented in the
ZBasic Language Reference Manual.
Extensive System Library
The ZBasic System Library provides a rich collection of over 250 subroutines and functions
that you can use to quickly add functionality to your application.
The routines fall into several fundamental categories including:
The routines are fully documented in the
ZBasic System Library Reference Manual.
- type conversion functions
- mathematical functions - sin, cos, log, etc.
- I/O-related routines - PWM, SPI, I2C, 1-Wire, serial, pin I/O, ADC, X-10, sound
- date/time functions
- string-oriented routines
- task management routines
- queue management functions
Advanced Optimizing Compiler
The ZBasic compiler is an advanced, optimizing design that produces very efficient code.
It can detect subroutines, functions and data items that are not used and (by default) omits
those unused elements. This results in smaller code size and smaller RAM usage.
Beyond that, the compiler also detects sections of code that are
unreachable or that have no practical effect. For example, the compiler's sophisticated code
analysis can detect the assignment of a value to a variable that is not utilized before a subsequent
assignment. Since the first assignment is pointless, the compiler omits the code for that assignment.
Additionally, the compiler's in-depth analysis detects variables and expressions whose value is
constant at compile-time and, when more efficient to do so, substitutes the constant
value for the variable access or expression evaluation.
The compiler is also designed to help you more quickly write correct programs by detecting a variety
of logic errors and other potential problems in the code.
For example, the compiler issues a warning when it detects:
- failure to set the return value in all paths through a function
- failure to set the value of a variable before its use
- definition of a data item that obscures an existing data item
- conditional expressions that are constant at compile-time
- a subroutine or function that will never return to its caller
- a reference to an array outside of its defined bounds
- a Case expression that is subsumed in an earlier case expression
- Case code that can never be selected
Finally, the compiler's advanced optimizer detects special cases where it can generate smaller or faster
code than would be suggested by the code as written. For example:
- employing a "reduction in strength" such as replacing multiplication by a power of two
with left shift or replacing a squaring operation with self-multiplication
- using mathematical or logical identities to simplify an expression
- rearranging an expression for more efficient evaluation
- replacing a sequence of operations by a shorter equivalent
For multi-tasking applications, the ZBasic compiler also includes a sophisticated static analysis
capability that provides information on each task's stack use.
You won't need to guess how much stack space should be allocated to your tasks and it will warn
you if insufficient space is being allocated.
The ZBasic compiler is a command-line utility (console application) that runs on Windows 2000, Windows XP or later versions.
Although you can invoke it manually, it is more commonly invoked automatically by the
Integrated Development Environment (IDE)
to compile your ZBasic project.
Alternately, you can launch the compiler and downloader from your favorite editor or IDE if it has the ability to be so configured.
Advanced Native Mode Features
For the ZX native mode devices, the ZBasic compiler produces optimized native machine code that
is directly executed by the ZX microcontroller. This provides the highest execution speed allowing
you to tackle more demanding and sophisticated applications. For advanced programmers using native
mode ZX devices, ZBasic provides the ability to define customized interrupt service routines and to
use inline assembly language or C code when the situation calls for it. ZBasic even allows you to
create and/or utilize object code libraries or pre-compiled modules.
Online Documentation and Installer
You may use the following links to view the ZBasic Language Reference Manual
and ZBasic System Library Reference Manual online.
Also, visit the Download Page to get the
installer, PDF-format documentation, firmware updates and other free downloads.