arm assembly pseudo-instructions and position-dependent codes

Publisher:雅致小筑Latest update time:2022-07-29 Source: csdnKeywords:arm Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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


Keywords:arm Reference address:arm assembly pseudo-instructions and position-dependent codes

Previous article:gec210 led bare metal development assembly instructions
Next article:GEC210 System Update Instructions

Latest Microcontroller Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号