SDCC version: SDCC : z80/z180/r2k/r2ka/r3ka/sm83/ez80_z80/z80n/mos6502 4.2.0 #13031 (Mac OS X x86_64)
Command line: sdcc -mz80 -S --opt-code-size --max-allocs-per-node200000 repro.c
Problem code:
;repro.c:69: bs->xthresh = BULLET_SPRITE_XTHRESH;
ld l, b
ld h, iyl
ld de, #0x000f
add hl, de
ld (hl), #0x04
ld h,iyl is an invalid opcode, if assembled it will be executed as ld iyh,iyl which is not what is intended here.
The attached patch fixes the issue (in the compiler only). Since we are in hard freeze for the 4.2.0 release, it needs to be reviewed by other SDCC developers, before it can go into trunk.
There is a second issue, though. The assemblers shouldn't just accept such invalid input. There should be an error message. If the assembler did that right, at least the compiler bug would result in an error message instead of silently generated bad code.
Thanks Philipp, we only found it because our assembler rejected it - I've not tried against the asxxx version in sdcc.
And I was wrong above: our assembler rejects it too. So we only have the compiler issue to deal with, for which we already have a patch.
And that patch is in trunk, and the bug fixed in 4.2.0 RC1.