AnsweredAssumed Answered

Long division Modulus Errors

Question asked by Erick McAfee on Dec 4, 2007
Latest reply on Dec 5, 2007 by Erick McAfee
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
the code works OK but TOTALLY CLOBBERS GLOBAL variables.
actual 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?