Asm declaration, Mikroc – ABL electronic PIC Microcontrollers PIC16 User Manual

Page 101

Advertising
background image

asm Declaration

C allows embedding assembly in the source code by means of asm declaration.
Declarations _asm and __asm are also allowed in mikroC, and have the same
meaning. Note that you cannot use numerals as absolute addresses for SFR or
GPR variables in assembly instructions. You may use symbolic names instead
(listing will display these names as well as addresses).

You can group assembly instructions by the

asm

keyword (or

_asm

, or

__asm

):

asm

{

block of assembly instructions

}

C comments (both single-line and multi-line) are allowed in embedded assembly
code. Assembly-style comments starting with semicolon are not allowed.

If you plan to use a certain C variable in embedded assembly only, be sure to at
least initialize it in C code; otherwise, linker will issue an error. This does not
apply to predefined globals such as

PORTB

.

For example, the following code will not be compiled, as linker won’t be able to
recognize variable

myvar

:

unsigned

myvar;

void

main() {

asm

{

MOVLW 10

// just a test

MOVLW test_main_global_myvar_1

}

}

Adding the following line (or similar) above

asm

block would let linker know that

variable is used:

myvar := 0;

Note: mikroC will not check if the banks are set appropriately for your variable.
You need to set the banks manually in assembly code.

MikroElektronika: Development tools - Books - Compilers

93

page

mikroC - C Compiler for Microchip PIC microcontrollers

mikroC

making it simple...

Advertising
This manual is related to the following products: