asm Declaration
The mikroC PRO for PIC32 allows embedding assembly in the source code by means of the asm
declaration. The declarations _asm
and __asm
are also allowed in the mikroC PRO for PIC32 and have the same meaning. Note that numerals cannnot be used as absolute addresses for SFR or GPR variables in assembly instructions. Symbolic names may be used instead (listing will display these names as well as addresses).
Assembly instructions can be grouped by the asm
keyword (or _asm
, or __asm
):
asm { block of assembly instructions }
The mikroC PRO for PIC32 comments (both single-line and multi-line) are allowed in embedded assembly code.
The only types whose name remains the same in asm as it is in the mikroC PRO for PIC32 are registers, e.g. INTCON, PORTB, WREG, GIE, etc.
Accessing variables
Depending on the place of declaration, accessing a variable can be done in several ways :
- Accessing global variable :
1. If declared as static (visible only in the file where it was declared) :<source_file_name>_<variable_name>
.
2. If declared as a non-static global (visible throughout the whole project) :_<variable_name>
.
3. If accessing registers (declared throughregister
,rx
orsfr
specifiers, visible throughout the whole project) :<variable_name>
. - Accessing local variable :
<routine_name>_<variable_name>
. - Accessing routine parameter :
FARG_<routine_name>_<variable_name>
.
Asm code and SSA optimization
If asm code is mixed with the C code, keep in mind that the generated code can substantially differ when SSA optimization option is enabled or disabled.
This is due to the fact that SSA optimization uses certain working registers to store routine parameters (W10-W13), rather than storing them onto the function frame.
Because of this, user must be very careful when writing asm code as existing values in the working registers used by SSA optimization can be overwritten.
To avoid this, it is recommended that user includes desired asm code in a separate routine.
What do you think about this topic ? Send us feedback!