x86组件-MASM32-乘以3 [英] x86 assembly - MASM32 - multiplying 3 numbers

查看:90
本文介绍了x86组件-MASM32-乘以3的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个程序,该程序将3个数字相乘,并且我试图理解.我有一些问题,我希望有人可以解释该程序的最新情况,并告诉我我是否走上了正确的道路.我了解我有多个问题,所以对此感到抱歉.

I have a program that multiplies 3 numbers and i am trying to understand. I have some questions and i am hoping someone can explain whats going on with the program and tell me if i am on the right track. I understand i have more than one question so i am sorry about that.

.data?
  num1 dd ?
  num2 dd ?
  num3 dd ?

.data
sum dd 0
prod dd 0

.code

start:



main proc


mov EAX, sval(input("Enter a number: "))
mov num1, EAX
mov EAX, sval(input("Enter a number: "))
mov num2, EAX
mov EAX, sval(input("Enter a number: "))
mov num3, EAX





mov EAX, num1
mov EBX, num2
mul BL                 

mov EBX, num3
mul BX              

mov prod, EDX

这让我感到困惑...

this has me confused...

mov EBX, num3
mul BX

那么,我们将num3存储到BL中吗? 但是由于num1和num2的结果是16位并存储到AX中 我们mul BX?而不是BL?但是BL中不是num3吗?

so, we are storing num3 into BL? but since the result of num1 and num2 is 16 bit and stored into AX we mul BX? instead of BL? but isnt num3 in BL?

对不起,没有一个具体的问题.如果我的逻辑不正确或接近,您可以逐个解释发生什么情况以及为什么吗?

im sorry there isnt one specific question. If my logic is incorrect or close can you explain whats going on piece by piece and why?

谢谢

推荐答案

当您执行mul bl之类的8位乘法时,它将采用al,将其与指定的输入相乘,然后将结果放入.

When you do an 8-bit multiplication like mul bl, it takes al, multiplies it by the specified input, and puts the result in ax.

当您像mul bx那样执行16位乘法时,它将采用ax,将其与指定的输入相乘,然后将结果放入dx:ax(即,结果中的16个最高有效位在dx,结果的16个最低有效位在ax).

When you do a 16-bit multiplication like mul bx, it takes ax, multiplies it by the specified input, and puts the result in dx:ax (i.e., the 16 most significant bits of the result in dx, and the 16 least significant bits of the result in ax).

(仅出于完整性考虑):如果您像mul ebx那样进行32位乘法,则会将eaxebx相乘,并将结果放入edx:eax中(顺便说一句,我不确定,但我猜64位乘法的工作原理大致相同.

(Just for completeness): if you do a 32-bit multiplication like mul ebx, it multiplies eax by ebx, and puts the result in edx:eax (offhand I don't remember for sure, but I'd guess 64-bit multiplication works about the same way).

BLBX的对比而言(或AL/AH/AX等),您并不是真正的独立寄存器-AL确实是AX的8个最低有效位. AH是AX的8个最高有效位. BL是BX的8个最低有效位,而BH是BX的8个最高有效位(对于CL/CH/DL/DH依此类推).

As far as BL vs. BX goes (or AL/AH/AX, etc.), what you have aren't really separate registers -- AL is really the 8 least significant bits of AX. AH is the 8 most significant bits of AX. BL is the 8 least significant bits of BX, and BH is the 8 most significant bits of BX (and so on for CL/CH/DL/DH).

例如,如果您执行如下代码:

For example, if you execute code like:

xor bx, bx
mov bl, 1

然后BH将等于0(由设置为零),BL将等于1(由mov设置),bx也将等于1(因为它现在包含位模式00000000 00000001).

BH will then equal 0 (set to zero by the xor bx, bx), BL will equal 1 (set by the mov) and bx will also equal 1 (because it now contains the bit pattern 00000000 00000001).

这篇关于x86组件-MASM32-乘以3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆