MARC4 User’s Guide
qFORTH Compiler
05.01 1
1 qFORTH Compiler
By using the MARC4 qFORTH compiler, embedded-sys-
tem designers no longer have to stick to assembly
language; the compiler generates a highly optimized
object code. The smart qFORTH compiler translates your
high-level qFORTH program into the MARC4 processors
native code. The compiler system selects the right assem-
bly-language instruction sequences and addressing
modes for optimal operation. The intermediate code
passes through rule-based expert systems at different
optimization stages. This code is optimized for local cen-
ters of reference (colon definitions, macros, loops) to
minimize stack operations and register references; it actu-
ally scoreboards register references to eliminate
redundancies.
The qFORTH compiler supports standard FORTH
constructs such as: BEGIN .. AGAIN, BEGIN .. UNTIL,
CASE .. ENDCASE, DO .. LOOP, IF .. THEN, IF .. ELSE
.. THEN, BEGIN .. WHILE .. REPEAT, and the following
4-bit and 8-bit data types: constants, variables, arrays and
8-bit ROM look-up tables. qFORTH extensions are inter-
rupt functions, direct I/O port access, in-line assembly
language and direct register access. The compiler also
generates a line-number reference file to support source-
code debugging in the MARC4 simulator and emulator.
The compiler is available in two versions. The fully inte-
grated version is run by selecting ’Compile’ in the menu
bar of the MARC4 integrated environment menu and the
command-line version is run by typing QFORTH2,
followed by options and the name of the file to be com-
piled at the DOS command line.
1.1 The qFORTH Program
Structure
In order to compile your qFORTH program correctly, the
compiler expects the program to be composed of direc-
tives, definitions and statements. Most qFORTH
programs will contain at least a group of statements which
will perform computational operations. These statments
are edited according to the guidelines outlined in the
qFORTH Programmer ’s Guide. Whether or not you add
compiler directives and CONSTANT definitions is
dependant on the requirements of your program. They are
more or less optional when compiling a qFORTH pro-
gram. Parameters are expected by the compiler, but not
defined by the programmer. The compiler will substitute
default values such as for stack size allocation.
At the end of this chapter you will find a section which
lists the default values used by the qFORTH compiler . B u t
first it is necessary to re-examine what the three sections
are which make up a qFORTH program.
1.1.1 Compiler Directives
The directives are compiler switches used to control the
way in which your program is compiled and to specify the
format of your compiler generated file(s). The majority
of the directives can be implemented as in-line com-
mands appearing at the beginning of your program code.
1.1.2 Definitions
The CONSTANT and VARIABLE definitions which are
values referenced by your program via names. They
should be assigned before the CONSTANT or
VARIABLE is referenced within the program.
1.1.3 Statements
A qFORTH program is composed of various statements
grouped together to perform a particular task which your
program invokes via a word. These words are called colon
definitions because they appear in your qFORTH pro-
gram as starting with a colon (‘:’), followed by a space
and the name assigned to these group of statements. A
statement group is a sequential list of MARC4 instruc-
tions, words found in the qFORTH system library or
words which have been defined in your program before
invoking this subroutine.
Note: All colon-definitions end with a semi-colon (‘;’).
Sequences of functionally grouped words are called
modules. Modules used to perform the underlying
computational tasks of the MARC4 are often caused by
interrupt service routines. These are predefined names
according to the naming conventions described in the
qFORTH Programmer’s Guide and are identified by ‘:
INT<x>’, whereby <x> is replaced by the priority
number 0 to 7.
The program entry point is identified as the $RESET ser-
vice routine since it is the first word which the MARC4
processor will execute after power-on reset. Normally,
this colon definition is located at the end of your source
program and consists of two parts: the register and the
application initialization section. After the initialization
of the stack pointers, the on-chip peripherals and the
RAM variables of the application have to be put in a well-
defined state.
1.1.4 Kicking the Assembler Habit
This short description has been intended as an overview
to program composition as required by the qFORTH com-
piler.