Searching \ for 'Mplab-C question (while (...) bug??)' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page: www.piclist.com/techref/microchip/languages.htm?key=mplab
Search entire site for: 'Mplab-C question (while (...) bug??)'.

Truncated match.
PICList Thread
'Mplab-C question (while (...) bug??)'
1997\07\30@184740 by Agrico LTX

picon face
Hello everyone!!

I would very much appreciate some assistance from those of you who have
worked with the Mplab-C compiler (names like Tjaart vd Walt spring to mind
;-) - hope I got the spelling right &-).

I am working on a project in which I am using a PIC17C44 with the Mplab-C
compiler. I am trying to write a string stored in ROM to a Hitachi based
LCD. The important bits in the .lst file are shown below:

Firstly the string:

0028                              const char mystring[] = " A B C D E F G
H\X00I";
0028 20 41 20 42 20 43 20 44
002C 20 45 20 46 20 47 20 48
0030 00 49 00 00

The spaces in the string are there because the memory is 16 bits wide, the
characters only 8. They are thus a workaround - without them only every
second character is displayed by the following routine:

void Write(char far *string)
{
       char c;                         // define a char
       string = string & 0x7fff;               // workaround - mplab-c wrongly
sets the
                                       // highest bit
       c = *string;
           while (c |= 0)
           {
               SendChar(c);
               string++;
               c = *string;
       }
}

As I hinted in the subject of this message, I suspect that the while loop
compiles incorrectly. The loop check compiles as follows:
MOVLR  00h
MOVFP  27,WREG                  ; get c
BTFSC  ALUSTA,2                 ; zero?
GOTO   0089h                    ; skip
The code can be seen in context in the list file portion below.  The
problem is that the MOVFP instruction does not modify the flags,  and the
loop terminates only later once the zero (terminating) character has
already been displayed!!!

List file:
                                 void Write(char far *string)
0023                              {
Warning __longAC will save space if located < 0x0020
0070 BA00    MOVLR  00h
0071 0123    MOVWF  23
0072 4124    MOVPF  FSR0,24
0027                                  char c;
0073 8F24    BCF    24,7              string = string & 0x7fff;

0074 6D23    MOVFP  23,TBLPTRL        c = *string;
0075 6E24    MOVFP  24,TBLPTRH
0076 A80A    TABLRD 0,0,0A
0077 A20A    TLRD   1,0A
0078 0127    MOVWF  27
                                     while (c |= 0)
                                     {
0079 BA00    MOVLR  00h                         //<<<<<<<<
007A 6A27    MOVFP  27,WREG                     //<<<<<<<<
007B 9A04    BTFSC  ALUSTA,2                    //<<<<<<<<
007C C089    GOTO   0089h                       //<<<<<<<<
007D                                     SendChar(c);
007D BA00    MOVLR  00h
007E 6A27    MOVFP  27,WREG
007F E054    CALL   0054h
0080 BA00    MOVLR  00h                  string++;
0081 2523    INFSNZ 23
0082 1524    INCF   24
0083 6D23    MOVFP  23,TBLPTRL           c = *string;
0084 6E24    MOVFP  24,TBLPTRH
0085 A80A    TABLRD 0,0,0A
0086 A20A    TLRD   1,0A
0087 0127    MOVWF  27
0088 C079    GOTO   0079h             }
0089 0002    RETURN                   return;
                                 }

A similar bug is documented for a do.. while loop,  which is why I opted
for a while(..) loop!  Is there any workaround, or am I doing something
stupid??

Any help would be very much appreciated...
       Roland Andrag

1997\07\30@193111 by Jacques Bellefleur

flavicon
face
At 12:12 AM 31/07/97 +0200, you wrote:
{Quote hidden}

wrongly sets the
{Quote hidden}

I had the same similar bad experience with my last written piece of software.

My findings are that MPLAB-C does not compile properly WHILE loops
testing the value at the address of a far pointer for a NUL

Re-write your while (c != 0) line of code as

       for ( ; c != 0 ; )
       {
               ... etc

.... it does the same and will compile properly.


Good Luck

Jacques

1997\07\30@224031 by John Payson

picon face
> >As I hinted in the subject of this message, I suspect that the while loop
> >compiles incorrectly. The loop check compiles as follows:
> >MOVLR  00h
> >MOVFP  27,WREG                  ; get c
> >BTFSC  ALUSTA,2                 ; zero?
> >GOTO   0089h                    ; skip
> >The code can be seen in context in the list file portion below.  The
> >problem is that the MOVFP instruction does not modify the flags,  and the
> >loop terminates only later once the zero (terminating) character has
> >already been displayed!!!

My guess is that the programmer who wrote the compiler read note 3 under
"Appendix B: Compatibility" [page 13-165 in my copy of the 96/97 PIC16/17
Microcontroller Data Book].  That note reads, simply:

3. Replace:
       MOVF    REG1, W
  with:
       MOVFP   REG1, WREG

Until seeing your post, I incorrectly thought it was MOVFP rather than MOVPF
which affects the zero flag; it turns out to be the other way 'round.  Perhaps
Microchip can note that in the next copy of the data book?  That same bug
could easily have bitten me.  [I've already been bitten by "incf" affecting
the CARRY flag...]

More... (looser matching)
- Last day of these posts
- In 1997 , 1998 only
- Today
- New search...