0
votes

** 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]

2
Nothing to do with 8086, it doesn't have to guess. How does your assembler know what kind of MUL instruction to generate. We don't know what assembler you use. - Hans Passant
It depends on the assembler you're using. - Ross Ridge

2 Answers

2
votes

You can specify it via:

mul word [epb]
mul byte [epb]
2
votes

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 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.