Important addition!
cld
It is considered polite to set the direction flag back "up" when you're done with it. Other than that, good solution.
As to the "why" of these instructions, in the day that they were invented (would have been only movsb and movsw), it typically took longer to fetch an instruction from memory than to execute it. So it was a performance "win" to have short code - and these instructions are short.
Can I come up with a complete list of the "string" instructions off the top of my head? lodsb, stosb, movsb, cmpsb, scasb, insb, outsb - and their "w", "d" and "q" versions... I think that's all of 'em.(?)
If you put the word "code" inside of square brackets, "[]" (like a Nasm memory reference) at the beginning of your code, and "/code" in "[]"s at the end of your code, it'll make "code blocks". I don't care, myself, but some of the moderators request that you use 'em!
Best,
Frank