views:

104

answers:

3

I have two questions about DA addressing mode. For example:

STMDA R0!, {R1-R7}

The start address will be R0 - (7 * 4) + 4, that is, R0-24, according to the ARM Architecture reference manual and end_address will be R0.

So:

  1. Will the value of R1 will be stored to R0-24 or R0?
  2. If R1 is stored to R0-24, then subsequent stores will grow towards the top of memory (from R0-24 to R0)?
+4  A: 

When using ARM multiple stores and loads, register values are always loaded/stored in ascending order in memory. So, when using a descending multiple store, the registers are written into memory backwards. Your STMDA instruction effectively breaks down into the following steps:

  • store R7 at R0
  • store R6 at R0 - 4
  • store R5 at R0 - 8
  • store R4 at R0 - 12
  • store R3 at R0 - 16
  • store R2 at R0 - 20
  • store R1 at R0 - 24
  • subtract 28 from R0 (because of writeback - the !).

So, to answer your questions:

  1. The value of R1 will be stored at R0 - 24. (Here, I mean the value of R0 before executing the instruction, not afterwards. You're using writeback - the ! - so after the instruction, R0 will have had 28 subtracted from it.)

  2. R1 is stored at R0 - 24, but as explained above, R1 is the last register to have its value stored in memory. R7 is stored first, and subsequent stores from there grow downwards in memory.

I have to admit I don't know of any documentation that supports this answer. Also, it's been a while since I last did any ARM coding. However, I definitely remember wondering how the ARM stores registers in a descending multiple store. I figured this out by writing a short program to find out.

Pourquoi Litytestdata
+1 absolutely correct. This behavior is documented in the ARM architecture reference manuals.
Stephen Canon
thanks, well, i think the manual defines R0-24 as the start_address is somewhat ambiguous,this start_address is just the minimum address of the memory instead of the first address that is stored.
wenlujon
The pseudocode that describes the instruction operation is quite clear, and matches Pourquoi's description.
Stephen Canon
A: 

Search for arm arm The ARM Architectural reference manual...

The first address formed is the , and is the value of the base register minus four times the number of registers specified in , plus 4. Subsequent addresses are formed by incrementing the previous address by four. One address is produced for each register that is specified in .

dwelch
A: 

part of the pseudocode is shown below:

address = start_address for i = 0 to 15 if register_list[i] == 1 then Memory[address,4] = Ri address = address + 4

it seems that the growth method of STM has nothing to do with addressing mode when storing data? it always stores data from lower address to higher,the addressing mode only decides the start address based on R0?

wenlujon