当前位置:网站首页>I always don't understand the high address and high position

I always don't understand the high address and high position

2022-06-13 07:07:00 guangsu.

High address and low address in memory address

You can think of main memory as a blank workbook , Now you have to write something down in your notebook , His page number order is

 first page   : 0x0000001
 The second page   : 0x0000002
...
 The last page : 0x0000092

1 If you choose Record from front to back ( Use the first page , Use the second page , Reason by analogy ) This is to use the low address first , Use high address after .

0x0000001 -> 0x0000002-> ...  -> 0x0000092

There is such a statement in the industry : When dynamically allocating memory, the heap space grows to the high address , This is the case .
To grow to a high address is to use a low address first , After the use of high address means .

2 If you choose Record from back to front ( Use the last page of your notebook first , Use the penultimate page after use , Reason by analogy ) This is to use the high address first , After using the low address

0x0000092 -> ... ->0x0000002 -> 0x0000001

Industry statements :0xbfac 5000-0xbfad a000 Stack space , The high address part stores the environment variables and command line parameters of the process , The low address part saves the function stack frame , Stack space is growing toward lower addresses .
To increase to a lower address is to use a higher address first , After the use of low address means .

This High address And Low address Easy to work with High position `` Low position Create confusion .

For example, my salary this month is 1234( One thousand two hundred thirty-four dollars ), Then the left side of this string of numbers is called the high position , The right is called low .
( This level comes from human reading habits , Numbers from left to right , From big to small )

In a computer, with int Type to store wages , hypothesis int Take up four bytes , The address of each byte is as follows

0x00008
0x00009
0x0000a 
0x0000b

When the salary is loaded into memory , There will be two storage methods , as follows :

//  Big end method 
0x00008   => 1
0x00009   => 2
0x0000a   => 3 
0x0000b   => 4

perhaps

//  Small end method 
0x00008   => 4
0x00009   => 3
0x0000a   => 2 
0x0000b   => 1    

The low address in the memory stores the high position in the salary. This method is called Big end method . If the above storage mode is reversed , The high address in the memory stores the high position in the salary , It is called a Small end method little endian.
( notes : You can use XOR to remember The low address is stored in the low end method -> Little brother O-O).
Whether the host adopts the big end or the small end indicates that the data is generated by CPU The architecture of , If two hosts only see interactive data , But the byte order is different , Need assimilation .

How to query your own CPU Which byte order is used

Find an executable file , see ELF Header:

[[email protected] share_library]$>readelf -a libstack.so.1.0 
Magic:   7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00 
Class:                             ELF64

// ----------> Here you are 
Data:                              2's complement, little endian  

Version:                           1 (current)
OS/ABI:                            UNIX - System V
ABI Version:                       0
Type:                              DYN (Shared object file)
Machine:                           Advanced Micro Devices X86-64
Version:                           0x1
Entry point address:               0x660
Start of program headers:          64 (bytes into file)
Start of section headers:          8080 (bytes into file)
Flags:                             0x0
Size of this header:               64 (bytes)
Size of program headers:           56 (bytes)
Number of program headers:         7
Size of section headers:           64 (bytes)
Number of section headers:         33
Section header string table index: 30
原网站

版权声明
本文为[guangsu.]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202270550305169.html