#338 PIC backend: SERIOUS: const string liter

closed-fixed
None
5
2013-05-25
2002-05-08
No

OK,

now heree's a real one, an actual show-stopper:
the high-address bits for string literals are
mis-computed:

Actually, this is a peephole bug. keep reading ...

main()
{
const 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 code that would have been perfect, if the high-address bits
written into PCLATH were correct. Near line 225 below, 0x23 stores
the high address bits.

00181 ;; -----------------------------------------
00182 ;; function main
00183 ;; -----------------------------------------
00184 ;_main:
0000 00185 _main ;Function start
0000 3018 00207 MOVLW LOW(__str_0) ;key=000,flow
0001 00A0 00208 MOVWF r0x20 ;key=001,flow seq=001
0002 00A1 00209 MOVWF r0x21 ;key=002,flow seq=001
0003 0820 00221 MOVF r0x20,W ;key=003,flow seq=001
0004 00A2 00222 MOVWF r0x22 ;key=004,flow seq=001
0005 0821 00225 MOVF r0x21,W ;key=005,flow seq=001
0006 00A3 00226 MOVWF r0x23 ;key=006,flow seq=001

what should have happened here is
MOVLW LOW(__str_0)
MOVWF r0x22
MOVLW HIGH(__str_0)
MOVWF r0x23

and then things would have worked.

===================
Ahhh: the comments tell all:

;;# MOVLW LOW(__str_0)
;;# MOVWF r0x20
;;# MOVLW ((__str_0 >> 8)&0xff)
;; peep 10 - Removed redundant move
MOVLW LOW(__str_0) ;key=000,flow seq=001
MOVWF r0x20 ;key=001,flow seq=001
MOVWF r0x21 ;key=002,flow seq=001

Dooh, that peephole optimization is wrong! its not a redundant move, its
a shift & mask that was important! Whoops! I suspect you have this
fixed already ...

Note: specifying sdcc --no-peep does not fix this bug.

0007 00242 _00108_DS_
0007 2009 00243 CALL _00114_DS_ ;key=007,flow
0008 280D 00246 GOTO _00115_DS_ ;key=000,flow
0009 00249 _00114_DS_
0009 0823 00250 MOVF r0x23,W ;key=000,flow seq=004
000A 008A 00251 MOVWF PCLATH ;key=001,flow seq=004
000B 0822 00252 MOVF r0x22,W ;key=002,flow seq=004
000C 0082 00253 MOVWF PCL ;key=003,flow seq=004
000D 00255 _00115_DS_
000D 00A4 00256 MOVWF r0x24 ;key=000,flow seq=005
000E 0824 00263 MOVF r0x24,W ;key=001,flow seq=005
000F 1903 00264 BTFSC STATUS,2 ;key=002,flow
0010 2817 00267 GOTO _00110_DS_ ;key=000,flow
0011 0824 00281 MOVF r0x24,W ;key=000,flow seq=007
0012 0099 00282 MOVWF _TXREG ;key=001,flow seq=007
0013 0AA2 00296 INCF r0x22,F ;key=002,flow seq=007
0014 1903 00297 BTFSC STATUS,2 ;key=003,flow
0015 0AA3 00299 INCF r0x23,F ;key=000,flow seq=008
0016 2807 00303 GOTO _00108_DS_ ;key=001,flow
0017 00316 _00110_DS_
0017 0008 00317 RETURN ;key=000,flow seq=009
0018 00327 __str_0
0018 3468 00328 RETLW 0x68 ;key=000,flow seq=00b
0019 3465 00330 RETLW 0x65 ;key=000,flow seq=00c
001A 346C 00332 RETLW 0x6c ;key=000,flow seq=00d
001B 346C 00334 RETLW 0x6c ;key=000,flow seq=00e
001C 346F 00336 RETLW 0x6f ;key=000,flow seq=00f
001D 3477 00338 RETLW 0x77 ;key=000,flow seq=010
001E 3420 00340 RETLW 0x20 ;key=000,flow seq=011
001F 3477 00342 RETLW 0x77 ;key=000,flow seq=012
0020 346F 00344 RETLW 0x6f ;key=000,flow seq=013
0021 3472 00346 RETLW 0x72 ;key=000,flow seq=014
0022 346C 00348 RETLW 0x6c ;key=000,flow seq=015
0023 3464 00350 RETLW 0x64 ;key=000,flow seq=016
0024 3421 00352 RETLW 0x21 ;key=000,flow seq=017
0025 340D 00354 RETLW 0x0d ;key=000,flow seq=018
0026 340A 00356 RETLW 0x0a ;key=000,flow seq=019
0027 3400 00358 RETLW 0x00 ;key=000,flow seq=01a

Discussion

  • Scott Dattalo

    Scott Dattalo - 2002-05-11

    Logged In: YES
    user_id=11911

    Fixed in gen.c

     
  • Scott Dattalo

    Scott Dattalo - 2002-05-11
    • milestone: --> fixed
    • assigned_to: nobody --> sdattalo
    • status: open --> closed-fixed
     

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks