Call of function - compilation problem

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

Call of function - compilation problem

ソリューションへジャンプ
2,027件の閲覧回数
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).

ラベル(1)
タグ(1)
0 件の賞賛
返信
1 解決策
1,127件の閲覧回数
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 件の賞賛
返信
2 返答(返信)
1,128件の閲覧回数
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 件の賞賛
返信
1,127件の閲覧回数
gaminn
Contributor IV

Oh, stupid mistake...Sorry.

 

Thank you

0 件の賞賛
返信