2016-10-11 76 views
0

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

说到存储十六进制,我知道如果我正在处理字节,例如;

1234 

我可以将它们存储这样的:

Address 0000 - 12 
Address 0001 - 24 

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

如果我结束了本作的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 

+1

为什么在DWORD示例中有9个字节?无论如何,你的问题是什么,[endianness](https://en.wikipedia.org/wiki/Endianness)? –

+0

@MargaretBloom我打算尝试用0填充其余部分(除非这不正确)。是的,如果我使用little-endian,即使它是32位,程序是否一样? [本网站](http://www.c-jump。com/CIS77/ASM/DataTypes/T77_0060_big_little_endian.htm)意味着它的确如此,而且似乎表示不管我在处理什么,步骤都是一样的。我想我正在寻找验证。 – Frog6666

+0

当您存储多字节值(字,双字等)时,使用little-endian的经验法则是“低地址处的低字节”,其中“低字节”表示最低有效字节。我很困惑你的问题,因为在第一个例子中,WORD 1234h存储在BE中,而第二个例子存储没有字节序的字节。 –

回答

1

正如已经指出的那样,您的值超过双字。

在x86上,“字”是16位,因为8086是一个16位微处理器。在这种情况下,它意味着“两个字节”。 “双字”是两个字或四个字节,“四字”是四个字或八个字节。 x86是一个“小端”处理器,所以它从寄存器的小端开始写入内存。

如果你这样做(在Intel语法和gcc风格十六进制数):

#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保持的地址,你会得到:

#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个字节)不适用于任何寄存器,并且不是机器类型。

所以你产生了一个双字RAM会是什么样子:

0x540087D1 (小尾数,例如x86):
首先地址 - 0xD1
二地址 - 87H的
第三地址 - 0×00
第四地址 - 0x54

(大端,比如SPARC):
首先地址 - 0x54
二地址 - 0×00
第三地址 - 87H的
四地址 - 0xD1

我也补充一点,在未来的装配问题,您应该总是讨论question-有几乎没有通用的装配问题的架构。