• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

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
 

Sceadwian

Banned
What chip are you using, and what's the error?
 
Last edited:

Sceadwian

Banned
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:

tubos

New Member
I used it as described in the datasheet:

complemented. If ‘d’ is ‘0’, the result is
stored in W. If ‘d’ is ‘1’, the result is
stored back in register ‘f’ (default).
If ‘a’ is ‘0’, the Access Bank is selected.
If ‘a’ is ‘1’, the BSR is used to select the
GPR bank.
If ‘a’ is ‘0’ and the extended instruction
set is enabled, this instruction operates
in Indexed Literal Offset Addressing
mode whenever f 95 (5Fh).
 

Sceadwian

Banned
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?
 

Ian Rogers

User Extraordinaire
Forum Supporter
Most Helpful Member
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
  }
 

tubos

New Member
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:

Sceadwian

Banned
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.
 

Sceadwian

Banned
That means you didn't know what you were doing, you assumed it knew what you wanted. :)
 
Status
Not open for further replies.

EE World Online Articles

Loading
Top