asm instruction fails in C18 mplab

Status
Not open for further replies.

tubos

New Member
Imsk is 8 bit char type
Code:
Imsk = 255 - Imsk;		               // This works
_asm COMF Imsk,1,0 _endasm		// Invert all bits FAILS ??????

Device 18F26K22
 
COMF Imsk,1,0
That line isn't correct, COMF requires two registers the input register and the output register, you're passing it three values and two of them are literals not valid registers.
 
Last edited:
I used it as described in the datasheet:

 
I was looking at an older instruction set, my mistake, is the a bit set correctly? I have no idea how C would react to address mode chance. What assurances are there that the C compiler is storing the variable in an appropriate register that the COMF instruction can access?
 
In C18 when accessing local variables (globals are ok) you can't access them by name... you have to work out where they are in the stack

This is from the known problems section of the readme manual.. Inline Assembly (C18-90 / 22170)

Code:
 #include <p18f452.h>

  void assignlocals( void )
  {
    auto char a, b;

    _asm

    // correctly assigns TMR0L to variable 'a'
    movlw a
    movff TMR0L, PLUSW2

    // DOES NOT correctly assign TMR0L to variable 'b'
    movff TMR0L, b

    _endasm
  }
 
Thank you that makes a lot of sense now.
Would have been nice if It generated an error.
I wasted a lot of time with this error.
Thanks for pointing that out.
 
Last edited:
This is what happens when you mix ASM into C. The compiler can't check your ASM code, it assumes you know what you're doing.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…