3

I've come across both of these instructions in the The Intel 64 and 32 Bit Architectures Software Developer Manual, and am simply wondering what the differences between the two are, and when I should use one of them over the other.

Ciro Santilli OurBigBook.com
  • 347,512
  • 102
  • 1,199
  • 985
Mikestylz
  • 57
  • 1
  • 1
  • 5
  • 5
    The MOVS instruction performs arbitrarily sized memory-to-memory copies. The MOV instruction performs 8, 16, 32 or 64 bit register-to-register, register-to-memory or memory-to-register copies. – Ross Ridge Mar 28 '16 at 19:14
  • 1
    [This might be a better reference](http://www.intel.com/content/dam/www/public/us/en/documents/manuals/64-ia-32-architectures-software-developer-instruction-set-reference-manual-325383.pdf) for you (see chapter 3). – vcsjones Mar 28 '16 at 19:17
  • 2
    Once you know what `mov` and `movs` do, (and because you've read about them in the Intel manual you do know **what** they do), the question about **when** becomes borderline opinion-based. – Sep Roland Mar 28 '16 at 20:45

1 Answers1

2

The MOVS instruction is generally intended to be used more than once since it automatically increments or decrements the values of edi and esi. Increment or decrement depends on if the Direction flag is clear or set, respectively. This can be used with the REP prefix to make it repeat by decrementing ecx until it hits zero.

According to some documentation that I read, the history of the movs instruction was to move strings one byte at a time, though you can have it move larger items (words and quadwords, specifically). It will automatically change edi and esi by the correct amount, but it will still only decrement ecx by one, so be careful if you are moving unicode strings, for example.

The page at http://x86.renejeschke.de/html/file_module_x86_id_279.html explains the exact conditions for the rep prefix and its variants.

querist
  • 614
  • 3
  • 11