#935 Incorrect handling of array items

closed-fixed
5
2013-05-25
2005-06-07
Anonymous
No

Vladislav Kasik, vladia@centrum.cz:

- When trying to read any array item (test[0] for
example) there is no assembler code for it.

- When used array item with "switch" an uninitialized
variable is used instead of the array value.

However writing to an array item seems correct, as well
as using in "if" conditions.

Example:

#define __16f627
#include "pic16f627.h"

unsigned char test[32];

static void main(void)
{
while(1)
{
test[0] = PORTA;
PORTB = test[0];
switch(test[2]) {
case 0x01:
PORTA |= 0x01;
break;
case 0x02:
PORTA |= 0x02;
break;
}
}

Compiled with:
sdcc -S -V -mpic14 -p16f627 test.c

SDCC :
mcs51/gbz80/z80/avr/ds390/pic16/pic14/TININative/xa51/ds400/hc08
2.5.1 #1041 (Jun 6 2005) (MIN
GW32)

Invalid output:

;--------------------------------------------------------
; File Created by SDCC : FreeWare ANSI-C Compiler
; Version 2.5.1 #1041 (Jun 6 2005)
; This file generated Tue Jun 07 17:30:13 2005
;--------------------------------------------------------
; PIC port for the 14-bit core
;--------------------------------------------------------
; .module test
list p=16f627
radix dec
include "p16f627.inc"
;--------------------------------------------------------
; extern variables in this module
;--------------------------------------------------------
;--------------------------------------------------------
; publics variables in this module
;--------------------------------------------------------
global _test
;--------------------------------------------------------
; special function registers
;--------------------------------------------------------
_TMR0 EQU 0x0001
_STATUS EQU 0x0003
_FSR EQU 0x0004
_PORTA EQU 0x0005
_PORTB EQU 0x0006
_PCLATH EQU 0x000a
_INTCON EQU 0x000b
_PIR1 EQU 0x000c
_TMR1L EQU 0x000e
_TMR1H EQU 0x000f
_T1CON EQU 0x0010
_TMR2 EQU 0x0011
_T2CON EQU 0x0012
_CCPR1L EQU 0x0015
_CCPR1H EQU 0x0016
_CCP1CON EQU 0x0017
_RCSTA EQU 0x0018
_TXREG EQU 0x0019
_RCREG EQU 0x001a
_CMCON EQU 0x001f
_OPTION_REG EQU 0x0081
_TRISA EQU 0x0085
_TRISB EQU 0x0086
_PIE1 EQU 0x008c
_PCON EQU 0x008e
_PR2 EQU 0x0092
_TXSTA EQU 0x0098
_SPBRG EQU 0x0099
_EEDATA EQU 0x009a
_EEADR EQU 0x009b
_EECON1 EQU 0x009c
_EECON2 EQU 0x009d
_VRCON EQU 0x009f
;--------------------------------------------------------
; udata
;--------------------------------------------------------
data_test udata
; .area DSEG (DATA)
_INDF EQU 0x0000
_PCL EQU 0x0002
_test res 32
r0x21 res 1
PSAVE EQU 0x006e
SSAVE EQU 0x006f
WSAVE EQU 0x0070
s0x71 EQU 0x0071
s0x72 EQU 0x0072
s0x73 EQU 0x0073
s0x74 EQU 0x0074
s0x75 EQU 0x0075
s0x76 EQU 0x0076
s0x77 EQU 0x0077
s0x78 EQU 0x0078
s0x79 EQU 0x0079
s0x7A EQU 0x007a
s0x7B EQU 0x007b
s0x7C EQU 0x007c
s0x7D EQU 0x007d
s0x7E EQU 0x007e
s0x7F EQU 0x007f
;--------------------------------------------------------
; overlayable items in internal ram
;--------------------------------------------------------
; udata_ovr
;--------------------------------------------------------
; bit data
;--------------------------------------------------------
; .area BSEG (BIT)
;--------------------------------------------------------
; config word
;--------------------------------------------------------
__config 0x3fff
;--------------------------------------------------------
; reset vector
;--------------------------------------------------------
STARTUP code
nop
goto __sdcc_gsinit_startup
;--------------------------------------------------------
; interrupt and initialization code
;--------------------------------------------------------
code_init code 0x4
__sdcc_interrupt:
__sdcc_gsinit_startup:
pagesel _main
goto _main
;--------------------------------------------------------
; code
;--------------------------------------------------------
code_test code
;***
; pBlock Stats: dbName = M
;***
;entry: _main ;Function start
; 2 exit points
;has an exit
;1 compiler assigned register :
; r0x21
;; Starting pCode block
_main ;Function start
; 2 exit points
_00109_DS_
;#CSRC test.c 10
; test[0] = PORTA;
BCF STATUS,5
BCF STATUS,6
MOVF _PORTA,W
BANKSEL _test
MOVWF _test
;#CSRC test.c 12
; switch(test[2]) {
DECF r0x21,W
BTFSC STATUS,2
GOTO _00105_DS_
MOVF r0x21,W
XORLW 0x02
BTFSC STATUS,2
GOTO _00106_DS_
GOTO _00109_DS_
_00105_DS_
;#CSRC test.c 14
; PORTA |= 0x01;
BCF STATUS,5
BCF STATUS,6
BSF _PORTA,0
;#CSRC test.c 15
; break;
GOTO _00109_DS_
_00106_DS_
;#CSRC test.c 17
; PORTA |= 0x02;
BCF STATUS,5
BCF STATUS,6
BSF _PORTA,1
;#CSRC test.c 19
; }
GOTO _00109_DS_
RETURN
; exit point of _main

end

Discussion

  • Raphael Neider

    Raphael Neider - 2005-07-01

    Logged In: YES
    user_id=1115835

    Fixed in SDCC 2.5.1 #1053.

     
  • Raphael Neider

    Raphael Neider - 2005-07-01
    • milestone: --> fixed
    • assigned_to: nobody --> tecodev
    • status: open --> closed-fixed
     

Log in to post a comment.

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

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks