Menu

#337 PIC backend: string literals

closed-out-of-date
None
5
2013-05-25
2002-05-07
No

I suspect you know this already, but:
string literals seem "dangerous":

main()
{
char * p = "hellow world!\r\n";

// copy string to serial port (serial port setup omitted)
while (1)
{
if (0 == *p) break;
TXREG = *p;
p++;
}
}

generates FSR/INDF addressing whereas a CALL would have been the correct
thing to do. I just noticed that declaring it "const char *" does
seem to use CALL (I assume correctly, I haven't checked). However,
its easy not to know/guess that "const char * " is the right thing to do
... maybe the compiler should generate a warning:
"WARNING: char * cannot be used to address string literals! Maybe you
want to use const char *" or something like that ...

--linas

Below is the broken code...

00173 ;; -----------------------------------------
00174 ;; function main
00175 ;; -----------------------------------------
00176 ;_main:
0000 00177 _main ;Function start
0000 300E 00192 MOVLW LOW(__str_0) ;key=000,flow
seq=001
0001 00A0 00203 MOVWF r0x20 ;key=001,flow seq=001
0002 00A1 00204 MOVWF r0x21 ;key=002,flow seq=001
0003 00216 _00108_DS_
0003 0821 00217 MOVF r0x21,W ;key=000,flow seq=002
0004 0084 00218 MOVWF FSR ;key=001,flow seq=002
0005 0800 00219 MOVF INDF,W ;key=002,flow seq=002
0006 00A2 00229 MOVWF r0x22 ;key=003,flow seq=002
0007 1903 00230 BTFSC STATUS,2 ;key=004,flow
seq=002
0008 280D 00233 GOTO _00110_DS_ ;key=000,flow
seq=003
0009 0822 00247 MOVF r0x22,W ;key=000,flow seq=004
000A 0099 00248 MOVWF _TXREG ;key=001,flow seq=004
000B 0AA1 00259 INCF r0x21,F ;key=002,flow seq=004
000C 2803 00263 GOTO _00108_DS_ ;key=003,flow
seq=004
000D 00276 _00110_DS_
000D 0008 00277 RETURN ;key=000,flow seq=005
00284 ;; Starting pCode block
00285 ;; __str_0 = hellow world!^M
00286
000E 00287 __str_0
000E 3468 00288 RETLW 0x68 ;key=000,flow seq=007
000F 3465 00290 RETLW 0x65 ;key=000,flow seq=008
0010 346C 00292 RETLW 0x6c ;key=000,flow seq=009
0011 346C 00294 RETLW 0x6c ;key=000,flow seq=00a
0012 346F 00296 RETLW 0x6f ;key=000,flow seq=00b
0013 3477 00298 RETLW 0x77 ;key=000,flow seq=00c
0014 3420 00300 RETLW 0x20 ;key=000,flow seq=00d
0015 3477 00302 RETLW 0x77 ;key=000,flow seq=00e
0016 346F 00304 RETLW 0x6f ;key=000,flow seq=00f
0017 3472 00306 RETLW 0x72 ;key=000,flow seq=010
0018 346C 00308 RETLW 0x6c ;key=000,flow seq=011
0019 3464 00310 RETLW 0x64 ;key=000,flow seq=012
001A 3421 00312 RETLW 0x21 ;key=000,flow seq=013
001B 340D 00314 RETLW 0x0d ;key=000,flow seq=014
001C 340A 00316 RETLW 0x0a ;key=000,flow seq=015
001D 3400 00318 RETLW 0x00 ;key=000,flow seq=016

Discussion

  • Scott Dattalo

    Scott Dattalo - 2003-04-11
    • assigned_to: nobody --> sdattalo
     
  • Raphael Neider

    Raphael Neider - 2006-06-26

    Logged In: YES
    user_id=1115835

    Appears fixed in SDCC r4251.

     
  • Raphael Neider

    Raphael Neider - 2006-06-26
    • milestone: --> unreproducable
    • status: open --> closed-out-of-date
     

Log in to post a comment.

MongoDB Logo MongoDB