Call of function - compilation problem

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

Call of function - compilation problem

Jump to solution
1,338 Views
gaminn
Contributor IV

Hello,

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

CLRH

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):

PSHA

PSHH

TSX

CLR  ,X

.......

 

 

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).

Labels (1)
Tags (1)
0 Kudos
1 Solution
438 Views
CrasyCat
Specialist III

Hello

 

Please make sure you have a prototype for function wait in module handlers.c prior to implementation of handler().

 

CrasyCat

View solution in original post

0 Kudos
2 Replies
439 Views
CrasyCat
Specialist III

Hello

 

Please make sure you have a prototype for function wait in module handlers.c prior to implementation of handler().

 

CrasyCat

0 Kudos
438 Views
gaminn
Contributor IV

Oh, stupid mistake...Sorry.

 

Thank you

0 Kudos