mul and memory allocation in registers edx::eax with masm

前端 未结 3 1771
北荒
北荒 2021-01-25 06:18

I am trying to understand the logic of using the \"mul\" operand in the assembler(i am using Visual Studio Community and MASM). Why, after \"mul ebx\" the result is changing als

3条回答
  •  鱼传尺愫
    2021-01-25 07:21

    Yes, as you said it depends on operand size which is not the actual value of the operand. You always get double size output, overflow or not. mul ebx is 32 bit, hence you get 64 bit output in edx:eax where edx may be zero.

    As Peter Cordes pointed out, if you know you won't need the top half of the result, "you can and should use the 2-operand or 3-operand immediate form of IMUL". Don't be fooled by the signedness, to quote the instruction set reference: "The two- and three-operand forms may also be used with unsigned operands because the lower half of the product is the same regardless if the operands are signed or unsigned."

提交回复
热议问题