Crazy function for local scope: help!

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Crazy function for local scope: help!

Jump to solution
1,898 Views
cicciounico
Contributor III
Hi,
I use MC9S08LC36.
I have make a function defined in funcs.h :
void CaricoOre(unsigned char );

I use this function and I pass it a global var defined in ram.h with:

#ifdef _MAIN_C
   #define g_var
#else
   #define g_var extern
#endif

g_var unsigned char ore;

My problem is: when I call My function, the var passed is 0 but insiede the function is random value!!
Why?
The screen shot: call function
http://ciccioamore.altervista.org/1.jpg

Inside the function:
http://ciccioamore.altervista.org/2.jpg





Thanks
Labels (1)
Tags (1)
0 Kudos
1 Solution
786 Views
cicciounico
Contributor III
YUUuuuuuuuuuu!   :smileyhappy:
Thanks: I have insert option: -Wpd
and the compiler have alert me with warnig!
Missing : #include funcs.h     :smileysurprised:

thanks again!   :smileyhappy:

View solution in original post

0 Kudos
3 Replies
786 Views
Navidad
Contributor III
Hi,

I am no debugger expert, but what happens here is that the parameter is passed through a register (namely A), and not on the stack. Check the value of the A register (the register view is not included in you screenshots). I would expect it to be 0. Note that for functions with a fixed number of arguments and when the size of the last argument is one byte, the compiler will always pass this last argument through a A register (this behavior is documented in the compiler manual in this section: "Calling Protocol and Conventions" ).

Navidad
786 Views
CrasyCat
Specialist III
Hello
 
It would be worthwhile checking if you have a prototype of function Caricoure in module where ShowLCD is implemented.
 
In order to figure that out, can you please add the option -Wpd to your compiler command line? If you get an error message that means you are invoking the function, but there is no prototype for it. 
 
Please add a prototype for the function before you call it.
 
If this does not help, I would recommend you to submit a service request for that.

Click here to submit a service request.

Make sure to attach a reproducible project and installed product information to the service request.
To generate the required information:
- Start CodeWarrior
- Open the project
- Select "Help" -> "Pack and Go" and follow instructions on the screen.

Attach the generated .zip file to the SR.
CrasyCat
787 Views
cicciounico
Contributor III
YUUuuuuuuuuuu!   :smileyhappy:
Thanks: I have insert option: -Wpd
and the compiler have alert me with warnig!
Missing : #include funcs.h     :smileysurprised:

thanks again!   :smileyhappy:
0 Kudos