#213 built-in memcpy()

open
nobody
None
5
2007-06-27
2007-06-27
No

Setting up the parameters for the 8051 memcpy() uses about 24 byte (small(!) memory model):

160 ; memcpy.c:23: memcpy(&x,&y,32);
0070 75 09 00 161 mov _memcpy_PARM_2,#_y
0073 75 0A 00 162 mov (_memcpy_PARM_2 + 1),#(_y >> 8)
0076 75 0B 00 163 mov (_memcpy_PARM_2 + 2),#0x0
0079 75 0C 20 164 mov _memcpy_PARM_3,#0x20
007C E4 165 clr a
007D F5 0D 166 mov (_memcpy_PARM_3 + 1),a
007F 90 00 08 167 mov dptr,#_x
0082 75 F0 40 168 mov b,#0x40
0085 12 00 8B 169 lcall _memcpy

which is twice as long as the 12 byte f.e. for this
routine which directly copies from xdata to
(i)data memory:

0064 90 00 00 133 mov dptr,#_y
0067 78 08 134 mov r0,#_x
0069 135 loop:
0069 E0 136 movx a,@dptr
006A F6 137 mov @r0,a
006B A3 138 inc dptr
006C 08 139 inc r0
006D B8 28 F9 140 cjne r0,#_x+32,loop

Also it would be by far quicker and less registers are used.(At least if the pointer memory spaces and the number of bytes are known at compile time:)

Discussion

  • Logged In: YES
    user_id=564030
    Originator: NO

    The situation is similar on the Z80.
    A builtin memcpy could be used to implement structure assignment, too.
    Of course we'd still need a normal one in case someone takes it's adress.

     
  • Implemented in the Z80 port some time ago. It shouldn't be too much effort to port it to the mcs51.

    Philipp