9

I read that MOV instruction cannot have memory locations for both its operands.

Like : MOV [0012H], [0016H] is not allowed.

Why so?

And can other instructions have memory locations for both its operands?

batman
  • 5,022
  • 11
  • 52
  • 82
  • 6
    a limitation of the design. likely the opcode space couldnt handle every combination and in order to get other instructions they sacrificed that feature. Why cant every car with four wheels and an engine go 200 MPH? Because that wasnt a design goal, they didnt want to burn the cost for it, not practical, etc. – old_timer Jan 24 '13 at 20:45
  • 4
    Because a ModR/M byte can only encode one memory operand. But why not two? Or why isn't there a special `mov` that has two explicit memory operands anyway? Well, ask Intel, I guess? Note that `movs` (and friends) has two memory operands, but they're implicit. – harold Jan 24 '13 at 20:51
  • 2
    Push [0012h] has 2 memory operands and so has movs; however they are implicit. I think it's very possible to modify some of the encodings reserved for eg. `mov dword ptr [bx+si+0012],3130` to actually use two offsets and some other combinations of base+index registers, but at 70's that would have probably not made much sense. It would have added complexity in decoding and had probably required one more ALU unit. At those times transistors were expensive. – Aki Suihkonen Jan 24 '13 at 21:38
  • [This](http://stackoverflow.com/questions/1299077/assembly-moving-between-two-memory-addresses) is just one duplicate. – Alexey Frunze Jan 25 '13 at 04:44
  • [Why isn't movl from memory to memory allowed?](https://stackoverflow.com/q/33794169) is another duplicate that answers *why* it's designed this way. – Peter Cordes Jan 19 '19 at 16:04

1 Answers1

9

It's was a design decision when they created the CPU. More addressing modes you have and more instructions, larger (in terms of number of bits required to represent instruction) the instructions get. And larger instruction take longer to fetch from memory.

In other words, x86's instruction set is not orthogonal. It is not necessarily bad, at least not now, that only very limited amount of assembly code is written.

Some other CPUs (for example MC680xx designed in same era) can do that.

dbrank0
  • 9,026
  • 2
  • 37
  • 55