#212 Bad code for decrement global variable

closed-fixed
nobody
None
5
2001-11-05
2001-11-04
Marc Nijweide
No

The following code generates bad code for case
bar==0. The DE register is in use but the decrement
operation does not recognize that.

int foo = 16;

extern void f( int x );

void g(int bar)
{
int a = 0;
int b = 0;

while(1) {
switch(bar) {
case 0:
--foo;
f(foo);
break;
case 1:
++foo;
f(foo);
break;
case 2:
++a;
f(a);
break;
case 3:
++b;
f(b);
break;
}
}
}

Code for case 0:
00101$:
; genMinus
ld hl,(_foo)
dec hl
ld a,l
ld d,h
ld iy,#_foo
ld 0(iy),a
ld 1(iy),d
; test3.c 14
; genIpush
; _saveRegsForCall: sendSetSize: 0 deInUse: 1 bcInUse:
1 deSending: 0
push bc
push de
ld hl,(_foo)
push hl
; genCall
call _f
pop hl
pop de
pop bc
; test3.c 15
; genGoto
jp 00107$

Tested with SDCC MingW snapshot 2001.11.04
sdcc -mz80 -c

-Marc.

Discussion

  • Michael Hope
    Michael Hope
    2001-11-05

    Logged In: YES
    user_id=373

    Fixed and improved. It appeared due to a cross over between
    the gbz80 and z80 ports.

     
  • Michael Hope
    Michael Hope
    2001-11-05

    • status: open --> closed-fixed