#214 Code gen overwrites registers

closed-fixed
nobody
5
2013-05-25
2001-11-07
No

The following problem occurs with all versions of SDCC, although this simply test case does not fail with the latest version in CVS. I haven't been able to simplify my more complex program yet.

The following C code:

extern char Data1[];

extern int f1(void);
extern void f2(char *,int);

void main(void) {
int l;

l = f1();
f2(&Data1,l+10);
}

generates the follow ASM code

; bug.c 9
lcall _f1
mov r2,dpl
mov r3,dph
; bug.c 10
mov r2,#_Data1
; Peephole 3.c changed mov to clr
clr a
mov r3,a
mov r4,a
mov a,#0x0A
add a,r2
mov _f2_PARM_2,a
; Peephole 180 changed mov to clr
clr a
addc a,r3
mov (_f2_PARM_2 + 1),a
mov dpl,r2
mov dph,r3
mov b,r4
lcall _f2

Notice that after the call to _f1, the results are stored in r2&r3. Immediately afterwards r2&r3 are overwritten. Later on before the call to _f2, r2&r3 are used, but have since been destroyed.

As I mentioned, this simple test case does not currently fail with the current CVS version, but my large program still does.

The current work around is to rewrite the C code so that function parameters are precalculated before being used:

l = f1()+10;
f2(&Data1,l);

Thanks,

Alex Karahalios

Discussion

  • Sandeep Dutta

    Sandeep Dutta - 2001-11-10
    • milestone: --> fixed
    • status: open --> open-fixed
     
  • Sandeep Dutta

    Sandeep Dutta - 2001-11-10

    Logged In: YES
    user_id=1551

    I think this is fixed.. could you try with the current cvs
    tree

     
  • Sandeep Dutta

    Sandeep Dutta - 2001-11-10
    • status: open-fixed --> 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