asm Declaration

The mikroC PRO for AVR 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 AVR and have the same meaning.

Assembly instructions can be grouped by the asm keyword (or _asm, or __asm):

asm {
  block of assembly instructions
}

There are two ways to embeding single assembly instruction to C code:

asm assembly instruction;

and

asm assembly instruction

Semicolon and LF are terminating asm scope for single assembly instructions. This is the reason why the following syntax is not asm block:

asm 
  {
  block of assembly instructions
  }

This code will be interpreted as single empty asm line followed by C compound statement.

The mikroC PRO for AVR comments (both single-line and multi-line) are allowed in embedded assembly code.

if you have a global variable "g_var", that is of type long (i.e. 4 bytes), you are to access it like this:

STS  _g_var+0, 27     ;puts least-significant byte of g_var in R27 GPR register
STS  _g_var+1, 27     ;second byte of _g_var; corresponds to Hi(g_var)
STS  _g_var+2, 27     ;Higher(g_var)
STS  _g_var+3, 27     ;Highest(g_var)
... etc.

If you want to know details about asm syntax supported by mikroC PRO for AVR it is recomended to study asm and lst files generated by compiler. It is also recomended to check "Include source lines in output files" checkbox in Output settings

Copyright (c) 2002-2012 mikroElektronika. All rights reserved.
What do you think about this topic ? Send us feedback!
Want more examples and libraries? 
Find them on LibStock - A place for the code