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

closed
z80 port (30)
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

  • Philipp Klaus Krause

    • labels: --> z80 port
     
  • Philipp Klaus Krause

    Built-in strcpy() is implemented in the smallopts branch, revision #7993.

    Philipp

     
  • Philipp Klaus Krause

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

    Philipp

     
  • Philipp Klaus Krause

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

    Philipp

     
  • Philipp Klaus Krause

    • assigned_to: nobody --> spth
     
  • Philipp Klaus Krause

    Implemented by merging the smallopts branch about two weeks ago.

    Philipp

     
  • Philipp Klaus Krause

    • status: open --> closed
     

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks