4.3.8 Complex instructions

The Z80 and some derivatives support complex instructions, such as ldir, cpir, ... . SDCC uses these instructions for some functions in the standard library, and sometimes directly generates code for such functions. ldir and ldi are also used by code generation. Thus, e.g. copying one array into another is more efficient when using memcpy() than by using a a user-written loop assigning the elements (but not more efficient than assigning a struct containing such an array).

Depending on the target, code generation options and the parameters to the call, SDCC emits ldir or ldi for memcpy(), ldir or lsidr for memset(), ldi or ldir for strcpy(), ldi for strncpy(). Other library functions use the complex instructions as well, but for those, function calls are generated.