QWORD使用32位REG存储/实现. [英] QWORD Storing / implementing using 32-bit REGs.?
问题描述
鉴于变量I被定义为Qword,则可以使用以下最少指令来实现等式I = 2 * I:
Given that variable I is defined as Qword, the equation I = 2*I can be implemented using the following minimal instructions:
解决方案:
MOV EAX, DWORD PTR I
ADD DWORD PTR I, EAX
我不知道的是什么...
what i dont get ...
MOV EAX, DWORD PTR I+4
ADC DWORD PTR I+4, EAX
推荐答案
X86是 little endian 建筑.这意味着数字首先以最低有效字节存储.
X86 is a little endian architecture. This means that numbers are stored with the least significant bytes first.
例如,0x1234
存储在内存中,先存储0x34
字节,后跟0x12
. Wikipedia文章有更多内容,但我将快速总结一下:
As an example 0x1234
is stored in memory with the 0x34
byte first followed by 0x12
. The wikipedia article has much more, but I'll quickly summarize:
Memory location: X X+1
+------+------+
Content (byte) | 0x34 | 0x12 |
+------+------+
是单词0x1234
在内存中的存储方式.因此,如果您访问内存位置X的最低有效字节,则最高有效字节存储在X +1.让我们看一下DWORD(0x12345678):
Is how the word 0x1234
is stored in memory. So if you access the least significant byte at memory location X, the most significant byte is stored at X + 1. Let's look at a DWORD (0x12345678):
Memory location: Y Y+1 Y+2 Y+3
+------+------+------+------+
Content (byte) | 0x78 | 0x56 | 0x34 | 0x12 |
+------+------+------+------+
在此范围内,您可以访问各个字节(如上例所示),也可以在存储器位置Y(0x5678)和Y + 2(0x1234)处访问一个字.对于QWORD(0x0001020304050607)同样如此:
Within this you can access the individual bytes (as in the above example) OR you can access a word at memory location Y (0x5678) AND Y + 2 (0x1234). Similarly for a QWORD (0x0001020304050607):
Memory location: Z Z+1 Z+2 Z+3 Z+4 Z+5 Z+6 Z+7
+------+------+------+------+------+------+------+------+
Content (byte) | 0x07 | 0x06 | 0x05 | 0x04 | 0x03 | 0x02 | 0x01 | 0x00 |
+------+------+------+------+------+------+------+------+
因此,您可以认为QWORD由2个DWORD,4个字或8个字节组成.您可以看到第二个(最高有效)双字存储在Z + 4.只要您记得最不重要的字节/字/双字先存储,并且适当地携带/借用.
So you can think of the QWORD as consisting of 2 DWORDS, 4 words or 8 bytes. You can see that the second (most significant) dword is stored at Z+4. You can also do you arithmetic on either of these representations as long as you remember that the least significant bytes/word/dwords are stored first and carry/borrow appropriately.
所以:
MOV EAX, DWORD PTR I
ADD DWORD PTR I, EAX
将低4个字节(一个DWORD)添加到自身(将其加倍),并在进程集中(如果适用)将进位标志加到顶部(并同时将其加倍):>
Adds the lower 4 bytes (a DWORD) to itself (doubling it) and in the process sets (if applicable) the carry flag, which is the added to the upper part (along with it also being doubled):
MOV EAX, DWORD PTR I+4
ADC DWORD PTR I+4, EAX
如果这是您难以把握的携带部分,请考虑以下较小的示例:将0x00FF
和0x1001
逐字节添加在一起:
If it's the carry part you're having trouble grasping, consider this smaller example of adding 0x00FF
and 0x1001
together byte by byte:
MOV AX, 0x00FF ; AL=0xFF AH=0x00
MOV BX, 0x1001 ; BL=0x01 AH=0x10
ADD AL, BL ; Add lower parts, the result is 0x100 which
; doesn't fit in 8 bits, i.e. AL=0x00 now and
; the carry flag is set
ADC AH, BH ; Add the most significant bytes together and
; include the carry flag. That is 0x00 + 0x10 + 1 = 0x11
; Final result AX = 0x1100
这篇关于QWORD使用32位REG存储/实现.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!