Download NQC Programmer`s Guide

Transcript
NQC Programmer's Guide
NQC provides a special operator to represent a data source:
@ c on st an t
The value of this expression is the data source described by the constant. The lower 16
bits of the constant represent the data value, and the next 8 bits are the source code. For
example, the source code for a random number is 4, so the expression for a random
number between 0 and 9 would be:
@ 0x 40 00 9
The NQC API file defines a number of macros which make the use of the @ operator
transparent to the programmer. For example, in the case of random numbers:
# de fi ne R an do m( n) @( 0x 40 00 0 + (n ))
Note that since source 0 is the global variable space, the global storage locations can be
referenced by number: @0 refers to storage location 0. If for some reason you need
explicit control over where variables are being stored, then you should use #pragma
reserve to instruct NQC not to use those storage locations, and then access them
manually with the @ operator. For example, the following code snippet reserves location
0 and creates a macro for it called x .
# pr ag ma r es er ve 0
# de fi ne x ( @0 )
Page 58