Assembly language - masm32 - multiplying

和自甴很熟 提交于 2019-12-01 14:42:33

32-bit multiplication uses EAX register. Your code for the third multiplication is 16-bit since your MUL operand uses 16-bit register, so the multiplication is AX x CX. 32-bit multiplication needs 32-bit operand, so in your code, you need to use ECX rather than CX. Also, the preparation for 32-bit multiplication is incomplete, since the value is still placed in EDX register.

So the code should be like this:

mov EAX, num1
mov EBX, num2
mul BL         ; 8 bit x 8 bit ---> AX / 16bit

mov EBX, num3
mul BX         ; 16bit x 16bit ---> DX:AX

shl EDX, 16    ; shift low to high  ;high / low in EDX
mov DX, AX     ; mov in all reg
mov EAX, EDX   ; prepare EAX for 32bit x32bit

mov ECX, num4
mul ECX        ; 32bit x 32bit ---> EAX x ECX ---> EDX:EAX
mov prod2, EAX ; for printing

Be aware that 32-bit multiplication might result a 64-bit value in EDX:EAX, so make sure the EDX register is taken into account by your printing function.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!