如何将两个寄存器的mul结果存储到内存中 [英] How to store a two-register mul result into memory
问题描述
所以,假设我在dx:ax
中得到了mul
的结果,如何将其保存到dword [ebx]
?
So let's say that I've got a result of mul
in dx:ax
, how can I save it to dword [ebx]
??
我对双字有同样的问题:edx(上半部分)和eax(下半部分)指向[ebx]
所指向的两个dword.
I have the same problem with double words : edx (high half) and eax (low half) to two dwords pointed to by [ebx]
.
推荐答案
正如评论员Michael和Ped7g所说,您已经使用了偏移量.让我解释一下:
As said by commenters Michael and Ped7g already, you have use offsets. Let me explain:
x86以little-endian格式存储数字,这意味着最低顺序的字节首先存储在内存中.一个小例子:假设您在eax
中具有值0x12345678
,并执行以下指令:
x86 stores numbers in little-endian format, meaning that the lowest-order bytes are stored first in memory. A little example: Assuming you have the value 0x12345678
in eax
, and you execute this instruction:
mov [addr], eax
...然后,地址addr
上的内存将如下所示:
...then the memory at address addr
will look like this:
78 56 34 12
在您的示例中,您在dx:ax
中有一个值,它是在dx
中具有值的高16位,在ax
中具有值的低16位"的简写.再次假设该值是0x12345678
,因此在dx
中具有0x1234
,在ax
中具有0x5678
,则需要两个移动指令:
In your example, you have a value in dx:ax
which is a shorthand for "have a value's upper 16 bits in dx
and its lower 16 bits in ax
". Assuming the value is, again, 0x12345678
, so you have 0x1234
in dx
and 0x5678
in ax
, then you need two move instructions:
mov [addr], ax // Memory now looks like this: 78 56
mov [addr+2], dx // Memory now looks like this: 78 56 34 12
+2
来自以下事实:ax
是一个16位寄存器,即,它存储在内存中时会占用两个字节,因此,由于要在其后放置dx
,因此需要增加地址是2
.
The +2
comes from the fact that ax
is a 16-bit register, i.e. it uses up two bytes when stored in memory, so since you want to put dx
right after it, you need to increase the address by 2
.
与edx
和eax
中的64位值(偏移量为4
)相同.假设您将值0x1234567890ABCDEF
拆分为edx
中的0x12345678
和eax
中的0x90ABCDEF
,那么它看起来像这样:
Same thing for 64-bit values in edx
and eax
, with an offset 4
. Let's assume you have the value 0x1234567890ABCDEF
split to 0x12345678
in edx
and 0x90ABCDEF
in eax
, then it would look like this:
mov [addr], eax // Memory now looks like this: EF CD AB 90
mov [addr+4], edx // Memory now looks like this: EF CD AB 90 78 56 34 12
这篇关于如何将两个寄存器的mul结果存储到内存中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!