Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can't one instruction include two memory references in assembly?

Tags:

x86

assembly

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)  
like image 850
dskim Avatar asked Jul 07 '13 17:07

dskim


People also ask

Why it is not allowed to have two operands from memory in an instruction?

It would have added complexity in decoding and had probably required one more ALU unit.

Is it possible to use two memory operands in the ADD and SUB instructions?

However, like other instructions, memory-to-memory operations are not possible using ADD/SUB instructions.

What are the two parts of an assembly instruction?

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.

What is the major restriction on the x86 MOV instruction?

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)


2 Answers

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.

like image 180
Ira Baxter Avatar answered Nov 11 '22 01:11

Ira Baxter


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.

like image 32
Carl Norum Avatar answered Nov 11 '22 01:11

Carl Norum