+ Reply to Thread
Results 1 to 6 of 6

Thread: Referencing C variables in In-line assembly

  1. #1
    zevious Newbie
    Join Date
    Feb 2009
    Posts
    3

    Default Referencing C variables in In-line assembly

    Hi,

    I'm wrote a small 18F in-line assembly snippet in MPLAB referencing a local C variable. From the results I'm not referencing the C variable correctly.

    Any ideas?

    unsigned char count = 0;
    unsigned char current_count = 10;

    count = current_count;

    _asm

    // Loop until count is 0
    start:
    DECFSZ count, 1, 0
    BRA start
    GOTO done
    done:

    _endasm


  2. #2
    Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent
    Join Date
    Mar 2005
    Location
    Brisbane Australia
    Posts
    6,805

    Default

    To use a variable without managing the banking you need to have it in access ram. Try moving your variable so it is global and put it in the access area by doing,
    Code:
    #pragma udata access somename
    near unsigned char count;
    #pragma udata
    
    Mike.

  3. #3
    zevious Newbie
    Join Date
    Feb 2009
    Posts
    3

    Default

    Thanks Mike,

    How would I manage the banking to avoid allocating it in access ram?

  4. #4
    Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent
    Join Date
    Mar 2005
    Location
    Brisbane Australia
    Posts
    6,805

    Default

    Well, if you run out of access ram you need to load the bsr with the bank number of your variable. What is wrong with using the access ram, the compiler doesn't seem to!!

    Mike.

  5. #5
    zevious Newbie
    Join Date
    Feb 2009
    Posts
    3

    Default

    Thanks again Mike,

    I believe I can use access RAM (near), and it do sound like it would end up being faster and require less cycles. But lets say I wanted to set the BSR with bank information to access the count variable in my simple loop example above. How would I accomplish that?

    I am sorry for these newbie questions but I'm just starting up with MPASM syntax (as you can tell)

  6. #6
    Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent Pommie Excellent
    Join Date
    Mar 2005
    Location
    Brisbane Australia
    Posts
    6,805

    Default

    You would simply do movlb count.

    Mike.

+ Reply to Thread

Similar Threads

  1. Assembly Variables for PICs!
    By Peter_wadley in forum Micro Controllers
    Replies: 9
    Latest: 22nd June 2007, 05:05 AM
  2. How reliable is cross referencing parts?
    By Canti in forum General Electronics Chat
    Replies: 23
    Latest: 3rd May 2007, 09:30 PM
  3. in-line assembly for PicBasic Compiler
    By Erwin_Macaraig in forum Micro Controllers
    Replies: 0
    Latest: 3rd November 2004, 07:02 AM
  4. ground referencing a differential input signal
    By giaracam in forum Electronic Projects Design/Ideas/Reviews
    Replies: 2
    Latest: 22nd September 2004, 12:41 PM
  5. Where is variables located in a PIC?
    By egh01 in forum Micro Controllers
    Replies: 0
    Latest: 22nd November 2003, 12:08 PM

Tags for this Thread