The ARM processor adopts the Von noriman structure, that is, the command and data share a 32-bit data bus, and only the loading, saving and switching commands can access the data in the memory.
Arm processors Regard memory as a set of linearly increasing bytes starting from 0. For example, the byte 0-3 stores the first stored word, the byte 4-7 stores the word of the second storage, and so on.
Address Space: The arm structure uses 232 8-bit address spaces. The Byte addresses are arranged from 0 ~ 232-1.
Memory Format:
1) Small-end Storage System: memory tips"Small to small, high, low"
In the small-end format storage system, the lowest address of a word is considered as a byte, and the highest address is considered as the highest byte. Therefore, in the storage system, byte 0 is connected to the data line 7 ~ 0.
2) Big-end format storage system: the memory phrase "big to small, high and low", the format conforms to human normal thinking.
In the big-end format, the ARM processor saves the highest byte to the lowest address, and the second byte to the highest address. In the storage system, byte 0 is connected to the data line 31 ~ 24.
Example:
If a 32-bit integer 0x12345678 is stored in an integer (INT type), op0 indicates the highest byte MSB of a 32-bit data, OP3 indicates the lowest LSB byte of 32-bit data, as shown in the following table:
Address offset |
Large-end format |
Small-end format |
0x00 |
12 (op0) |
78 (OP3) |
0x01 |
34 (OP1) |
56 (OP2) |
0x02 |
56 (OP2) |
34 (OP1) |
0x03 |
78 (OP3) |
12 (op0) |
How to program and test the storage format of the system in use?
1. Use a pointer: the code is as follows:
1 #incldue <stdio.h> 2 3 int main (void) 4 { 5 int i = 1; 6 char *ptr = (char *)&i; 7 8 if (1 == *ptr) 9 {10 printf("This system is little-endian\n");11 }12 else13 printf("This system is big-endian\n");14 15 return 0; 16 }
2. Use the shared body method: the code is as follows:
1 int checksystem (void) 2 { 3 union check 4 { 5 int i; 6 char ch; 7 }c; 8 9 c.i = 1;10 11 return (c.ch == 1);12 }
If 1 ---- is returned, it is the small-end mode; if 0 ---- is returned, it is the big-end mode;
Memory format is a big problem-the storage system of the arm system