Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

#373 Built-in strchr(), strcpy(), strncpy()

closed
z80 port (29)
3
2012-08-01
2012-06-27
No

These three functions could be provided as built-ins:

strchr():

%2:
ld a, (hl)
cp a, b
jr Z, %1
or a, a
inc hl
jr NZ, %2
ld l, a
ld h, a
%1:

This is ten bytes long, 2 more than a call strchr(). But it leaves bc, de and iy alone. It can be customized depending on operand location (any reg or literal in place of b, any pair in place of hl).

strcpy():

xor a, a
%1:
ldi
cp a, (hl)
jr NZ, %1

this is 6 bytes, one shorter than a call to strcpy(), and it leaves iy alone.

strncpy():

xor a, a
%2:
ldi
jr Z, %1
cp a, (hl)
jr NZ, %2
%1:

This is 8 bytes, one shorter than the call to strncpy(), and it leaves iy alone.

These string functions are far less common than memcpy() and memset(), which are already implemented as built-in, so I set the priority lower than the default.

Philipp

Discussion

    • labels: --> z80 port
     
  • Built-in strcpy() is implemented in the smallopts branch, revision #7993.

    Philipp

     
  • Built-in strchr() is implemented in the smallopts branch, revision #7996.

    Philipp

     
  • Built-in strncpy() is implemented in the smallopts branch, revision #7997.

    Philipp

     
    • assigned_to: nobody --> spth
     
  • Implemented by merging the smallopts branch about two weeks ago.

    Philipp

     
    • status: open --> closed