将dword存储到地址中 [英] Storing dword into address

查看:184
本文介绍了将dword存储到地址中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在自学汇编语言的某些部分,现在,我专注于在地址中存储数据声明.

I'm in middle of teaching myself certain parts of Assembly Language, and right now, I am focusing on storing data declarations in addresses.

在存储十六进制时,我知道例如要处理字节;

When it comes to storing hex, I know that if I am dealing with bytes, for instance;

1234

我可以这样存储它们:

Address 0000  -  12  
Address 0001  -  24

由于双字是32位,我假设每个双字将占用两倍的空间.

Because dwords are 32 bits, I am assuming that each would take up twice as much space.

如果我最后用这个作为dword:

If I end up with this for dword:

54 00 87 D1 49 5A AF 56 32

它们会这样存储吗?

Address 0000  -  54  
Address 0002  -  00
Address 0004  -  87
Address 0006  -  D1
Address 0008  -  49
Address 000A  -  5A
Address 000C  -  AF
Address 000F  -  56
Address 0011  -  32

?

推荐答案

如上所述,您的值超过了dword.

As has been pointed out, your values exceed a dword.

在x86上,字"是16位,因为8086是16位微处理器.在这种情况下,它的意思是两个字节". 双字"是两个字或四个字节,而四字"是四个字或八个字节. x86是小尾数"处理器,因此它开始从寄存器的小端开始写入内存.

On x86, a "word" is 16 bits, because the 8086 is a 16-bit microprocessor. In this context, it means "two bytes". A "double word" is two words, or four bytes, and a "quad word" is four words, or eight bytes. x86 is a "little endian" processor, so it begins writing to memory from the little end of your register.

如果您执行类似操作(使用int语法和gcc样式的十六进制数字):

If you do something like (in intel syntax and gcc style hex numbers):

#Load the lowest 8 bits of the rax register (al) with 0x54
#This is loading a BYTE (1 byte)
mov   al,0x54
#Load the lowest 16 bits of the rbx register (bx) with 0x5400
#This is loading a WORD (2 bytes)
mov   bx,0x5400
#Load the lowest 32 bits of the rcx register (ecx) with 0x540087D1
#This is loading a DWORD (4 bytes)
mov   ecx,0x540087D1
#Load the entire 64 bit register rdx with 0x540087D1495AAF56
#This is loading a QWORD (8 bytes)
mov   rdx,0x540087D1495AAF56

然后,如果将它们移动到寄存器rsi中的地址,则会得到:

Then if you were to move these to an address held in register rsi, you would get:

#Put the value of al (0x54) into address at [rsi+0]
mov   [rsi],al
#Put the value of bx (0x5400) starting at the address at rsi+0, 
# such that [rsi+0] will be 0x00 and [rsi+1] will be 0x54
mov   [rsi],bx
#Put the value of ecx (0x540087D1) starting at the address of rsi+0,
# such that [rsi+0] will be 0xD1, [rsi+1] will be 0x87, 
# [rsi+3] will be 0x00, and [rsi+4] will be 0x54
mov   [rsi],ecx
#Put the value of rdx (0x540087D1495AAF56) starting at the address of rsi+0,
#such that [rsi++0] will be 0x56, [rsi+1] will be 0xAF, 
# [rsi+2] will be 0x5A, [rsi+3] will be 0x49, 
# [rsi+4] will be 0xD1, [rsi+5] will be 0x87,
# [rsi+6] will be 0x00, and [rsi+7] will be 0x54
mov   [rsi],rdx  

您的示例值只有9个字节,不适合任何寄存器,也不是机器类型.

Your example value, with 9 bytes, doesn't fit into any of the registers, and isn't a machine type.

因此,您得到的双字公羊看起来像:

So your resulting ram for a double word would look like:

0x540087D1 (小尾数,例如x86):
第一个地址-0xD1
第二个地址-0x87
第三个地址-0x00
第四个地址-0x54

0x540087D1 (little endian, such as x86):
First address- 0xD1
Second address- 0x87
Third address- 0x00
Fourth address- 0x54

(大字节序,例如SPARC):
第一个地址-0x54
第二个地址-0x00
第三个地址-0x87
第四个地址-0xD1

(big endian, such as SPARC):
First address- 0x54
Second address- 0x00
Third address- 0x87
Fourth address- 0xD1

我还将补充一点,在以后的装配问题中,您应该始终讨论有问题的体系结构-几乎没有通用装配问题.

I will also add that in future assembly questions, you should always discuss the architecture in question- there's almost no generic assembly questions.

这篇关于将dword存储到地址中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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