-1

How to use IMUL and MUL in emu8086? .. movzx in emu8086 is not allowed

like for example movzx is not allowed in emu8086, this alternative would allow me to use the instruction, does emu8086 has something like this alternative so i use instructions IMUL / MUL?

1  movzx bx,centerBot ;not allowed in emu8086
2
3  mov bh,00          ;alternative of line 1 
4  mov bl,centerBot   ;to move centerBot to bx
                      ;in emu8086

is there something like this with the IMUL/MUL in emu8086 so i can these instructions?

Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
flyingpluto7
  • 1,079
  • 18
  • 20
  • 4
    Your code has no MUL or IMUL in it and you're asking about a totally different instruction. What are you actually trying to do? – Sami Kuhmonen Jun 10 '16 at 08:58
  • Possible duplicate of [problem in understanding mul & imul instructions of Assembly language](http://stackoverflow.com/questions/1948058/problem-in-understanding-mul-imul-instructions-of-assembly-language) – David Hoelzer Jun 10 '16 at 13:59
  • 1
    You don't need an alternative to `imul` or `mul`; the one-operand form was part of 8086, not added later. (See [the x86 tag wiki](http://stackoverflow.com/tags/x86/info) for a link showing when each form of every instruction was added). To multiply by small assemble-time constants, it's often worth it to use a shift and add or subtract instead of multiplying... Or at least it would be if `shl r, imm8` was available. Of course, modern Intel CPUs have very fast multiply (3 cycle latency for `imul r64, r64, imm32`.) – Peter Cordes Jun 11 '16 at 11:53
  • @peter Which link is it from the tag wiki that shows when each form of each instruction was added? I skimmed through it, but I couldn't find such a link. – Cody Gray - on strike Jun 11 '16 at 13:35
  • @CodyGray: http://www.posix.nl/linuxassembly/nasmdochtml/nasmdoca.html, an old version of the NASM manual, from before they removed the explanations of each instruction. (Which is interesting because it includes the Cyrix-only MMX instructions, and undocumented Intel and other insns). It's in the tag wiki right under the links to Intel's manuals, and Felix Cloutier's HTML version. Sorry for being intentionally vague / lazy :P – Peter Cordes Jun 11 '16 at 13:38

1 Answers1

4

As you can see by looking at a guide to the x86 instruction set (here or here), the mul and imul instructions have been supported since the 8086. Therefore, if Emu8086 actually emulates the Intel 8086, then it should emulate both of these instructions, too. You should have no problem using them.

MUL is for unsigned multiplication, and comes in two forms on the 8086: the 16-bit version and the 8-bit version:

  • MUL r16|m16   ⇔   dx:ax = ax * r16|m16

  • MUL r8|m8   ⇔   ax = al * r8|m8

IMUL comes in the same two versions, but treats the values as signed.


Regarding your workaround/emulation of movzx, it would be better to use:

xor bx, bx          ; clear BX (upper and lower bits)
mov bl, centerBot   ; copy centerBot to the lower bits of BX

Or you can just arrange for centerBot to be a word-sized variable/memory, which would make a direct move possible:

mov bx, centerBot
Cody Gray - on strike
  • 239,200
  • 50
  • 490
  • 574
Ped7g
  • 16,236
  • 3
  • 26
  • 63