asm Declaration

The mikroC PRO for 8051 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 8051 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
}

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

asm assembly instruction;

and

asm assembly instruction

Note: 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 8051 comments (both single-line and multi-line) are allowed in embedded assembly code.

Accessing individual bytes is different as well. For example, a global variable "g_var" of type long (i.e. 4 bytes) can be accessed like this:

    MOV _g_var+0, #1  ;puts 1 in low byte of g_var
    MOV _g_var+1, #2  ;puts 2 in high byte of g_var
    MOV _g_var+2, #3  ;puts 3 in higher byte of g_var
    MOV _g_var+3, #4  ;puts 4 in highest byte of g_var
    ... etc.

If you want to know details about asm syntax supported by mikroC PRO for 8051 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-2013 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