#617 Incorrect variable initialisation

closed-fixed
z80 port (188)
5
2013-05-25
2003-10-23
No

Hi,

I would like to report you a problem I have observed
with sdcc V2.3.5
The following code brings a faulty variable initialisation.

Here is an example of a C source code generated for Z80
cpu (sdcc -mz80)
It initialise a variable and send it to the outport
subroutine
outport send the value to an I/O port (code not needed
to observe the problem)

//C Code
#define TIMER_CTRL 11
unsigned char gates;

void outport(unsigned char machin, unsigned char truc)
{
machin;truc;
}

void main(void)
{
gates = 0; //initialise the variable
// outport(TIMER_CTRL, gates); //do nothing here
}
//END of C Code

assembly code generated for main:

push ix
ld ix, 0
add ix, sp
ld iy, 8000h
ld (iy+0), 0 <== the variable is
correctly initialised
pop ix
ret

Now test'osberve the problem:
//C Code
#define TIMER_CTRL 11
unsigned char gates;

void outport(unsigned char machin, unsigned char truc)
{
machin;truc;//no code needed
}

void main(void)
{
gates = 0; //initialise the variable
outport(TIMER_CTRL, gates); //the code use it
this time
}
//END of C Code

assembly code generated for main:

push ix
ld ix, 0
add ix, sp
ld iy, 8000h
ld (iy+0), 0Bh <== here is the bad initialisation for
the variable
ld hl, 0Bh it is initialised
with TIMER_CTRL!
push hl
call TTT
pop af
pop ix
ret

Please tell me if I am wrong.

N.R.
(n.rentero@libertysurf.fr)

Discussion

  • Erik Petrich

    Erik Petrich - 2003-10-23

    Logged In: YES
    user_id=635249

    It combined the two constant parameters into a single
    constant for an efficient 16 bit push, but the scope of this
    optimization was larger than intended.
    Fixed in src/z80/ralloc.c 1.64

     
  • Erik Petrich

    Erik Petrich - 2003-10-23
    • labels: --> z80 port
    • milestone: --> fixed
    • assigned_to: nobody --> epetrich
    • 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:





No, thanks