Position-dependency and position-independence are mainly reflected in whether the address of the program when it is running is the same as the address of the code segment specified during compilation.
Compilation environment: ADS1.2
Development board: GEC210 (s5pv210soc)
Program running method: Use uboot's tftp to download the bin file to memory (0x30008000), and then run
The assembly code is as follows:
ldr r3,=delay 1
ldr r3,delay 2
adr r3,delay 3
. . . . .
delay
mov r2,#0xff00000
.......
end
Set the entry address in ADS to 0x30008000 (RO base in ARM linker options)
The disassembled code is as follows in AXD
30008000 [0xe59f3040] ldr r3,0x30008048 ; = #0x30008038
30008004 [0xe59f302c] ldr r3,delay ; = #delay
30008008 [0xe28f3028] add r3,pc,#0x28 ; #0x30008038
. . . .
30008048 [0x30008038] dcd 0x30008038 8..0
. . . .
The first column 30008000 is the address, the numbers in the brackets in the second column represent the corresponding machine code, and the following are the corresponding arm instructions.
We see the first instruction, the original instruction is written as ldr r3,=delay
The disassembled instruction becomes ldr r3,0x30008048
The corresponding machine code is 0xe59f3040
We look at the lower 12 bits of the machine code, whose value is 0x040.
Calculate pc+0x40 = 0x30008000 + 8 + 0x40 = 0x30008048
Get the new address 0x30008048, look at the content of address 0x30008048 0x30008038
0x30008038 is the address of the delay label, and the value is read from the memory unit
So we can see that ldr r3,=delay is a position-dependent instruction (if you don't understand, read on)
Look at the other two instructions
Original instruction ldr r3,delay
Disassemble the instruction ldr r3,delay
Machine instruction 0xe59f302c
The lowest 12 bits of the machine instruction are reserved as 0x02c
Calculate PC+0x02c = 0x30008004+8+0x02c = 0x30008038
0x30008038 is the address of the delay label, which is calculated by adding the value of pc.
The value of the previous instruction is stored in a certain unit and then read out using the instruction.
This value (0x30008038) is calculated and related to the PC. It is calculated based on the value of the PC, while the address of the first instruction is read and is a fixed value, which has nothing to do with the PC.
The third instruction adr r3,delay
Disassembly add r3,pc,#0x28
It can be directly seen that the value of r3 is obtained by adding a certain number to pc.
From the above instructions, we can see that the value related to PC is the position-independent instruction, and the code independent of PC is the position-dependent instruction.
Not finished yet, continue
Two situations
1. I downloaded the compiled bin file to the location 0x30008000, and all three instructions can correctly obtain data
2. I downloaded the bin file to 0x30001000 (or other available memory address), then the first instruction cannot obtain the correct data, but the 2nd and 3rd instructions can obtain the correct data.
At this time, the value of pc should be 0x30001000+8 = 0x30001008;
The address calculated by the first instruction is 0x30001048. This address has a data 0x30008038. When the instruction tries to access 0x30008038 to read a value, it will obviously go wrong. In fact, it is not the address corresponding to the delay label. The address of delay should be 0x30001038.
The next two instructions can both calculate the value 0x30001038, which is the actual address of delay.
The above is a brief explanation of position-dependent and position-independent. If you still don't understand, you can try using debugging tools such as ads or keil.
Simply put, position independence means that no matter where the starting address of the code segment is specified when you compile, and I download it to any memory space, the program can run normally.
The location-related code is the code that specifies the location of the code segment when the program is compiled. The program must be downloaded to the specified location in order to run normally.
Note: The value of pc is equal to the address of the currently executing instruction + 8
Previous article:gec210 led bare metal development assembly instructions
Next article:GEC210 System Update Instructions
- 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
- CGD and Qorvo to jointly revolutionize motor control solutions
- CGD and Qorvo to jointly revolutionize motor control solutions
- Keysight Technologies FieldFox handheld analyzer with VDI spread spectrum module to achieve millimeter wave analysis function
- Infineon's PASCO2V15 XENSIV PAS CO2 5V Sensor Now Available at Mouser for Accurate CO2 Level Measurement
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- A new chapter in Great Wall Motors R&D: solid-state battery technology leads the future
- Naxin Micro provides full-scenario GaN driver IC solutions
- Interpreting Huawei’s new solid-state battery patent, will it challenge CATL in 2030?
- Are pure electric/plug-in hybrid vehicles going crazy? A Chinese company has launched the world's first -40℃ dischargeable hybrid battery that is not afraid of cold
- Solutions to counteract noise issues in Wi-Fi-equipped devices
- Pengfeng Technology RVBoards-Nezha (RISC-V SBC): Development Tool Introduction 1
- Espressif ESP8685 Technical Specification
- How to migrate FreeRTOS applications to secure SAFERTOS
- LED Timer Keychain
- RF2051 chip
- MSP430G2 LaunchPad, how to play music with buzzer
- Disassemble a WSN node device and see how to select materials?
- Allwinner V853 heterogeneous multi-core AI intelligent vision development board review - V853 YOLO V3 test
- Development board CC3200-LAUNCHXL,