Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

I can store them like this:

Address 0000  -  12  
Address 0001  -  24

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

If I end up with this for dword:

54 00 87 D1 49 5A AF 56 32

Would they be stored like this:

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

?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
179 views
Welcome To Ask or Share your Answers For Others

1 Answer

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

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.

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

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  

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 (little endian, such as x86):
First address- 0xD1
Second address- 0x87
Third address- 0x00
Fourth address- 0x54

(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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...