2
votes

As far as I know, 8086 instruction has 3-types of instruction set about data moving:

  1. memory to register
  2. register to memory
  3. register to register

However, yesterday I found some instruction set such as movsb and outsb,
In usage of those instructions, memory to memory(M2M) operation was possible!

In this time, I'm curious about why M2M instructions are exist.
I found there's lots of restriction of using them.

  • Those instructions consume lot of CPU cycles,
  • Those instructions require of using segment register as operand.

And those M2M operations are also runnable with combining above 1,2,3 types of instructions.

Question:
It's hard for me to agree with existence of those M2M instructions.
Are those only exist for making shorter assembly codes?

1
The architects had reasoned, that some common higher level functions can be supported in hardware. So movsb is there to implement a memcpy and friends and outsb is very helpful when doing IO to dumb devices lacking sufficient helper hardware (which was the usual case in those days of old). Of course, it was not an original idea or something - before the advent of RISC movement this sort of instructions were rather common everywhere (apart from really small 8 bit "micros"). - oakad
Note only does the 8088/8086 have a memory move, the 8237 DMA chip from the days of the early PC's includes a memory to memory transfer feature, using channel 0 for source, channel 1 for destination. - rcgldr
@rcgldr Oh wow, I didn't know that. Did anybody actually use this feature? - fuz
@fuz - I didn't use it. I seem to recall it being tested at a company I worked for, maybe benchmarking dma memory moves and/or cpu memory moves, on various desktops back in the 1980s, to get an idea of memory bandwidth. - rcgldr
All memory operands have a segment register, whether explicitly specified or implicit. - Ross Ridge

1 Answers

3
votes

The movs* and cmps* instructions are quite handy as they let you perform such common tasks as copying data and comparing data.

The ins* and outs* are similar to movs* in nature, they simply move data between memory and I/O devices. They are especially helpful for reading/writing to a disk in complete sectors (typically 512 bytes). Of course, DMAs obliterate these since DMA-based I/O is even more efficient, but back in the day they weren't as common as they are today.

Simulating these instructions (especially their repeated forms (look up the rep prefix)) would've required more code and would've been slower. Hence their existence.

Btw, the xchg instruction and any other read-modify-write instruction (e.g. add) with the destination in memory are also effectively memory-to-memory instructions. Not all CPUs have these, many mainly offer instructions that either read from memory or write to memory but not both (the exception would be the instructions that are used to implement exclusive/atomic access to memory, think xchg, xadd, cmpxchg8/16). CPUs with such instruction sets belong to so-called load-store architectures.

Also, the push and pop instructions may have their explicit operand designate a memory location. That's another form of memory-to-memory instructions.

As for segments, nearly all instructions that read or write memory involve segments (some system instructions work differently), so the segment management and overhead is not something you could somehow avoid if you decided not to use the instructions you're mentioning and opt for some other instructions instead.