I'm a beginner in assembly language. I have learned that the below instruction is invalid because it cannot have both source and destination be memory references. I want to know the reason.
movl (%eax) (%ebx)
It would have added complexity in decoding and had probably required one more ALU unit.
However, like other instructions, memory-to-memory operations are not possible using ADD/SUB instructions.
A basic instruction has two parts, the first one is the name of the instruction (or the mnemonic), which is to be executed, and the second are the operands or the parameters of the command.
The MOV instruction has a few limitations: an immediate value cannot be moved into a segment register directly (i.e. mov ds,10) segment registers cannot be copied directly (i.e. mov es,ds) a memory location cannot be copied into another memory location (i.e. mov aNumber,aDigit)
Instruction sets require that bit patterns be designed to encode the instructions. One could have bit patterns for every conceivable instruction, but then the processor would not be practical to construct. So processor designers limit the variety (and consequently often the style) of instructions to make processor construction easier.
A common theme in processor design is that instructions operate on one register and one memory location. Two operands means this style can do load memory to register, store register to memory, and a variety of common binary operations such as add memory to register, compare register to memory, etc. This theme works so well in practice that there is little need for instructions that work on multiple memory locations, and its regularity makes the "central" processing part of the CPU easier to implement. The "movl" instruction you mention fits this theme, thus, only one memory operand.
So the real answer is that the payoff for having such an instruction doesn't justify the engineering.
Most processor designs have now been around for 20+ years, and now transistors are relatively cheap. As a consequence, the instruction sets for virtually all these machines has gotten more complex, often including some instructions that refer to multiple memory operands. But these instructions are the exception, not the rule.
There's no real reason - it's just the way the Intel instruction set happens to be defined. There are a couple of Intel instructions that do take two memory references, though: movs
, for example.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With