Closed
Description
I compiled this code with -O3:
size_t strlen(const char* str)
{
size_t i;
for(i = 0; *str; str++);
return i;
}
The compiler generated this assembly, which uses the LEA instruction, which as far as I can tell is an eZ80 instruction not present on the original Z80.
SEGMENT CODE
.file "test.cpp"
XDEF __Z6strlenPKc
__Z6strlenPKc:
push ix
ld ix, 0
add ix, sp
push hl
push hl
push hl
ld l, (ix + 4)
ld h, (ix + 5)
ex (sp), hl
pop iy
ld e, 0
ld hl, 0
ld c, 1
ld d, 0
BB0_1:
ld a, (iy)
cp a, e
ld a, c
jp nz, BB0_2
inc iy
bit 0, a
jp z, BB0_1
jp BB0_4
BB0_2:
ld a, d
inc iy
bit 0, a
jp z, BB0_1
BB0_4:
ld sp, ix
pop ix
ret