AnsweredAssumed Answered

Call of function - compilation problem

Question asked by Martin Dusek on Mar 16, 2009
Latest reply on Mar 16, 2009 by Martin Dusek


My MCU is HCS08QG8 and I use CodeWarriror 5.9.0.


I have a wait() function that I call in two files (main.c in main() function and handlers.c in handler() function). My problem is that wait() function called in handlers.c doesn't work. If i look at assembly code and search for assembly of both calls (they are the same - wait(209):smileywink:, I can see for the call in main.c:


wait(209); // this is called in main file 

Assembly of this call: 

LDA  #0xD1

JSR  0xEF91


And for handlers.c file: 


wait(209); // this is called in handle file

Assembly of this call: 

LDX  #0xD1


JSR  0xEF91


My wait() function looks like:

void wait(unsigned char ms) {  unsigned char i;  for(i = 0 ; i < ms ; i++) {    wait_1ms();  }  }


Assembly (only beginning):








So, I can see that parameter ms of wait() for the call in main.c is stored in register A, but for the call in handlers.c it is stored in register X. And wait() function is assembled in the way that register A is considered as the place where the ms parameter is located (and register X is the variable called i in wait()).


What can cause that compiler compiles my code in such a way (a way that doesn't work in handlers.c).