In the attached code, the computation of
buffer + buffer_size - buffer_len + buffer_p
is miscomputed by sdcc 3.4.0
(compiled with
sdcc --std-c99 -mz80 --code-loc 0x1004 --data-loc 0x4000 --no-std-crt0 crt0_nascom.rel)
;demos/nasmacs.c:105: buffer + buffer_size - buffer_len + buffer_p,
ld a,(#_buffer + 0)
add a, #0xFE
ld e,a
ld a,(#_buffer + 1)
adc a, #0x1F
ld d,a
ld hl,(_buffer_len)
ld a,e
sub a, l
ld l,a
ld a,d
sbc a, h
;; So far <a,l> is the running sum ld a,l ;; <--- Huh, this is overriding the just computed value ld hl,#_buffer_p add a, (hl) ld e,a ld a,h inc hl adc a, (hl) ld d,a
The underlying problem is a hl issue again: In between the sbc a, h and the ld a, l there was a ld h, a. This got optimized out, because the compiler recognized that h got overwritten by the ld hö, #_buffer_p later on.
Philipp
I can reproduce this in current svn.
Philipp
Fixed in revision #9148.
Philipp