1. This forum section is a read-only archive which contains old newsgroup posts. If you wish to post a query, please do so in one of our main forum sections (here). This way you will get a faster, better response from the members on Motherboard Point.

Need help with MPASM syntax for PIC18

Discussion in 'Embedded' started by larkmore, Feb 1, 2008.

  1. larkmore

    larkmore Guest

    Hello all. Trying to give a variable two different names. Right now,
    I have an array of variables declared thusly:

    #DEFINE PARAMETER_BUFFER_SIZE 0X30 ;PARAMETER BUFFER SIZE
    #DEFINE PARAMETER1 0X00
    #DEFINE PARAMETER2 0X01
    #DEFINE PARAMETER3 0X02
    ;
    ; and so on and so forth
    ;
    UDATA 0X100
    PARAMETER_BUFFER RES PARAMETER_BUFFER_SIZE

    Then I can access them in my program as

    movwf PARAMETER_BUFFER+PARAMETER1, BANKED

    However, this gets really annoying when trying to use the debugger
    watch window because address 0x100 shows the name PARAMETER_BUFFER and
    all addresses after that just show the address instead of a variable
    name. What I would like to do is be able to "redeclare" those same
    memory locations to be named something like

    UDATA 0X100
    fake_PARAMETER1 RES 1
    fake_PARAMETER2 RES 1
    fake_PARAMETER3 RES 1

    but still leave it dynamically assigned. I've tried

    UDATA 0X100
    PARAMETER_BUFFER RES PARAMETER_BUFFER_SIZE
    UDATA 0X100
    fake_PARAMETER1 RES 1

    but I get the error "Each object file section must be contiguous
    (section .udata)". I've tried

    #define fake_PARAMETER1_ADDR (PARAMETER_BUFFER+PARAMETER1)
    fake_PARAMETER1 equ fake_PARAMETER1_ADDR

    but I get the error "Operand contains unresolvable labels or is too
    complex". Is there a way to do what I want without declaring every
    single variable's address statically?
    -Will
     
    larkmore, Feb 1, 2008
    #1
    1. Advertisements

  2. larkmore

    Dave Guest


    If you were writing in C then you may be able to acheive what you want
    with a union, but in assembler I don't know if there is an equivalent.

    Dave.
     
    Dave, Feb 2, 2008
    #2
    1. Advertisements

  3. larkmore

    Thad Smith Guest

    You should debug this. It has been a while since I used MPASM, but I
    assume the define works like the C preprocessor and should yield a suitable
    expression from the definitions above. Try using fake_PARAMETER1_ADDR in
    your instruction.

    Is there a way to do what I want without declaring every
    You could do something like

    UDATA 0x100
    PARAMETER_BUFFER equ $ ; start of buffer
    PARAMETER1 RES 1
    PARAMETER2 RES 2
    ....
    RES PARAMETER_BUFFER_SIZE-($-PARAMETER_BUFFER) ; remaining
    buffer
     
    Thad Smith, Feb 2, 2008
    #3
  4. larkmore

    Eric Smith Guest

    I think it does the right thing if you use CDATA instead of RES.
    Other than that, CDATA is an abomination that was obviously invented
    by someone with little experience with assemblers. It puts the
    assembler into a different mode until the end of the CDATA. Sigh.
     
    Eric Smith, Feb 4, 2008
    #4
  5. larkmore

    Eric Smith Guest

    I meant CBLOCK, not CDATA.
     
    Eric Smith, Feb 4, 2008
    #5
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.