BASIC09 is a structured
BASIC programming language
BASIC (Beginners' All-purpose Symbolic Instruction Code) is a family of General-purpose programming language, general-purpose, high-level programming languages designed for ease of use. Dartmouth BASIC, The original version was created by John ...
dialect developed by
Microware
Microware Systems Corporation was an American software company based in Clive, Iowa, that produced the OS-9 real-time operating system.
Microware Systems Corporation existed as a separate entity from 1977 until September 2001, when it was bought ...
on behalf of
Motorola
Motorola, Inc. () was an American Multinational corporation, multinational telecommunications company based in Schaumburg, Illinois, United States. After having lost $4.3 billion from 2007 to 2009, the company split into two independent p ...
for the then-new
Motorola 6809
The Motorola 6809 ("''sixty-eight-oh-nine''") is an 8-bit microprocessor with some 16-bit features. It was designed by Motorola's Terry Ritter and Joel Boney and introduced in 1978. Although source compatible with the earlier Motorola 6800, the 6 ...
CPU and released in February 1980. It is primarily used with the
OS-9
OS-9 is a family of real-time, process-based, multitasking, multi-user operating systems, developed in the 1980s, originally by Microware Systems Corporation for the Motorola 6809 microprocessor. It was purchased by Radisys Corp in 2001, and ...
operating system
An operating system (OS) is system software that manages computer hardware, software resources, and provides common services for computer programs.
Time-sharing operating systems schedule tasks for efficient use of the system and may also in ...
, released in 1979. Microware also released a version for OS-9/68k on the
68000
The Motorola 68000 (sometimes shortened to Motorola 68k or m68k and usually pronounced "sixty-eight-thousand") is a 16/32-bit complex instruction set computer (CISC) microprocessor, introduced in 1979 by Motorola Semiconductor Products Secto ...
as Microware BASIC.
In contrast to typical BASICs of the era, BASIC09 includes a multi-pass
compiler
In computing, a compiler is a computer program that translates computer code written in one programming language (the ''source'' language) into another language (the ''target'' language). The name "compiler" is primarily used for programs that ...
that produces compact
bytecode
Bytecode (also called portable code or p-code) is a form of instruction set designed for efficient execution by a software interpreter. Unlike human-readable source code, bytecodes are compact numeric codes, constants, and references (norma ...
known as I-code. I-code replaces a number of data structures found in other BASICs with direct pointers to code and values, speeding performance. Users can further compile code using the
PACK
command, at which point it can be called directly by OS-9 and operated as native code. In the case of PACKed code, a cut-down version of the BASIC09
runtime system
In computer programming, a runtime system or runtime environment is a sub-system that exists both in the computer where a program is created, as well as in the computers where the program is intended to be run. The name comes from the compile t ...
is used, Runb, further improving memory footprint and load time.
The language includes a number of
structured programming
Structured programming is a programming paradigm aimed at improving the clarity, quality, and development time of a computer program by making extensive use of the structured control flow constructs of selection ( if/then/else) and repetition ( ...
additions, including
local variable
In computer science, a local variable is a Variable (programming), variable that is given ''local scope (programming), scope''. A local variable reference in the subroutine, function or block (programming), block in which it is declared overrides ...
s, the ability to ignore line numbers in favor of named routines, user-defined structures, and several distinct base data types including 16-bit and 8-bit (byte) integers, in addition to floating point and strings.
Syntax
Program organization
A key difference between BASIC09 and conventional BASICs of the era, like the canonical
Microsoft BASIC
Microsoft BASIC is the foundation software product of the Microsoft company and evolved into a line of BASIC interpreters and compiler(s) adapted for many different microcomputers. It first appeared in 1975 as Altair BASIC, which was the first ve ...
, is the addition of the
PROCEDURE
structure which created separately executable blocks of code. Code in a
PROCEDURE
had more in common with complete programs in other BASICs, including the variables being
local
Local may refer to:
Geography and transportation
* Local (train), a train serving local traffic demand
* Local, Missouri, a community in the United States
* Local government, a form of public administration, usually the lowest tier of administrat ...
to the code, and their ability to be executed in a stand-alone fashion.
PROCEDURE
s were called by name using the
RUN
command, and could include variables for function-call semantics; for instance,
RUN add(4,7)
calls a procedure named
add
that takes two parameters. Parameters were imported into the procedure using the
PARAM
keyword, in this example
PARAM a,b
:
PROCEDURE add
PARAM a,b
PRINT a+b
A side-effect of the use of named procedures is that the resulting memory workspace is, in effect, its own namespace. In this respect, the BASIC09 system appears to the user to be a directory of callable programs. This contrasts with typical BASICs, where only one program is available at a given time and the construction of larger programs calling library-like code generally requires the
source code
In computing, source code, or simply code, is any collection of code, with or without comments, written using a human-readable programming language, usually as plain text. The source code of a program is specially designed to facilitate the wo ...
to be copied and pasted between separate programs. In BASIC09, the user can
LOAD
procedures by name into the workspace and then call them from their own code to construct larger programs from the separately stored procedures.
In addition to code in the workspace, if the program invokes
RUN
with a procedure name that could not be found, it would then look for a disk file with the same name and load and run that file. This worked not only with BASIC09 code, but also any other executable program, including
machine language
In computer programming, machine code is any low-level programming language, consisting of machine language instructions, which are used to control a computer's central processing unit (CPU). Each instruction causes the CPU to perform a very ...
files. This meant that BASIC09 could easily call system routines.
In addition to
RUN
, other common BASIC commands likewise used names. For instance,
LIST bob
would print out the source code ("list") the procedure named "bob", while
LIST*
prints out all of the procedures currently in memory. The prettyprinted output from
LIST
could be redirected to a file or a printer with a shell-like notation, e.g.
LIST bob >/p
. One could also
SAVE
and
LOAD
procedures from storage.
Structured programming
In addition to the organizational properties of the
PROCEDURE
, BASIC09 also included a number of extensions to the
flow control statements found in BASIC to provide more structure. For instance, the
IF
statement could be used in the traditional
IF
...
THEN
format on a single line, or it could be used in a structured multi-line format:
IF x>10 THEN
PRINT "x is larger than 10"
ELSE
PRINT "x is smaller than 10"
ENDIF
FOR/NEXT
loops naturally have a structured format as the
NEXT
can be placed on any line, but BASIC09 also added
WHILE/ENDWHILE
and
REPEAT/UNTIL
for additional clarity when working with non-indexed loops. It also included the center-exit
LOOP/ENDLOOP
which used the
EXITIF
statement for testing anywhere in the loop's body.
Data types
BASIC09 included several built-in data types. In addition to the traditional string (STRING) and 40-bit floating point (REAL) types found in most BASICs of the era, it also included the 16-bit signed INTEGER, the 8-bit unsigned BYTE, and the logical BOOLEAN type. The BOOLEAN types were not
packed
Data structure alignment is the way data is arranged and accessed in computer memory. It consists of three separate but related issues: data alignment, data structure padding, and packing.
The CPU in modern computer hardware performs reads and ...
into bytes, a single BOOLEAN used an entire 8-bit byte to store a single value. The language provided separate bytewise
boolean operators for bitwise operations on BYTEs and INTEGERs. In contrast to other BASICs that also operated different base types, BASIC09 did not "decorate" the variable name to indicate the type, and instead used the
DIM
for definitions; for instance,
DIM a,b:BOOLEAN
to declare two BOOLEAN variables, or
DIM c(5):INTEGER
for an array of five INTEGERs.
Additionally, BASIC09 included the
TYPE
keyword, which allowed compound types to be defined, with each "element" listed on a single line separated by semicolons. For instance:
TYPE employee_record=name:STRING;number(2):INTEGER;former:BOOLEAN
defines an employee record type named
employee_record
with three elements,
name
,
number
and
former
. The employee_record type can now be used in a definition like any other type, for instance,
DIM employees(100):employee_record
, which defines an array of 100 employee_record's. The elements are accessed in code using dot notation, for instance,
employees(50).name="Bob"
.
Runtime
Editing
Line numbers were used in most BASIC dialects primarily as a way to support the editor. Users would edit particular lines of code by typing a number, with the text following either adding to or replacing the lines already in memory. As every line of code had a number, this also made them suitable for indicating the target of a
GOTO
or
GOSUB
, compared to other languages like
FORTRAN where a separate "line label" was used for this purpose.
BASIC09 did not normally use line numbers, so its editor had to be modified to allow the user to edit lines without referring to them by number. However, BASIC09 did not assume any sort of full-screen capability, so using
cursor keys
Arrow keys or cursor movement keys are buttons on a computer keyboard that are either programmed or designated to move the cursor in a specified direction.
The term "cursor movement key" is distinct from "arrow key" in that the former term may ...
was not an option. Instead, the system had a separate editor prompt and allowed the user to move about using the and keys, moving forward or backward one line at a time. To insert a new line of code without a line number, the user left a blank at the start of the statement.
Note that the language is
case sensitive
Case or CASE may refer to:
Containers
* Case (goods), a package of related merchandise
* Cartridge case or casing, a firearm cartridge component
* Bookcase, a piece of furniture used to store books
* Briefcase or attaché case, a narrow box to ...
for user-provided values like procedure and variable names, but not for keywords. Keywords typed into the editor in lower case will be shown in upper case when the program is
LIST
ed. BASIC09 allowed multiple statements on a single line of code, but used the as a separator instead of the used in most dialects. This is because it used the colon in the
:=
assignment operator, which was in addition to the normal
=
.
:=
was identical in effect to
=
, but made the difference between assignments and comparisons more obvious.
Compiler
The internal multipass compiler converts BASIC09
source code
In computing, source code, or simply code, is any collection of code, with or without comments, written using a human-readable programming language, usually as plain text. The source code of a program is specially designed to facilitate the wo ...
into a
tokenized, optimized,
bytecode
Bytecode (also called portable code or p-code) is a form of instruction set designed for efficient execution by a software interpreter. Unlike human-readable source code, bytecodes are compact numeric codes, constants, and references (norma ...
, called I-code. I-code differs from the more traditional tokenizing approach found in most BASICs in that a number of items were placed directly in memory instead of using references that then had to be looked up.
For instance, in MS-based interpreters, a variable reference in code is left in string format; the variable
VAR
would be represented in memory by the three
ASCII
ASCII ( ), abbreviated from American Standard Code for Information Interchange, is a character encoding standard for electronic communication. ASCII codes represent text in computers, telecommunications equipment, and other devices. Because of ...
characters "VAR". During execution, when this variable is encountered in the code the interpreter has to look up that string in a table of variables, find the associated storage address in memory, and then finally read the value stored in that location. The table is usually constructed so that the value follows the name, to save time during the final lookup.
In contrast, in I-code the address of the variable is determined in advance and the reference in code is replaced by that address. This avoids a runtime search through the variable table. Other optimizations include a separate
FOR/NEXT
routine used when the index variable is an INTEGER, and separate INTEGER and REAL math libraries.
For added performance, BASIC09 also included the
PACK
command which took a procedure name and returned an optimized version. Some of these optimizations included removing non-coding instructions like code comments and the replacement of constant expressions to a single value. For instance,
PACK
would recognize that
LET x=x+SQR(100)/2
contains only constants on the right, and replaces it with the code
x=x+5
, which requires only a single operation at runtime, the addition, removing the division and square root.
PACK
reduced the memory footprint of the procedure and improved performance by about 10 to 30%.
Lightweight runtime
Although it was common to run programs within the BASIC09 environment, as it was in other BASICs, BASIC09 also shipped with a separate run-only version of the code known as Runb. Runb removed the editing and debugging features of the system, and was about half the size of the full BASIC09 as a result.
The purpose of Runb was primarily to run PACKed modules when called from other programs. This meant that if the user typed in the name of a BASIC09 module in the OS/9 command line, and that module has been marked as PACKed, it is opened and run by Runb instead of the BASIC09. This reduces memory footprint and improves load time.
Significant features
* reasonably structured control flow provisions (e.g., line numbers were mainly needed for computed
GOTO
GoTo (goto, GOTO, GO TO or other case combinations, depending on the programming language) is a statement found in many computer programming languages. It performs a one-way transfer of control to another line of code; in contrast a function ca ...
, as BASIC09 did not have a switch/case statement, or computed
GOSUB
BASIC (Beginners' All-purpose Symbolic Instruction Code) is a family of general-purpose, high-level programming languages designed for ease of use. The original version was created by John G. Kemeny and Thomas E. Kurtz at Dartmouth College ...
)
* structure declaration (rare in any BASIC variant then; more common in later BASIC implementations)
* intrinsic integer and
Boolean data type
In computer science, the Boolean (sometimes shortened to Bool) is a data type that has one of two possible values (usually denoted ''true'' and ''false'') which is intended to represent the two truth values of logic and Boolean algebra. It is name ...
s
* more than two significant characters in variable names (some BASICs of the time allowed only one, many
Microsoft BASIC
Microsoft BASIC is the foundation software product of the Microsoft company and evolved into a line of BASIC interpreters and compiler(s) adapted for many different microcomputers. It first appeared in 1975 as Altair BASIC, which was the first ve ...
variants allowed only two)
* procedures with local variables (indeed, ''all'' variables in BASIC09 are local to procedures) and parameter passing by reference
* a reasonable
debugger (its only significant drawback was that one could not examine the contents of fields in structures)
* a way to interface to
machine language
In computer programming, machine code is any low-level programming language, consisting of machine language instructions, which are used to control a computer's central processing unit (CPU). Each instruction causes the CPU to perform a very ...
code, which could be passed parameters using the BASIC09 calling sequence
* automatic
prettyprint
Pretty-printing (or prettyprinting) is the application of any of various stylistic formatting conventions to text files, such as source code, markup, and similar kinds of content. These formatting conventions may entail adhering to an indentatio ...
ing of source, which enforced a standard layout and avoided the ghastly mess that was the usual appearance of a program of any size in the interpreted BASICs of the time. Programmers normally would cram as many lines together as possible to avoid line number memory overhead—not a problem in BASIC09
See also
*
COMAL
COMAL (''Common Algorithmic Language'') is a computer programming language developed in Denmark by Børge R. Christensen and Benedict Løfstedt and originally released in 1975. COMAL was one of the few structured programming languages that was a ...
was another BASIC-like language with structured programming constructs
Notes
References
Citations
Bibliography
*
*
About the Author
''Terry Ritter, ..Software...FORMERLY: Staff Engineer, Motorola MOS Division, Microcomputer Systems Design Group, Jul. 1976 - Jan. 1981. ... Architect of structured BASIC language for 6809. Software Engineer, 1979-81 .... Originator and Supervising Project Engineer -- BASIC09, 1978-80, A structured BASIC language project, with operating system OS9 and associated specifications.''
External links
September 1980, first review of OS-9 and Basic09, sent in by Tom Harmon of HHH Enterprises
Dale L. Puckett, 1985, {{ISBN, 0-918035-00-7, Cat No.: 26-3189
Package: Basic09 1.1.0 / Release Date: January 5, 2003
''This release of Basic09 for the Tandy Color Computer 1/2/3 represents the first community-based release since the discontinuation of the CoCo in the 1980s.
TRS-80 Color Computer
BASIC interpreters