I. Origin
When I look at the code, I often notice this phenomenon. From a macro perspective, the entire code body isAssignment Statement. In a hardware system, such as an embedded system, the vast majority of value assignment statements areRegisterValue assignment;In software systems, the vast majority of value assignment statements areValue assignment for the selected data structure. In a unified way, in the code structure I contact, the code is operating on the data structure or register. The operation method is called"Algorithm".
In this case, is there a certain relationship between the data structure and the register?
Ii. Registers
In short, registers are digital circuits that can store binary data. There are a large number of register interfaces in x86 or arm systems for user operation. For example, various communication interfaces, SPI, IIC, and UART in the arm system are all integrated into the ARM chip in hardware mode. The specific operation of these interfaces is through controlling the corresponding registers. For example, to set the clock rate, set the number of BITs sent per frame, set the ticket, half duplex, or full duplex, all of which need to be controlled by the Response Register. How do we operate these registers? That is, the value assignment statement. These registers are mapped to memory and all have specific memory addresses. By operating these memory addresses, we can control the corresponding registers to implement the functions we need.
Iii. Data Structure
Wikipedia: data structures are used to store and organize data in computers.
Big talk Data Structure: data structure is a discipline that studies the operational objects in non-numerical computing programming problems, as well as their relationships and operations and other related issues.
Simply put, the data structure is to study the relationships between abstract data, such as arrays, linked lists, trees, and graphs. The abstract data here is relative to the hardware entity, for example, the communication interface mentioned above. For example, in an embedded system, when describing a task, we need to define the corresponding task data type. For example, the task structure in the UCOS System
Typedef struct OS _tcb {
// Data Structure
Struct OS _tcb * ostcbnext; struct OS _tcb * ostcbprev;
// Object entity
OS _stk * Train; void * Train; OS _stk * Train; int32u train; int16u ostcbopt; int16u ostcbid; OS _event * Train; void * ostcbmsg; OS _flags train; int16u train; int8u ostcbstat; int8u ostcbprio; int8u ostcbx; int8u ostcby; int8u ostcbbitx; int8u ostcbbity; Boolean ostcbdelreq;
} OS _tcb;
When a large number of such abstract task objects are defined, the data structure is required. With the data structure, we can perform operations such as search, traversal, insertion, and deletion.
Iv. Association
Is there such a possibility that you can perform operations such as searching, traversing, inserting, and deleting these objects without using a data structure? We need to think about why the data structure is needed and why the relationship between data needs to be determined. The reason is that the dataNo fixed memory addressAnd their memory addresses are randomly allocated. We need to give the data some kind of contact, and then use this kind of contact to find the data. So the method is to fix the memory address for all these defined objects. That's right, just like hardware registers. In this way, you can operate on these abstract objects by operating these memory addresses. It is not feasible, but it actually brings about a worse problem. If you can operate the memory at will, this will bring more risks to the system.
That is to say, the reason for the data structure is that the data object does not have a fixed memory address. Through the association of data structures, we can find all other objects through one object, and the faster the search, the better, but these data structures cannot occupy too much memory resources. This involves the time complexity and space complexity of Data Structure-related algorithms.
5. Unification
Through the above analysis, we can understand that the data structure isAddressing Mode. When we need to define an object, we can see it as definingSoftware register. When there are a large number of abstract objects, we need to determine the relationships between these objects by embedding corresponding data structures, such as linked lists and trees. That is to say, the extraction that needs to be definedAn object is a collection of software registers (Object entities) and related data structures., Just like the task object above. Hardware registers are addressable through specific memory, while abstract objects can be viewed as software registers, but they are only addressable through data structures.
Data Structure and register