Download NQC Programmer`s Guide
Transcript
NQC Programmer's Guide
4 Technical Details
This section explains some of the low-level features of NQC. In general, these
mechanisms should only be used as a last resort since they may change in future releases.
Most programmers will never need to use the features described below - they are mainly
used in the creation of the NQC API file.
4.1
The asm statement
The asm statement is used to define almost all of the NQC API calls. The syntax of the
statement is:
asm { item1, item2 ... itemN }
Where an item is one of the following
constant_expression
& expression
& expression : restrictor
The statement simply emits the values of each of the items as raw bytecodes. Constant
items are the simplest - they result in a single byte of raw data (the lower 8 bits of the
constant value). For example, the API file defines the following inline function:
void ClearMessage() { asm { 0x90 }; }
Whenever ClearMessage() is called by a program, the value 0x90 is emitted as a
bytecode.
Many API functions take arguments, and these arguments must be encoded into an
appropriate effective address for the bytecode interpreter. In the most general case, an
effective address contains a source code followed by a two byte value (least significant
byte first). Source codes are explained in the SDK documentation available from LEGO.
However, it is often desirable to encode the value in some other manner - for example to
use only a single byte value after the source code, omit the source code itself, or only
allow certain sources to be used. A restrictor may be used to control how the effective
address is formatted. A restrictor is a 32 bit constant value. The lower 24 bits form a
bitmask indicating which sources are valid (bit 0 should be set to allow source 0, etc).
Page 58