Symbols

Symbols allow operands and program lines to be given meaningful names in NCL source. They make programs easier to read and modify without introducing additional runtime state.

Symbols are resolved during the program pre-pass. By the time execution begins, symbolic references have been replaced with the values or program line numbers they represent.

Constants

Constants provide names for operands.

A constant is defined with a name beginning with #, followed by its value:

#COUNT $000
#LIMIT 10
#MESSAGE "Hello!"

The definition may appear alone:

#COUNT $000
MOVE #COUNT 10

or alongside instructions on a coalesced program line:

#COUNT $000; MOVE #COUNT 10

Each reference to a constant is replaced with its defined operand:

#COUNT $000
#LIMIT 10

MOVE #COUNT #LIMIT

becomes:

MOVE $000 10

Forward References

Constants are collected before substitution, so a constant may be referenced before its definition:

MOVE $000 #LIMIT

#LIMIT 10

An undefined constant is a fatal pre-pass error and prevents the program from executing.

Redefining Constants

A constant may be defined more than once.

When the same name has multiple definitions, the last definition takes precedence throughout the entire program:

#VALUE 10
MOVE $000 #VALUE

#VALUE 20
MOVE $001 #VALUE

Both references resolve to 20:

MOVE $000 20

MOVE $001 20

Constant definitions therefore do not take effect sequentially.

Constant Substitution

A constant represents one complete operand.

Substitution occurs once. The resulting operand is not processed again for additional constant references:

#foo #bar
MOVE $000 #foo

becomes:

MOVE $000 #bar

Constants may contain indirect memory references:

#TOP [sp]
MOVE $000 #TOP

which becomes:

MOVE $000 [sp]

Constants are not substituted inside indirect memory references:

#PTR $000
MOVE $001 [#PTR]

#PTR is not resolved in this form.

See Memory & Stack for indirect addressing.

Built-in Constants

NCL provides built-in constants for values defined by the language and system interfaces.

The standard boolean constants are:

Constant Value Description
#FALSE 0 False.
#TRUE 1 True.

NCL does not have a separate boolean data type. Boolean values are represented using integers:

MOVE $000 #TRUE
-- > $000 = "1"

Additional constants may be provided by system interfaces, coprocessors, expansion modules, and peripherals.

Built-in constants follow the same substitution rules as other constants.

Labels

Labels provide names for program lines.

A label begins with : and represents the number of the program line containing it:

:loop

Labels may appear alone on a line:

:loop
DEC $000
BNEQ :loop $000 0

Here, :loop refers to the otherwise empty line containing the label.

A label may instead appear alongside an instruction:

:loop DEC $000
BNEQ :loop $000 0

Here, :loop refers to the line containing DEC.

Labels may also appear anywhere within a coalesced program line:

D.TXT "."; :loop DEC $000; BNEQ :loop $000 0

The label still represents the complete program line. It does not identify an individual instruction within that line.

Labels may be referenced before their definitions:

JUMP :start

MOVE $000 100

:start MOVE $000 42

If a label is defined more than once, the last definition takes precedence throughout the program.

An undefined label is a fatal pre-pass error and prevents the program from executing.

Relative Line References

Relative line references identify program lines by their position relative to the line containing the reference.

They begin with @ followed by an offset:

@0
@1
@-1

@0 refers to the current line, @1 to the following line, and @-1 to the preceding line.

For example:

DEC $000
BNEQ @-1 $000 0

The BNEQ branches to the preceding line while $000 is non-zero.

Relative references operate on complete program lines. Coalesced instructions do not receive individual line numbers:

INC $000; BLT @0 $000 10

Here, @0 refers to the line containing both instructions. When the branch is taken, execution returns to the beginning of the line and executes INC again.

Relative line references are converted to absolute program line numbers during the program pre-pass.