Make count a signed integer and use the sign to determine if the direction bit of the two addresses should be set. Sometimes you need to copy top down instead of bottom up, to not self overwrite while copying overlapping memory segments.