NXC Version 1.2.1 r5
The asm statement is used to define many of the NXC API calls.
The syntax of the statement is shown below.
The statement simply emits the body of the statement as NeXT Byte Codes (NBC) code and passes it directly to the NBC compiler's backend. The asm statement can often be used to optimize code so that it executes as fast as possible on the NXT firmware. The following example shows an asm block containing variable declarations, labels, and basic NBC statements as well as comments.
A few NXC keywords have meaning only within an asm statement. These keywords provide a means for returning string or scalar values from asm statements and for using temporary variables of byte, word, long, and float types.
|__RETURN__, RETURNS||Used to return a signed value other than RETVAL or STRRETVAL|
|__RETURNU__||Used to return an unsigned value.|
|__RETURNF__||Used to return a floating point value.|
|__RETVAL__||Writing to this 4-byte signed value returns it to the calling program|
|__GENRETVAL__||Writing to this generic value returns it to the calling program|
|__URETVAL__||Writing to this 4-byte unsigned value returns it to the calling program|
|__STRRETVAL__||Writing to this string value returns it to the calling program|
|__FLTRETVAL__||Writing to this 4-byte floating point value returns it to the calling program|
|__STRBUFFER__||This is primary string buffer which can be used to store intermediate string values.|
|__STRTMPBUFFER__||This is a secondary string buffer.|
|__TMPBYTE__||Use this temporary variable to write and return single byte signed values|
|__TMPWORD__||Use this temporary variable to write and return 2-byte signed values|
|__TMPLONG__||Use this temporary variable to write and return 4-byte signed values|
|__TMPULONG__||Use this temporary variable to write and return 4-byte unsigned values|
|__TMPFLOAT__||Use this temporary variable to write and return 4-byte floating point values|
|__I__||A local counter variable|
|__J__||A second local counter variable|
|__IncI__||Increment the local counter variable named I|
|__IncJ__||Increment the local counter variable named J|
|__DecI__||Decrement the local counter variable named I|
|__DecJ__||Deccrement the local counter variable named J|
|__ResetI__||Reset the local counter variable named I to zero|
|__ResetJ__||Reset the local counter variable named J to zero|
|__THREADNAME__||The current thread name|
|__LINE__||The current line number|
|__FILE__||The current file name|
|__VER__||The product version number|
The asm block statement and these special ASM keywords are used throughout the NXC API. You can have a look at the NXCDefs.h header file for several examples of how they are used. To keep the main NXC code as "C-like" as possible and for the sake of better readability NXC asm block statements can be wrapped in preprocessor macros and placed in custom header files which are included using #include. The following example demonstrates using a macro wrapper around an asm block.