#350 Integers not initialized at all !!!!!

closed-fixed
None
5
2015-03-27
2002-05-26
No

This is just to add some emphasis to previous report
under "while loops".

sdcc seems to forget about initializing integers.

no warnings, no errors, no code generated for integer
assignments.

It's kind of a showstopper and takes a lot of confidence in
the compiler away.

--------begin c source snippet-----
static unsigned char
lcount,rcount, /*internal: time spaces to
skip */
lrate,rrate, /*internal: step rate
*/
lphase,rphase, /*internal: current step
phase */

ldir,rdir; /* direction */
static unsigned int
lstg,rstg; /* steps to go */

...
other unrelated code
...
main(){
/*
* Initialize 8051 registers
*/

TMOD &= 0x0f; /* clear timer 1 control bits */
TMOD |= 0x20; /* set timer 1 to mode 2 */
//TL1 = 0xE8; TH1 = 0xE8; /* ~400 */
TL1 = 0x88; TH1 = 0x88; /* ~400 */

/*
* Initialize variables for stepper movement
*/
rstg=0;
lstg=300;
rphase=0;
lphase=0;
rcount=0;
lcount=0;
rdir=0;
ldir=0;
rrate=0;
lrate=0;

ET1=1; /* enable timer 1 interupt */
EA=1; /* enable interupts */
TR1 = 1; /* start timer */
---------------------- end c snippet.

sdcc produces the following assembler.

---------------------- begin assembler snippet
;--------------------------------------------------------
; File Created by SDCC : FreeWare ANSI-C Compiler
; Version 2.3.0 Sun May 26 09:20:44 2002
....
sfr defines ommitted.
....
;--------------------------------------------------------

;--------------------------------------------------------
; internal ram data
;--------------------------------------------------------
.area DSEG (DATA)
_lcount:
.ds 1
_rcount:
.ds 1
_lrate:
.ds 1
_rrate:
.ds 1
_lphase:
.ds 1
_rphase:
.ds 1
_ldir:
.ds 1
_rdir:
.ds 1
_lstg:
.ds 2
_rstg:
.ds 2

....
code ommitted here
....

; -----------------------------------------
; function main
; -----------------------------------------
_main:
; stepper.c 97
anl _TMOD,#0x0F
; stepper.c 98
orl _TMOD,#0x20
; stepper.c 100
mov _TL1,#0x88
mov _TH1,#0x88
; stepper.c 107
mov _rphase,#0x00
; stepper.c 108
mov _lphase,#0x00
; stepper.c 109
mov _rcount,#0x00
; stepper.c 110
mov _lcount,#0x00
; stepper.c 111
mov _rdir,#0x00
; stepper.c 112
mov _ldir,#0x00
; stepper.c 113
mov _rrate,#0x00
; stepper.c 114
mov _lrate,#0x00
; stepper.c 118
setb _ET1
; stepper.c 119
setb _EA
; stepper.c 120
setb _TR1
; stepper.c 135
------------ end assembler snippet.

Discussion

  • Bernhard Held

    Bernhard Held - 2002-05-26
    • milestone: --> fixed
    • assigned_to: nobody --> bernhardheld
    • status: open --> closed-fixed
     
  • Bernhard Held

    Bernhard Held - 2002-05-26

    Logged In: YES
    user_id=203539

    Not reproducable with 2.3.2.

    _main:
    ar2 = 0x02
    ar3 = 0x03
    ar4 = 0x04
    ar5 = 0x05
    ar6 = 0x06
    ar7 = 0x07
    ar0 = 0x00
    ar1 = 0x01
    ; s.c:17: TMOD &= 0x0f; /* clear timer 1 control bits */
    ; genAnd
    anl _TMOD,#0x0F
    ; s.c:18: TMOD |= 0x20; /* set timer 1 to mode 2 */
    ; genOr
    orl _TMOD,#0x20
    ; s.c:20: TL1 = 0x88; TH1 = 0x88; /* ~400 */
    ; genAssign
    mov _TL1,#0x88
    ; genAssign
    mov _TH1,#0x88
    ; s.c:25: rstg=0;
    ; genAssign
    clr a
    mov (_rstg + 1),a
    mov _rstg,a
    ; s.c:26: lstg=300;
    ; genAssign
    mov _lstg,#0x2C
    mov (_lstg + 1),#0x01
    ; s.c:27: rphase=0;
    ; genAssign
    mov _rphase,#0x00
    ; s.c:28: lphase=0;
    ; genAssign
    mov _lphase,#0x00
    ; s.c:29: rcount=0;
    ; genAssign
    mov _rcount,#0x00
    ; s.c:30: lcount=0;
    ; genAssign
    mov _lcount,#0x00
    ; s.c:31: rdir=0;
    ; genAssign
    mov _rdir,#0x00
    ; s.c:32: ldir=0;
    ; genAssign
    mov _ldir,#0x00
    ; s.c:33: rrate=0;
    ; genAssign
    mov _rrate,#0x00
    ; s.c:34: lrate=0;
    ; genAssign
    mov _lrate,#0x00
    ; s.c:38: ET1=1; /* enable timer 1 interupt */
    ; genAssign
    setb _ET1
    ; s.c:39: EA=1; /* enable interupts */
    ; genAssign
    setb _EA
    ; s.c:40: TR1 = 1; /* start timer */
    ; genAssign
    setb _TR1
    00101$:
    ret

     

Log in to post a comment.

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

Sign up for the SourceForge newsletter:





No, thanks