Tuesday, November 18, 2008

    PIC32 Assembler Directives that Control Code Generation

    When inspecting MPLAB Assembler for PIC32 MCUs (pic32-as) source code, you may have noticed some new assembler directives such as .set noat and .set nomacro. These directives are specific to PIC32 MCUs and affect the way that pic32-as assembles your code.

    The following excerpt from the upcoming MPLAB Assembler, Linker, and Utilities for PIC32 MCUs User’s Guide describes these new directives.

    .set noat

    When synthesizing some address formats, pic32-as may require a scratch register. By default, the assembler will quietly use the at ($1) register, which is reserved as an assembler temporary by convention. In some cases, we don't want the compiler to use that register. The .set noat directive prevents the assembler from quietly using the at register.

    .set at

    Allow the assembler to quietly use the at ($1) register.

    .set noautoextend

    By default, MIPS16 instructions are automatically extended to 32 bits when necessary. The directive .set noautoextend will turn this off. When .set noautoextend is in effect, any 32-bit instruction must be explicitly extended with the .e modifier (e.g., `li.e $4,1000'). The directive .set autoextend may be used to once again automatically extend instructions when necessary.

    .set autoextend

    Enable auto-extension of MIPS16 instructions to 32 bits.

    .set nomacro

    The assembler supports synthesized instructions, an instruction mnemonic that synthesizes into multiple machine instructions. For instance, the sleu instruction assembles into an sltu instruction and an xori instruction. The .set nomacro directive causes the assembler to emit a warming message when an instruction expands into more than one machine instruction.

    .set macro

    Suppress warnings for synthesized instructions.

    .set mips16e

    Assemble with the MIPS16e ISA extension.

    .set nomips16e

    Do not assemble with the MIPS16e ISA extension.

    .set noreorder

    By default, the assembler attempts to fill a branch or delay slot automatically by reordering the instructions around it. This feature can be very useful.

    Occasionally, you'll want to retain precise control over your instruction ordering. Use the .set noreorder directive to tell the assembler to suppress this feature until it encounters a .set reorder directive.

    .set reorder

    Allow the assembler to reorder instructions to fill a branch or delay slot.

    1 comment:

    Anonymous said...

    Good article.

    It might be useful to point out that the assembler directives that you list are not specific to the PIC32 MCU but are a standard feature of most MIPS assemblers. That is, MIPS assemblers require either these directives or some similar directives to achieve the same purposes due to the architecture of MIPS CPUs.