System & Program Control

Overview

The SYS interface provides access to system-level program control, hardware detection, scheduling, and timing services.

Unlike native CPU instructions, SYS verbs are handled by the system controller through the EXT bus. Programs may use them to launch or queue programs, inspect available peripheral interfaces, suspend execution, and configure the system clock.

Like other EXT operations, a synchronous SYS call completes before execution continues with the next instruction.


System constants

The system provides built-in constants containing information about the current system and program invocation.

#SYS.UUID — System UUID

#SYS.UUID

Contains the UUID of the NCS/e system running the program.

The value is a lowercase version 4 UUID including hyphens.

For example:

550e8400-e29b-41d4-a716-446655440000

The UUID identifies the system itself.


#THIS — Current Program

#THIS

Contains the exact program path used to launch the current program invocation.

It may be used when a program needs to invoke or queue itself again:

SYS.NEXT #THIS :return

#0–#15 — Program Arguments

#0
#1
...
#15

Contain the arguments supplied when the current program invocation was launched.

Arguments are stored as strings.

For example:

SYS.RUN "FIB" 0 15 "Hello"

The launched program receives:

#0 = "15"
#1 = "Hello"

Hardware detection

The system maintains a list of namespaces provided by initialized peripherals and expansion hardware.

Programs may inspect this list using SYS.HW.

SYS.HW — Check Hardware

SYS.HW <dst> <namespace>

Checks whether a peripheral namespace is currently available.

Operands

Position Name Type Range Description
1 dst Location — Destination for the result.
2 namespace String value — Peripheral namespace to check.

Modified locations

Location Description
dst 1 if the namespace exists, otherwise 0.

Examples

Check whether a Display interface is available:

SYS.HW $000 "D"
-- > $000 = 1 if the D namespace exists
-- > $000 = 0 otherwise

Conditionally use the Display:

SYS.HW $000 "D"
BEQ :noDisplay $000 0

D.TXT "Display detected."
D.BLT

:noDisplay

Notes

  • SYS.HW checks for an available namespace, not a particular physical implementation of a device.
  • Compatible hardware may provide the same namespace as standard NCS/e hardware.
  • The namespace is specified without a trailing ..

Program execution

SYS.RUN, SYS.QUEUE, and SYS.NEXT use the same program invocation format:

SYS.<verb> <program> <entrypoint> [arg...]

The program path is followed by an entrypoint and up to 16 optional arguments.

Entrypoints

An entrypoint specifies the program line where the new invocation begins.

Entrypoints may be supplied using line numbers, labels, or relative line references.

Labels and relative line references in the current program are resolved to absolute program line numbers during the pre-pass.

SYS.RUN "TOOLS" 50
-- > Starts at line 50

SYS.NEXT #THIS :return
-- > :return is resolved to its program line

SYS.NEXT #THIS @2
-- > @2 is resolved relative to the current program line

An entrypoint of 0 selects the program's default entrypoint.

Arguments

Up to 16 arguments may be passed after the entrypoint.

Arguments are stored as strings in the launched program and are available as constants #0 through #15.

Integer values are converted to their string representation before being passed.

SYS.RUN "FIB" 0 15 "Hello"

The launched program receives:

#0 = "15"
#1 = "Hello"

The special constant #THIS contains the program path used to launch the current invocation. It may be used when a program needs to invoke or queue itself again.


SYS.RUN — Run Program

SYS.RUN <program> <entrypoint> [arg...]

Terminates the current program and immediately starts another program.

Operands

Position Name Type Range Description
1 program String value — Program path to run.
2 entrypoint Branch target — Starting program line.
3–18 arg... String value — Optional program arguments.

Modified locations

This operation does not directly modify any locations.

Examples

Run a program at its default entrypoint:

SYS.RUN "CHESS" 0

Start a program at a specific line:

SYS.RUN "TOOLS" 50
-- > Starts TOOLS at line 50

Pass arguments to a program:

SYS.RUN "FIB" 0 15
-- > FIB receives #0 = "15"

Notes

  • The current program does not resume after SYS.RUN.
  • Starting another program creates a new program invocation with new CPU state.

SYS.QUEUE — Queue Program

SYS.QUEUE <program> <entrypoint> [arg...]

Adds a program to the back of the execution queue.

Operands

Position Name Type Range Description
1 program String value — Program path to queue.
2 entrypoint Branch target — Starting program line.
3–18 arg... String value — Optional program arguments.

Modified locations

This operation does not modify any locations.

Examples

Add programs to the back of the queue:

SYS.QUEUE "FIB" 0 45
SYS.QUEUE "FIB" 0 46
SYS.QUEUE "FIB" 0 47
-- > Programs run in the order they were queued

Notes

  • SYS.QUEUE does not interrupt the currently running program.
  • Programs are added to the back of the execution queue.

SYS.NEXT — Queue Program Next

SYS.NEXT <program> <entrypoint> [arg...]

Adds a program to the front of the execution queue, causing it to run before programs already waiting in the queue.

Operands

Position Name Type Range Description
1 program String value — Program path to queue.
2 entrypoint Branch target — Starting program line.
3–18 arg... String value — Optional program arguments.

Modified locations

This operation does not modify any locations.

Examples

Add two programs normally, then insert another ahead of them:

SYS.QUEUE "SECOND" 0
SYS.QUEUE "THIRD" 0

SYS.NEXT "FIRST" 0

-- > Queue order:
-- > FIRST
-- > SECOND
-- > THIRD

Queue another invocation of the current program:

SYS.NEXT #THIS :return "Welcome back!"

-- Work...

:return

A relative reference may be used to continue at a nearby line:

SYS.NEXT #THIS @2 "Welcome back!"
SYS.RUN "A:/OTHER.NCL" 0

-- A new invocation begins here.
D.TXT #0

Notes

  • SYS.NEXT does not interrupt the currently running program.
  • Programs added with SYS.NEXT take priority over programs already waiting in the queue.
  • Repeated SYS.NEXT calls insert at the front, so the most recently added invocation runs first.
  • Labels and relative references are resolved during the current program's pre-pass before being supplied as entrypoints.

Timing

System timing operations control when program execution continues and how quickly the CPU advances between execution cycles.

SYS.WAIT — Wait Cycles

SYS.WAIT <cycles>

Suspends program execution for the specified number of CPU cycles.

Operands

Position Name Type Range Description
1 cycles Integer value ≥ 0 Number of cycles to wait.

Modified locations

This operation does not modify any locations.

Examples

-- Wait for 10 CPU cycles.
SYS.WAIT 10

Notes

  • SYS.WAIT is measured in CPU cycles, not seconds.
  • The amount of real time represented by a cycle depends on the current CPU clock rate.
  • SYS.CLOCK therefore affects the approximate real-time duration of SYS.WAIT.

SYS.SLEEP — Sleep

SYS.SLEEP <seconds>

Suspends program execution for at least the specified number of seconds.

Operands

Position Name Type Range Description
1 seconds Integer value ≥ 0 Minimum number of seconds to sleep.

Modified locations

This operation does not modify any locations.

Examples

-- Sleep for at least 5 seconds.
SYS.SLEEP 5

Notes

  • SYS.SLEEP specifies a minimum duration in seconds.
  • Execution resumes on a subsequent CPU cycle after the requested duration has elapsed.
  • The configured clock rate can therefore increase the effective sleep duration.
  • For example, with SYS.CLOCK 10000, SYS.SLEEP 1 may effectively pause execution for about 10 seconds.

SYS.CLOCK — Clock Rate

SYS.CLOCK <delay>

Sets the CPU clock rate by specifying the delay, in milliseconds, between execution cycles.

Operands

Position Name Type Range Description
1 delay Integer value 50–30000 Delay between CPU cycles in milliseconds.

Modified locations

This operation does not modify any locations.

Examples

-- Run with 50 ms between cycles.
SYS.CLOCK 50

-- Run with 1 second between cycles.
SYS.CLOCK 1000

Notes

  • A smaller delay produces a faster clock; a larger delay produces a slower clock.
  • SYS.CLOCK directly affects SYS.WAIT, which is measured in CPU cycles.
  • SYS.CLOCK can indirectly extend SYS.SLEEP, because execution resumes on a CPU cycle only after the requested sleep duration has elapsed.