Relationship between LDR and ltorg in arm assembly

Source: Internet
Author: User

I have read the arm assembly language syntax for more than a month. Now we are getting started. Of course there are still many things worth further efforts.

 

Recently, I have some new ideas about LDR and ltorg.

 

LDR is a replication command. The function is to read a single data instruction from memory to register. It has 19 command formats.

The two formats are macro commands (macro). The format is as follows:

1. LDR <cond> <type> Rd, <label>

2, LDR <cond> Rd, = <32-bit-value>

 

The second macro command is analyzed here. It will be compiled into an instruction by the compiler, saving the given 32-bit value to the Register Rd. generally, this drop command is LDR <cond> Rd, [PC, # <OFFSET>], the 32-digit data is stored in a literal pool starting with the address (PC + <OFFSET>.

 

For instructions about LDR <cond> Rd, [PC, # <OFFSET>], you should review the "single register load-store instruction addressing method" compiled by arm. The forward address addressing method is used here. The PC value remains unchanged. The memory value is mem [PC + offset].

 

Ltorg is used to declare the beginning of a Data Buffer Pool (also called a text pool. When using the pseudo-command LDR, you often need to add the ltorg declaration data buffer pool where appropriate. The data loaded by LDR is temporarily stored in the data buffer pool by the compiler.

Instructions for use:

When LDR and other commands are used in the program, the usage of the data buffer pool may be out of bounds. To prevent out-of-bounds operations, you can use the ltong pseudo operation to define the data buffer pool. Generally, large code segments can use multiple data buffer pools. The arm assembly compiler generally puts the data buffer pool at the end of the code segment, that is, before the next code segment starts or before the end pseudo operation. The ltorg pseudo operation is usually placed after the unconditional jump command, or after the subroutine returns the command, so that the processor will not mistakenly execute the data in the data buffer pool as a command.

 

Sample Code:

Area example, code, readonly; // declare a code segment named example and the attribute is read-only.

Start BL funcl

; Code

Funcl // subroutine

; Code

LDR R1, = 0x800 // load 0x800 to r1

MoV PC, LR // subprogram ends

Ltorg // define the data buffer pool

Data Space 4200 // allocate 40 bytes of memory units from the current START and initialize to 0

End // end of the program

 

The 0x800 value is temporarily placed in the data [0-3] field by the compiler.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.