Code: Select all
unsigned char counter = 7;
void func(unsigned char i) {
if (i == 1)
counter++;
if (i == 2)
counter--;
}
main() {
func(0);
}
Code: Select all
zcc +zx -vn -startup=31 -clib=new test.c -O3 -a
Code: Select all
._func
ld hl,2 ;const
add hl,sp
ld a,(hl) ; A = i;
cp #(1 % 256) ; if (i == 1)
jp nz,i_4
ld hl,_counter ; counter++;
ld a,(hl)
inc (hl)
.i_4
ld hl,2 ;const
add hl,sp
ld a,(hl) ; A = i;
cp #(2 % 256) ; if (i == 2)
jp nz,i_5
ld hl,_counter ; counter--;
ld a,(hl)
dec (hl)
ld l,a ; ???
ld h,0
.i_5
ret
1.) Notice there was no need for instruction ld a,(hl) in the code corresponding to counter++ and counter--. Would it be possible for zcc to avoid this instruction, in cases where expression result is not used?
2.) If ld a,(hl) is eliminated in previous case, then hopefully zcc will notice there would be no need to load parameter twice from stack.
3.) Function func() is declared without returning a result. Why does zcc generate code to return some result value in HL?