troubles embedding asm in C code

General discussion on mikroC.
Post Reply
Author
Message
BlackBird
Posts: 6
Joined: 22 Jun 2010 22:19

troubles embedding asm in C code

#1 Post by BlackBird » 20 Aug 2010 04:42

Hi guys,

Look at that simple code: :D

Code: Select all

//***************************
unsigned short Cont1, Cont2;  // Global vars
void main(void);
void Retardo1(void);

void Retardo1()
{
asm { 
  MOVLW 0xFF
  MOVWF _Cont1, 1
  MOVWF Cont2, 1  }
      }
 void main()
 {
 Retardo1();
 }
The compiler returns two identical errors: :(
not found: _Cont1
not found: Cont2

So, where is the error here? Does any body knows? :shock:

According to the help explanation a global variable inside the asm code should use a "_" before variable name (_Var) and it should be declared as global in C code.
I think I did that, but it doesn't work. :?

Another question supporting my interest in embedding assembly code in MickroC code is:
I'm communicating a PC with a raw device through USB port, among functions I had used is one in wich I have to create some time delays. The interesting thing is: If I put on this function more than three instructions " Delays_ms(200);" the Raw device is not recognized by the computer (the communication at start is disrrupted) and with three or less intructions the raw device in recognized by the computer.
Look at the function:

Code: Select all

void PulsedTone()
  { Aux1=CFG2;
    Aux1=Aux1 & 0x07;
    if (Aux1!=0)
       {
        Vdelay_ms(2000);
        Vdelay_ms(1000);
        Vdelay_ms(60);
        Vdelay_ms(1000);  <--- this is the critical call, no mather if you use Delay_ms or other related (I need to put 6 calls)
        }
            dBL=0x0; dBR=0x0;   // Mute Channels
            Set_dB();
   }
I think if I tray to write an own delay function in asm it would work without troubles. isn't it?

kind regards

Edited by Administratro: Added Code Tag!

BlackBird
Posts: 6
Joined: 22 Jun 2010 22:19

Re: troubles embedding asm in C code

#2 Post by BlackBird » 21 Aug 2010 20:26

Hi guys,

I'm answering my own post:

I've found the errors related to "embedding asm on mikroC code".
It's so simple (after I have broke my head for about 2 hours)
All you have to do is a dummy use of variables just once.
Ex:

Code: Select all

unsigned short Cont1, Cont2   ( global declaration)

void main() {
 Cont1= Cont1;  // Dummy use     :shock: 
 Cont2= Cont2;  // Dummy use      :shock: 
 Myasm();     // call to my asm function

}
.......
Myasm()
{
MOVLW 0xFF
MOVW _Cont1, 1
MOVW _Cont2, 1
...
...
}
That's all folks!! :mrgreen:

Edited by Administrator: Added Code Tag!

Post Reply

Return to “mikroC General”