• AVR Freaks

Hot!xc16 call same function different

Author
luis_e7
New Member
  • Total Posts : 16
  • Reward points : 0
  • Joined: 2008/10/10 13:57:50
  • Location: 0
  • Status: offline
2019/05/09 09:40:13 (permalink)
0

xc16 call same function different

Hi, Best regards,

I'm working on a code for a dsPIC33F, and I run into a problem calling a function.
It turns out that in the code I call a function in two different parts, and in one part it works well and returns well, but in the other part it does not return even passing the same parameters.
Check the compiled code in asm and note that when calling the function in the part that works it uses W0 and W1, in the other it does the reverse W1 and W0, and the memory addresses are exchanged.

What can be wrong.

Thanks for your help.
 
Part of the code that works well.
n = 16;
res = READ_DATA_BLOCK(buf,n);
Next is asm disassembly
MOV [W14+6], W1
MOV [W14+4], W0
RCALL READ_DATA_BLOCK
 
The same call function, but the values assigned to W0 and W1 are different when into the function. And Never return
res = READ_DATA_BLOCK(buf, 16);
Next is asm disassembly
MOV #0x10, W1
MOV [W14+6], W0
RCALL READ_DATA_BLOCK
post edited by luis_e7 - 2019/05/09 12:36:03
#1

7 Replies Related Threads

    NorthGuy
    Super Member
    • Total Posts : 5754
    • Reward points : 0
    • Joined: 2014/02/23 14:23:23
    • Location: Northern Canada
    • Status: offline
    Re: xc16 call same function different 2019/05/09 14:49:34 (permalink)
    4 (1)
    You pass different parameters to the function. Why do you expect the compiler to pass the same?
    #2
    luis_e7
    New Member
    • Total Posts : 16
    • Reward points : 0
    • Joined: 2008/10/10 13:57:50
    • Location: 0
    • Status: offline
    Re: xc16 call same function different 2019/05/10 21:05:00 (permalink)
    0
    If you look closely, the values ​​that are passed are the same,
    buf is a pointer of a buffer
    and the argument always equals 16 in both cases to check, since n is variable in the first case and in the second is constant.
    When the function enters in the second case the values ​​arrive in different order, therefore the variable that must be 16 is not.
    #3
    qhb
    Superb Member
    • Total Posts : 9999
    • Reward points : 0
    • Joined: 2016/06/05 14:55:32
    • Location: One step ahead...
    • Status: offline
    Re: xc16 call same function different 2019/05/11 00:39:24 (permalink)
    0
    Have you checked that actual values passed?
    You're assuming that "W14+6" is always the buffer pointer, rather than just "the nth auto variable in this block of code".
     

    Nearly there...
    #4
    NorthGuy
    Super Member
    • Total Posts : 5754
    • Reward points : 0
    • Joined: 2014/02/23 14:23:23
    • Location: Northern Canada
    • Status: offline
    Re: xc16 call same function different 2019/05/11 05:37:23 (permalink)
    4 (1)
    May be the compiler could have figured put that you pass 16, may be it will do it at higher level of optimizations. But it didn't. It does as you say - it moves 16 into a local variable, then it retrieves the value from there and passes it to the function.
     
    Also, names of the variables do not exist at this point. W14 is a frame pointer. The frame contains local variables. In the first call the variable "buf" is located at offset 4. "n" is located at offset 6. In the second call, the "buf" (a different variable with the same name) is located at offset 6. Since the second call is made from a different function (with a different set of local variables), the fact that they are located at the same offset from W14 means nothing.
     
    #5
    luis_e7
    New Member
    • Total Posts : 16
    • Reward points : 0
    • Joined: 2008/10/10 13:57:50
    • Location: 0
    • Status: offline
    Re: xc16 call same function different 2019/05/11 14:50:43 (permalink)
    0
    When I check W0 and W1 after calling the function and jumping to the code of it,
    In the first case
    W0 = Offset Buffer
    W1 = 16
    Second Case
    W0 = 16
    W1 = 16
    With these values ​​the function is evaluated incorrectly, and does not return to the correct address, Skip to another part of the code.
    Thank you for your attention.
    I'm reorganizing the code, to verify if the same thing happens by calling it from another sector of the code.
    #6
    luis_e7
    New Member
    • Total Posts : 16
    • Reward points : 0
    • Joined: 2008/10/10 13:57:50
    • Location: 0
    • Status: offline
    Re: xc16 call same function different 2019/05/14 12:52:59 (permalink)
    0
    Good news,
     
    Perform another different function, and call it from two different parts of the code and the same thing happened, in the second part the values ​​arrive in different order.
     
    After so much review, and without finding an explanation, I decided to remove the headers files from the project tree where the function is created, and call them from the code with #include.
     
    The compilation in assembly is now different, but the data is passed in the correct way.
     
    I think I'm not sure how to use this Header Files option in the project tree.
     
    Thanks for your time and help.
     
    Best regards,
    post edited by luis_e7 - 2019/05/14 12:56:05
    #7
    NorthGuy
    Super Member
    • Total Posts : 5754
    • Reward points : 0
    • Joined: 2014/02/23 14:23:23
    • Location: Northern Canada
    • Status: offline
    Re: xc16 call same function different 2019/05/14 13:30:55 (permalink)
    4 (1)
    I guess if the compiler had such bad bugs, they would've been discovered already. Thus it is highly unlikely. I suggest you create a small example which reproduces the problem and post it along with complete disassembly.
    #8
    Jump to:
    © 2019 APG vNext Commercial Version 4.5