Long division Modulus Errors

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

Long division Modulus Errors

ソリューションへジャンプ
2,392件の閲覧回数
Emac
Contributor III
Hello all,
 
I have recently seen a problem where global variables have been clobbered when I get down to a "Long MODulo Unsigned" operation.  I have 5.7.0 CW IDE for HCS12 and have debugged down to the C implementation of
dword n
 
 n%10
 
the code works OK but TOTALLY CLOBBERS GLOBAL variables.
 
actual code
 
Code:
/**This routine converts numbers of type word to a string format of 0xXXXX===============================================================================**DESCRIPTION:***This routine converts numbers of type word to a string format of 0xXXXX in *decimal notation.*CALLING SEQUENCE:   wordToDecStr(char *s, word n)**@param *s (character pointer of size + 1  or greater).@param n  (16 bit word to be converted).@param size  (char variable indicating number of leading zeros required).*\todo- List of things to do- Remove commented code*/void wordToDecStr(unsigned char *s, dword n,char size){ unsigned char i, j; dword temp; //return in error case if((size==0)) {   return; }    //fill with character zeros for (j=0;j<size;j++) {  s[j] = '0'; } //modulus your way from the back to the front i=0; while ((n > 0)&&(size>i))  {    temp=(n % 10) + '0'; ////<<<<ERROR OCCURS HERE  s[size-i-1] =(char)temp;    n /= 10;  i++; }//end while s[size]='\0';//string terminator}//end wordToDecStr()

 
 
Does anybody have any experience with this?
ラベル(1)
タグ(1)
0 件の賞賛
返信
1 解決策
1,064件の閲覧回数
CompilerGuru
NXP Employee
NXP Employee
Where is the stack pointer SP when that code gets executed?

The description sounds as if the application would use more stack space that which was allocated for it.

Daniel

元の投稿で解決策を見る

0 件の賞賛
返信
2 返答(返信)
1,065件の閲覧回数
CompilerGuru
NXP Employee
NXP Employee
Where is the stack pointer SP when that code gets executed?

The description sounds as if the application would use more stack space that which was allocated for it.

Daniel
0 件の賞賛
返信
1,064件の閲覧回数
Emac
Contributor III
Thanks,
 
You were absolutely right, the symptoms were that the stack was clobering global variables.  I finally found the CPU build options for stack size and saw that it was originally set to 80!  I increased it and works fine now.  Thanks. 
 
Let this be a warning to those who unit test code and find problems durring integration, stack size and subroutine nesting can bite you if you don't know what to look for.
 
Daniel you are awesome!
0 件の賞賛
返信