Ldmia, Ldmib, Ldmdb, Ldmda, Stmia, LDMFD, LDMFA, ldmed, Ldmea and other instructions

Source: Internet
Author: User

About multi-register load storage directives

1.LDMIA instruction, Ldmib instruction, ldmdb instruction, LDMDA directive

(1) Ldmia instruction, IA means address plus 4 after each transfer

(2) Ldmib instruction, address plus four before each transfer

(3) Ldmdb instruction, the address before each transmission minus 4, here also pay attention to the program first to R5, or first give R8, here is obviously first give R8

(4) Ldmda instruction, after each transmission address minus 4, here is also first give R8, not first to r5!!

2. Take a look at the stmia directive, the STMIB directive, the Stmdb directive, the STMDA command

(1) stmia instruction, Stmia R0,{R1,R2,R3,R4}; Store the R1-R4 data to the R0 point of the address, R0 value is not updated, IA after the transfer address plus 4, so here the memory address is from the beginning of the 0x8004 change

(2) Stmib instruction, Stmib R0,{R1,R2,R3,R4}; Stores the R1-R4 data to the address R0 points to, the value of R0 is not updated, IB each transfer before the address plus 4, so the value in memory is from the 0x8008 began to change

(3) Stmdb instruction, Stmdb R0,{R1,R2,R3,R4}; Stores the R1-R4 data to the address that R0 points to, the value of R0 is not updated, and the DB is reduced by 4 after each transfer, so the value in memory is decreasing from 0x8010, Notice that the R4 in the expression first gives the address 0x8010


(4) Stmda similar to the above Stmdb directive, DA is the address minus 4 after each transfer, I will not.

Here is the most TMD annoying is the stack addressing method, followed by STMFD, stmed, STMFA, Stmea

1. stm Loading Instructions

(1) Stmfd means full stack decrement instruction, the stack grows downward. If it is explained that the stack downward growth, growth downward, the stack top pointer in memory to the low address of the move, called the downward growth, here why I would like to speak STMFD instructions, how not to say ldmfd and other instructions, because here involves the stack, to memory to write the value stored in the register, more can reflect the action of the Stack, After reading the following example, you will know why the STM suffix is fd.

Key code: STMFDSP!,{R1-R3,R4}, you can see this, first put the r4,r3,r2,r1 in turn, as for why is not R1,R2,R3,R4 in order to press the stack, because the experiment is not so, so R4 ready to go into the stack, the stack pointer sp minus 4, Then first put the value of the R4 register inside the memory address for 0x803c inside, here why SP to first minus 4, because this is full stack, so we have to make the stack pointer changes in response before the storage, as to what is full stack and empty stack, I do not explain here. The effect of the program can be seen:

(2) Look at the above stmfd, now see STMFA is very simple: but here need to pay special attention , here is not the first operation of R4 Register, but the operation R1 register, as for why, I do not know, just the experiment summed up, this thing does not have any rules to say, Let's do the experiment. In the same way, the SP to make the corresponding changes, that is, the first sp+4=0x8044, and then put the value of the R1 register to the memory address of 0x8044, and then r2,r3,r4 in turn, and finally change the value of the SP, because the code more than an exclamation point STMFA sp!,{ R1-R3,R4}

(3) stmed is the empty descending stack, you can see the stack pointer at the beginning of the 0x8040, so first put the value of R4 register to the memory unit 0x8040, here is actually the first operation R4 Register, as for why, can only say and stmfd corresponding.


(4) Stmea empty increment stack, here I only stickers do not speak, haha, do not understand, go home farming to

below to see and STMFD instructions corresponding to the LDMFD and other instructions, I explained in turn ldmfd, LDMFA, ldmed, Ldmea instructions, as for why I said in this order, in order to and above the STMFD and other directives linked together.

(1) Remember what those STM commands would be first, right, the first is the STMFD instruction, which puts the in-memory data into registers in bulk. FD is full descending stack.

It is worth noting that FD is not full stack decrement, why the SP is increased after the execution of the program, in the absence of the implementation of MOVR9, SP this directive, FD does represent a diminishing meaning, here because the SP stack top pointer is actually increased, as to why not write LDMFA, Just so ldmfd can and STMFD directive correspondence, looks pleasing to the point bar, actually here I want to explain is Stmdb is not and ldmdb corresponds, but and ldmia corresponds, here notice on line, after the program is more, directly remember, but you as long as the principle understand, how to write it.

(2) That naturally follows the LDMFA directive: the same thing!!

(3) ldmed directive: According to gourd painting scoop

(4) LDMEA directive: Do not write, eat to go!!!

The last note is that the SP pointer here is a value that I assume, if you later write arm code, call C function, use the stack pointer, the system will automatically assign, there is no problem of whether the SP is illegal, what is the illegal problem? To give an example, see, here the corresponding SP is 0x8020, and is full decrement, the value of the register to write to memory, I clearly write is STMFDSP!,{R1-R3,R4}, the contents of 4 registers written into memory, but finally saved two, Because your 0x8018 address may be stored there before the contents of the code snippet, so you can not change, to get the memory you can't write this time the address is readable to the register, I have not tried, interested can try. So be aware of this when using STM instructions!!



Ldmia, Ldmib, Ldmdb, Ldmda, Stmia, LDMFD, LDMFA, ldmed, Ldmea and other instructions

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.