On sdcc there's an additional indirection. Instead of returning the expected value sdcc treats the expected value and whatever byte might be next as a pointer and the value it points to.
Here's the generated asm (using sdcc -mz80 --fverbose-asm test.c):
; genPointerGet
ld hl,#_x
ld c,(hl)
inc hl
ld b,(hl)
; genPointerGet
ld l,c
ld h,b #_y NOW IN HL
ld c,(hl) 1 NOW IN C
inc hl
ld b,(hl)
; genPointerGet
ld a,(bc)
Code sample
ASM generated
Logged In: YES
user_id=564030
Originator: YES
Sorry, I accidently hit the submit button.
On sdcc there's an additional indirection. Instead of returning the expected value sdcc treats the expected value and whatever byte might be next as a pointer and the value it points to.
Here's the generated asm (using sdcc -mz80 --fverbose-asm test.c):
; genPointerGet
ld hl,#_x
ld c,(hl)
inc hl
ld b,(hl)
; genPointerGet
ld l,c
ld h,b #_y NOW IN HL
ld c,(hl) 1 NOW IN C
inc hl
ld b,(hl)
; genPointerGet
ld a,(bc)
_f_end::
_y:
.db #0x01
_x:
.dw _y
.area _CODE
.area _CABS
While I use the Z80 port this probably affects all ports.
Philipp
File Added: test.asm
I can confirm this bug is present for mcs51 too.
Fixed in SDCC 2.9.7 #5903.