CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

PCD V4.127 not preserving registers in printf("%x"

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
FvM



Joined: 27 Aug 2008
Posts: 2337
Location: Germany

View user's profile Send private message

PCD V4.127 not preserving registers in printf("%x"
PostPosted: Sun Nov 27, 2011 3:05 pm     Reply with quote

Hello,

I'm still struggling to find a stable PCD version newer than V4.112. Just when I thought, V4.127 could be a candidate,
I stumbled upon a new bug, that wasn't yet present in V4.125. (Unfortunately, the latter has other and more bugs,
so falling back to V4.125 isn't a good option...).

I could implement a workaround in the present case, but not preserving registers in internal function calls is a
serious issue, thus I wonder if the same problem shows in other places as well.

Code:
#include <24F16KA102.h>
#device icd=2
#FUSES HS //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#use delay(clock=20000000)
#use RS232(baud=19200, UART1)

#define W4_BUGFIX 0

void _putc(unsigned int8 c)
{
   int16 l;
#IF  getenv("VERSION")==4.127 && W4_BUGFIX
   #asm MOV W4,[W15++] #endasm
#ENDIF
   l=l*3;
   putc(c);
#IF  getenv("VERSION")==4.127 && W4_BUGFIX
   #asm MOV [--W15],W4 #endasm
#ENDIF
}

void main()
{
unsigned int16 us;
us=9;
printf(_putc,"printf_x fails in V4.127 because W4 isn't preserved V%3x\r\n",us);
while (1);
}


Generated printf output:

"printf_x fails in V4.127 because W4 isn't preserved
V009000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000
000000000000000000000000000000000000000000000000000000"

And that's how the erroneous printout is brought up. @PRINTF_X_74 is the internal print function called with
%x format for a 16 bit integer.

Code:
@PRINTF_X_74:
0256:  MOV     W0,W3
0258:  SWAP    W1
025A:  MOV.B   #5,W4L ; W4 used as digit counter
025C:  DEC.B   0003
025E:  DEC.B   0008 ; W4L--
0260:  BRA     Z,290
0262:  MOV     W3,W0
0264:  SL      W3,#4,W3
0266:  LSR     W0,#C,W0
0268:  AND     #F,W0
026A:  BRA     NZ,274
026C:  CP.B    W4L,#1
026E:  BRA     Z,274
0270:  BTSS.B  3.7
0272:  BRA     25C
0274:  ADD     #30,W0
0276:  MOV     #3A,W2
0278:  CP      W0,W2
027A:  BRA     NC,27E
027C:  ADD.B   2,W0L
027E:  MOV     W1,[W15++]
0280:  MOV     W3,[W15++]
0282:  MOV.B   W0L,85F
0284:  CALL    244    ; W4 not preserved
0288:  MOV     [--W15],W3
028A:  MOV     [--W15],W1
028C:  BSET.B  3.7
028E:  BRA     25C
0290:  RETURN
 
.................... void _putc(unsigned int8 c)
.................... {
....................    int16 l;
....................    l=l*3;
*
0244:  MOV     860,W4 ; W4 is overwritten
0246:  MUL.UU  W4,#3,W0
0248:  MOV     W0,860
....................    putc(c);
024A:  MOV.B   85F,W0L
024C:  BTSC.B  223.1
024E:  BRA     24C
0250:  MOV.B   W0L,224
0252:  CLR.B   225
.................... }
0254:  RETURN 
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group