LDR pseudocommands and LDR loading commands in arm

Source: Internet
Author: User

In the arm instruction set, LDR is usually used as the loading command, but it can also be used as a pseudo command.

The form of the LDR pseudo command is "ldr rn, = expr ". The following is an example to describe its usage.

Count equ 0x40003100

......

LDR R1, = count

MoV r0, #0

STR r0, [R1]

Count is a defined variable with the address 0x40003100. This definition method is very common in assembly languages. If you have used a single-chip microcomputer, you should be familiar with this usage.

LDR R1, = count is to put the address of the variable count, that is, 0x40003100 into R1.

MoV r0, #0 is to put the immediate number 0 into R0. Last Str
R0, [R1] is a typical storage command that places values in R0 to the storage unit with the value in R1 as the address. Actually, 0 is put in the storage unit with the address 0x40003100. Yes
See the three commands to assign values to the variable count. It seems uncomfortable to assign values to a variable using three commands. This may be related to the arm's use of RISC.

The following is an example.

; Assign the Count value to R0

LDR R1, = count

LDR r0, [R1]

LDR R1, = count: how to assign the Count address to R1? If you are interested, see the compiled result. This command is actually compiled into a LDR command and a DCD pseudocommand.

Ldr pc, = myhandleirq indicates to put the myhandleirq symbol into the PC register 2) ldr pc, myhandleirq indicates to read the value in the address indicated by the myhandleirq symbol in the memory, and the memory needs to be read once more. In the Code: start:
Ldr pc, = myhandlereset @ jump to handlereset
Ldr pc, = myhandleundef @ jump to handleundef
Ldr pc, = myhandleswi @ jump to handleswi
Ldr pc, = myhandleiabort @ jump to handleiabort
Ldr pc, = myhandledabort @ jump to handledabort
NOP
Ldr pc, = myhandleirq @ jump to handleirq <= previous error line
Ldr pc, = myhandlefiq @ jump to handlefiq @ myhandleirq:. Word OS _cpu_irq_isr
Myhandleirq:
Sub LR, LR, #4 @ to calculate the return address
Analytic dB SP !, {R0-r12, LR}
Ldr lr, = int_return @ restore the return address
Ldr pc, = int_handle @ call for the interrupt handler. If it is changed to "ldr pc, myhandleirq" in the "previous error line", it cannot be interrupted. The other case is correct. Note the following: start:
Ldr pc, = myhandlereset @ jump to handlereset
Ldr pc, = myhandleundef @ jump to handleundef
Ldr pc, = myhandleswi @ jump to handleswi
Ldr pc, = myhandleiabort @ jump to handleiabort
Ldr pc, = myhandledabort @ jump to handledabort
NOP
Ldr pc, myhandleirq @ jump to handleirq <= previous error line
Ldr pc, = myhandlefiq @ jump to handlefiq myhandleirq:. Word OS _cpu_irq_isr
@ Myhandleirq:
@ Sub LR, LR, #4 @ to calculate the return address
@ Stmdb SP !, {R0-r12, LR}
@ Ldr lr, = int_return @ restore the return address
@ Ldr pc, = int_handle @ call for the interrupt handler. When the handler is interrupted, you also need to retrieve OS _cpu_irq_isr from myhandleirq, that is, one more storage. This article describes in detail the usage 1 of the LDR pseudo commands compiled by arm.


Http://blog.csdn.net/axx1611/archive/2008/04/27/2335410.aspx

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.