6.1.9.2 Asmopt Directive

The ASMOPT action directive selectively controls the assembler optimizer when processing assembly code. The allowable actions are shown in Table 6-7.

Table 6-7. Asmopt Actions
Action Purpose
off Disables the assembler optimizer for subsequent code.
on Enables the assembler optimizer for subsequent code.
pop Retrieves the state of the assembler optimization setting.
push Saves the state of the assembler optimization setting.

No code is modified after an ASMOPT off directive. Following an ASMOPT on directive, the assembler will perform allowable optimizations.

The ASMOPT push and ASMOPT pop directives allow the state of the assembler optimizer to be saved onto a stack of states and then restored at a later time. They are useful when you need to ensure the optimizers are disabled for a small section of code, but you do not know if the optimizers have previously been disabled.

For example:
ASMOPT PUSH  ;store the state of the assembler optimizers
ASMOPT OFF   ;optimizations must be off for this sequence
movlw 0x55
movwf EECON2
movlw 0xAA
movwf EECON2
ASMOPT POP   ;restore state of the optimizers