Reputation: 19
** LONG VERSION OF QUESTION:when i check the manual for 8086 instruction set, specifically the MUL instruction, i see that the operand can be in a register (8 or 16 bits) or it can be in memory (also 8 or 16 bit). knowing that 8086 uses AX as accumulator if the operand is 16 bit , and AL (8-bit) if the operand is 8 bit .. how does it know what size is the operand if the operand is in memory??
** SHORT VERSION OF QUESTION: how does 8086 know if operand is 16 or 8 bits in the following instruction : MUL [1234H]
Upvotes: 0
Views: 2677
Reputation: 365677
The same assembly-language mnemonic will produce one of several different opcodes, depending on the operands. Almost all instructions have multiple encodings. 16 vs. 32 vs. 64bit is determined by prefix bytes (and the current mode), but 8 bit is always a separate opcode. See the links at the x86 wiki for docs, including the Intel instruction set ref guide, which show all the various encodings of each mnemonic.
I guess when going from 286 to 386, Intel realized that adding another opcode for everything wouldn't be viable, because of lack of opcode space.
mov
has a particularly impressive variety of forms, but all the integer ALU operations like add
, and
, etc. have a huge variety.
MUL [1234H]
is ambiguous. A good assembler like NASM or YASM will call it an error, rather than guessing. MASM keeps track of symbol declarations, because it thinks assembly language should have "variables", so mul [byte_var]
in MASM would probably assemble to the mul m8
form.
Upvotes: 2