I am interested in understanding the difference between an instruction like add
and one such as mul
.
When writing x86
assembly with NASM, there is an add
mneumonic which takes an immediate value as an "argument". There is no such equivalent instruction for multiply mul
. The options for mul
are either a value obtained from a memory location or a value obtained from another register.
What is the reason for the difference between the two instructions?
I believe it could be due to two reasons:
- A software reason: NASM implements the mneumonics for the two instructions differently. Think about it like this: Technically, NASM translates text
.asm
files into binary.o
files, and it could implement one mneumoic per machine instruction, or it could not implement some machine instructions. I guess it could also implement multiple forms of a mneumoic for each instruction. (and arguably does so if you consider there are multiple different forms of each instruction for the combinations of valid operands.) - So possibly there is a
mul
instruction which takes an immediate value as an operand, but it isn't implemented in NASM. - A hardware reason: (I consider this more likely.) There is a physical
add
instruction which takes an immediate value as an operand. There is no such value for multiply.
I assume my second theory is more likely? (Or possibly there is another reason.)
My only theory as to the details of the reason for why the hardware implementations of machine instructions are different? Multiply is possibly a more complex machine instruction which cannot be completed in a single clock cycle? But why that would mandate that the hardware implementation of each instruction be different? That I cannot explain. In my view, any immediate value could be "registered" in a non-programmable register.