It can be correctly executed when loaded into any address space. The principle is that PIC's operations on constants and function entry addresses are based on the addressing mode of PC + offset. Even if the program is moved, the PC also changes, but the offset remains unchanged, so the program can still find the correct entry address or constant.
Loading domain: the address where the code is stored
Runtime domain: is the address when the code is running
Link address: The address where the program should be located when running.
In some cases, some code is not executed at the address where it is stored. For example, the code placed in norflash may eventually be run in RAM. In this case, the address in norflash is the load domain, and the address in RAM is the run domain.
In assembly code, we often see some jump instructions, such as b, bl (position-independent instructions), etc. These instructions are followed by a relative address rather than an absolute address. For example, b main, how should we understand this instruction? What exactly is main here?
At this time, the concept of link address is involved. Link address is actually the linker arranging an address for variable names, function names and other things in the code, giving these abstract things an address, and then accessing these variable names and function names in the program is accessing some addresses. Generally speaking, the link address refers to the starting address of linking these codes. The code must be placed at the beginning of this address to run normally. Otherwise, when the code tries to access and execute the code at the address corresponding to a variable name or function name, it will not be found, and then the program will undoubtedly run away.
But the case of b main mentioned above is a little special. Jump instructions such as b and bl are not absolute jump instructions, but relative jump instructions. What does it mean? That is, the main label finally gets not the absolute address of main after being arranged by the linker, but the value obtained by subtracting the absolute address of the current instruction from the absolute address of main. In other words, b and bl access a relative address, not an absolute address. Therefore, the code segment including this statement and main can run normally regardless of whether it is placed in its execution domain. This is the so-called position-independent code.
From the above discussion, we can know that if your code needs to be position-independent, then you cannot use absolute addressing instructions, otherwise it will be position-dependent.
Previous article:ARM position-independent code design for uboot
Next article:The driver module in arm is loaded and called by the application
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- Analysis of the application of several common contact parts in high-voltage connectors of new energy vehicles
- Wiring harness durability test and contact voltage drop test method
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- Sn-doped CuO nanostructure-based ethanol gas sensor for real-time drunk driving detection in vehicles
- Design considerations for automotive battery wiring harness
- Do you know all the various motors commonly used in automotive electronics?
- What are the functions of the Internet of Vehicles? What are the uses and benefits of the Internet of Vehicles?
- Power Inverter - A critical safety system for electric vehicles
- Analysis of the information security mechanism of AUTOSAR, the automotive embedded software framework
- BMS solutions for electric bicycles and electric motorcycles under the new national standard for electric vehicles
- Bluetooth spoofing vulnerability affects billions of IoT devices
- About Sensorless Brushless DC Motor (BLDCM) High Torque/Heavy Load Starting
- Electromagnetic compatibility of independent power systems and their power electronic devices
- Conversion between CC2640R2F projects
- Bluetooth RF Conformance Test
- Next-Generation C2000 Microcontrollers and CapTIvate Technology Live Broadcast Registration Open!
- Regarding impedance matching, is the characteristic impedance setting of the board trace the same as the series resistor impedance matching?
- EEWORLD University Hall----Live Replay: TI chip technology helps motor development
- ADC Test Voltage vs. Temperature