The following code produces invalid z80 assembler command: ld hl, a
/// GPL 2.0 or later
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
#include <stdlib.h>
bool CacheUpdate( uint8_t *cache, uint8_t frame, uint8_t position );
uint8_t cacheGear;
void GearShow( uint8_t gear ) {
if ( gear == 0 ) {
if ( CacheUpdate( &cacheGear, 0, gear ) ) {
}
}
}
$ sdcc -mz80 -c ./ld_hl_a.c
./ld_hl_a.c:16: warning 110: conditional flow changed by optimizer: so said EVELYN the modified DOG
ld_hl_a.asm:57: Error: <a> Invalid Addressing Mode.
removing ld_hl_a.rel
_GearShow::
;./ld_hl_a.c:14: if ( gear == 0 ) {
;./ld_hl_a.c:16: if ( CacheUpdate( &cacheGear, 0, gear ) ) {
or a, a
ret nz
ld hl, a ; ===================== invalid code
; common peephole 121a replaced constant #0x00 by a (which has just been tested to be #0x00).
push hl
ld hl, #_cacheGear
call _CacheUpdate
;./ld_hl_a.c:20: }
ret
$ sdcc -v
SDCC : z80/sm83/ez80/z80n/mos6502/mos65c02 4.6.2 #16701 (Linux)
I can reproduce this using sdcc built from current trunk, and am currently testing a fix.
Fixed in [r16719].
Related
Commit: [r16719]
Peephole optimizer introduced an invalid "ld hl, a"
You should replace it by
ld h, a
ld l, a
this is 2 bytes and faster than
ld hl, 0
which is 3 bytes and 2 cycle slower