• AVR Freaks

Hot!Puzzled with "Check operand #0"

Author
Denge
Super Member
  • Total Posts : 91
  • Reward points : 0
  • Joined: 2016/03/03 07:23:12
  • Location: belgium
  • Status: offline
2019/10/31 05:16:59 (permalink)
0

Puzzled with "Check operand #0"

Hi All,
 
I'm chewing for a day now to understand what is happening here:
 
In the main program file i define
; Main source file
.global  Led
Led = RA2 ; LED

and make it global so it is also visible in the init file where I use it in 
; Init source file
.extern Led
bset LATA,#Led

 
But when assembling I receive the error
Error: Invalid operands specified ('bset LATA,#Led').
       Check operand #0.

 
It must have to do with the definition of "Led" as when I change Led to RA2 or simply 2 the error is gone.
 
I do the same .global, .extern mechanism with labels and these assemble properly.
 
Anyone an idea what I'm doing wrong here?
 
pic33EP512GP502

MPLAB X IDE v5.25
XC16 V1.41
 
Thanks
#1

12 Replies Related Threads

    du00000001
    Just Some Member
    • Total Posts : 3234
    • Reward points : 0
    • Joined: 2016/05/03 13:52:42
    • Location: Germany
    • Status: online
    Re: Puzzled with "Check operand #0" 2019/10/31 05:24:59 (permalink)
    4 (1)
    So the line would translate to
    BSET LATA, #RA2
    As I'm quite sure that RA2 doesn't translate to '2' (check that!), the error is justified.
    I'd try
    LEDBit = 2
    BSET LATA, #LEDBit

    PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
    #2
    Denge
    Super Member
    • Total Posts : 91
    • Reward points : 0
    • Joined: 2016/03/03 07:23:12
    • Location: belgium
    • Status: offline
    Re: Puzzled with "Check operand #0" 2019/10/31 05:44:24 (permalink)
    0
    Hi du,
     
    RA2 is defined as 0x0002 in this Pic's include file and should thus translate to 2.
    The nasty thing is  define "Led" in the main file, use it in the Init file where it is not recognised although I use the correct .global in the main file and .extern in the init file.
    #3
    du00000001
    Just Some Member
    • Total Posts : 3234
    • Reward points : 0
    • Joined: 2016/05/03 13:52:42
    • Location: Germany
    • Status: online
    Re: Puzzled with "Check operand #0" 2019/10/31 05:49:05 (permalink)
    4 (1)
    Oh, you define it in the main and use it in the init file?
    How do you suppose will the assembler know about the definition when assembling the init file?
    Clairvoyance?

    PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
    #4
    Denge
    Super Member
    • Total Posts : 91
    • Reward points : 0
    • Joined: 2016/03/03 07:23:12
    • Location: belgium
    • Status: offline
    Re: Puzzled with "Check operand #0" 2019/10/31 06:00:03 (permalink)
    0
    I'm defining the symbol Led as .global in the main file and as .extern in the Init file.
     
    It works fine for    rcall   initOsc (in the main file),
    where initOsc is defined as .extern in the main file and as .global in the Init file.
    However here we are talking about routine labels...
    #5
    du00000001
    Just Some Member
    • Total Posts : 3234
    • Reward points : 0
    • Joined: 2016/05/03 13:52:42
    • Location: Germany
    • Status: online
    Re: Puzzled with "Check operand #0" 2019/10/31 07:12:49 (permalink)
    4 (1)
    Denge
    It works fine for    rcall   initOsc (in the main file),
    where initOsc is defined as .extern in the main file and as .global in the Init file.

    Yep. So the function prototype of initOsc() is known in main. To stitch this together is the job of the linker.
     
    As an immediate value ('#') doesn't generate some linkable relation at all, the whole definition has to be known when the init file is passing through the assembler.
     

    PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
    #6
    Denge
    Super Member
    • Total Posts : 91
    • Reward points : 0
    • Joined: 2016/03/03 07:23:12
    • Location: belgium
    • Status: offline
    Re: Puzzled with "Check operand #0" 2019/10/31 08:32:10 (permalink)
    0
    Mhhh, I got it.
    What would than be the best practise to get comprehensive port names throughout the different files while defining them once?
    #7
    1and0
    Access is Denied
    • Total Posts : 9989
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: Puzzled with "Check operand #0" 2019/10/31 08:53:11 (permalink)
    5 (1)
    Denge
    What would than be the best practise to get comprehensive port names throughout the different files while defining them once?

    Put them in an include/header file.
    #8
    Denge
    Super Member
    • Total Posts : 91
    • Reward points : 0
    • Joined: 2016/03/03 07:23:12
    • Location: belgium
    • Status: offline
    Re: Puzzled with "Check operand #0" 2019/11/02 08:58:56 (permalink)
    0
    Hello 1and0,
    This worked fine :-)
     
    Thanks
    #9
    Gort2015
    Klaatu Barada Nikto
    • Total Posts : 3338
    • Reward points : 0
    • Joined: 2015/04/30 10:49:57
    • Location: 0
    • Status: offline
    Re: Puzzled with "Check operand #0" 2019/11/15 16:38:26 (permalink)
    1 (1)
     
    .include "xc.inc"
     

    MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
    https://www.youtube.com/watch?v=Iu1qa8N2ID0
    + ST:Continues, "What Ships are Made for", Q's back.
    #10
    Denge
    Super Member
    • Total Posts : 91
    • Reward points : 0
    • Joined: 2016/03/03 07:23:12
    • Location: belgium
    • Status: offline
    Re: Puzzled with "Check operand #0" 2019/11/16 12:19:39 (permalink)
    0
    Hi Gort2015,
    I've already
    .include "p33EP512GP502.inc"

    on top of each file, so what should be the benefit of adding XC.inc??
    #11
    1and0
    Access is Denied
    • Total Posts : 9989
    • Reward points : 0
    • Joined: 2007/05/06 12:03:20
    • Location: Harry's Gray Matter
    • Status: offline
    Re: Puzzled with "Check operand #0" 2019/11/16 12:30:08 (permalink)
    0
    Denge
    I've already
    .include "p33EP512GP502.inc"

    on top of each file, so what should be the benefit of adding XC.inc??

    The <xc.inc> is a generic include file, which will include your device specific "p33EP512GP502.inc".
    #12
    Gort2015
    Klaatu Barada Nikto
    • Total Posts : 3338
    • Reward points : 0
    • Joined: 2015/04/30 10:49:57
    • Location: 0
    • Status: offline
    Re: Puzzled with "Check operand #0" 2019/11/16 13:43:25 (permalink)
    1 (1)
    Underscore any labels in assembly to make them visible in C.
    Without an underscore, it is visible in asm only.
     
    ".globl" or "global" in either case
     
    .section abc, code
    _func:  .globl _func
        return
     
    .section Number, data
    _var: .int 42    .globl _var
     
    ".extern"   is not needed, ".globl" has already satified that ref for the linker.
     
     
     
     

    MPLab X playing up, bug in your code? Nevermind, Star Trek:Discovery will be with us soon.
    https://www.youtube.com/watch?v=Iu1qa8N2ID0
    + ST:Continues, "What Ships are Made for", Q's back.
    #13
    Jump to:
    © 2019 APG vNext Commercial Version 4.5