how to program in assembly in mikroC?

General discussion on mikroC.
Post Reply
Author
Message
coffeecuppepsi
Posts: 1
Joined: 20 Apr 2010 13:50

how to program in assembly in mikroC?

#1 Post by coffeecuppepsi » 12 Nov 2010 03:21

how can i access general registers in mikroC?
e.g. this does not work clrf 6;
but this does clrf portb;
it's ok for special registers because they have names... but how do i access general register??

User avatar
tihomir.losic
mikroElektronika team
Posts: 2138
Joined: 02 Dec 2009 14:16
Location: Serbia
Contact:

Re: how to program in assembly in mikroC?

#2 Post by tihomir.losic » 14 Nov 2010 13:57

Hello,

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

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

Code: Select all

asm {
  block of assembly instructions
}
There are two ways to embeding single assembly instruction to C code:

Code: Select all

asm assembly instruction;
and

Code: Select all

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:

Code: Select all

asm 
  {
  block of assembly instructions
  }
This code will be interpreted as single empty asm line followed by C compound statement.

The mikroC PRO for PIC 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:

Code: Select all

MOVF    _g_var+0, 0     ;puts least-significant byte of g_var in W register
MOVF    _g_var+1, 0     ;second byte of _g_var; corresponds to Hi(g_var)
MOVF    _g_var+2, 0     ;Higher(g_var)
MOVF    _g_var+3, 0     ;Highest(g_var)
... etc.
If you want to know details about asm syntax supported by mikroC PRO for PIC it is recomended to study asm and lst files generated by compiler.

Best regards,
mikroElektronika [Support team]

Post Reply

Return to “mikroC General”