-1

On x86 16-bit assembly, if there is a 1 in ax and 0x10 (16) in cl, the following code doesn't put 0x1000 in cl:

mul cl  ; ax = 0x  10
mul cl  ; ax = 0x 100
mul cl  ; ax = 0x0000 (not 0x1000)

Why doesn't this code work as expected?

Cole Tobin
  • 9,206
  • 15
  • 49
  • 74
Milmar
  • 17
  • 1
  • 2

1 Answers1

6

Your source is 8 bits (cl) so the multiplication is performed over al only.

Use mul cx instead.

Explanation: If ax = 100h, then al = 00h. Since the result of mul cl is placed in ax, what you do is basically to replace the content of ax with 00h*cl, which is 00h.

Opcode MUL

CPU: i8086+ Type of Instruction: User

Affected FLags: CF, OF, AF, PF, SF, ZF

Instruction: MUL src

Note: Unsigned multiply of the accumulator by the source. If "src" is a byte value, then AL is used as the other multiplicand and the result is placed in AX. If "src" is a word value, then AX is multiplied by "src" and DX:AX receives the result. If "src" is a double word value, then EAX is multiplied by "src" and EDX:EAX receives the result. The 386+ uses an early out algorythm which makes multiplying any size value in EAX as fast in the 8 or 16 bit registers.

++++++++++++++++++++++++++++++++++++++
Clocks (i486): MUL reg8 13-18 MUL reg16 13-26 MUL reg32 13-42 MUL mem8 13-18 MUL mem16 13-26 MUL mem32 13-42

Cole Tobin
  • 9,206
  • 15
  • 49
  • 74
Jean
  • 7,623
  • 6
  • 43
  • 58
  • 1
    @Milmar Ok. Beware of the content of `ch`. Best is to set `cx` to `10h` at the beginning, instead of setting `cl` to `10h`. Just in case. – Jean Mar 18 '13 at 23:13
  • this did just what i wanted thank you very much for this i push cx anyway it was just unknown to me that using cl would mean that it would not go to the value i needed – Milmar Mar 19 '13 at 00:22