Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.arch.embedded > #21708

Re: Question about ARM instruction: STMIA / STMEA

From Nobody <nobody@nowhere.invalid>
Newsgroups comp.arch.embedded
Subject Re: Question about ARM instruction: STMIA / STMEA
Date 2015-08-08 02:46 +0100
Organization A noiseless patient Spider
Message-ID <pan.2015.08.08.01.46.20.823000@nowhere.invalid> (permalink)
References <5f1e3e48-3b23-4d32-a5f9-a38731a91c9b@googlegroups.com>

Show all headers | View raw


On Thu, 06 Aug 2015 15:42:07 -0700, Robert Willy wrote:

> When I read ARM Thumb2 instruction manual, I find a problem on 
> STMIA / STMEA.
> 
> It said: "Store Multiple Increment After (Store Multiple Empty Ascending)
>  stores multiple registers to consecutive memory locations using an address
>  from a base register."
> 
> Does that mean STMIA is equivalent to STMEA?

Yes.

> Then, when I try to find the answer online, I have more questions on this
> topic. Below the dot line is from Keil website. Although it gives more
> explanation, I don't understand it, especially Table 4.5 and 4.6.
> 
> For example, on Table 4.5, there is one row has content:
> 
> FD (Full Descending stack)	DB (Decrement Before)	IA (Increment After)
> 
> I don't see the relationship between 'DB' and 'IA'. Could you explain it
> to me a little more?

"EA" means that the stack is

a) "empty", meaning that the stack pointer points to the first
word beyond the end of the stack (i.e. where the next "pushed" word will
be stored), and
b) "ascending", meaning that the stack grows upward in memory, i.e.
pushing increases the stack pointer while popping decreases it.

So to push a word onto an empty+ascending stack, you store the word at the
current stack pointer then increment the stack pointer (increment after =
IA).

To pop a word from an empty+ascending stack you first decrement the stack
pointer (so that it points to the last word on the stack rather than the
space after it) then read the word it now points to (decrement before = DB).

To summarise: STMEA = STMIA, LDMEA = LDMDB.

The Increment/Decrement Before/After syntax describes the operation in
terms of what happens to the register and when (this is the conventional
pre/post-increment/decrement terminology). It's more appropriate if you
aren't manipulating a stack.

The Empty/Full Ascending/Descending syntax describes the nature of the
stack (on the assumption that you are actually dealing with a stack).

With the former, load and store operations are asymmetric (or more
accurately, anti-symmetric). Whichever suffixes are used for the store,
the opposite suffixes must be used for the load, e.g. STMIA<=>LDMDB.

With the latter, load and store always use the same suffix, e.g.
STMEA<=>LDMEA.

This is all syntactic sugar. The LDM/STM opcode format has a flag for
Increment (set) or Decrement (clear) and another for Before (set) or
After (clear). The assembler takes care of converting either syntax to the
appropriate flags.

Load	Incr	Before	Opcode 1	Opcode 2
0	0	0	STMDA		STMED
0	0	1	STMDB		STMFD
0	1	0	STMIA		STMEA
0	1	1	STMIB		STMFA
1	0	0	LDMDA		LDMFA
1	0	1	LDMDB		LDMEA
1	1	0	LDMIA		LDMFD
1	1	1	LDMIB		LDMED

Back to comp.arch.embedded | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Question about ARM instruction: STMIA / STMEA Robert Willy <rxjwg98@gmail.com> - 2015-08-06 15:42 -0700
  Re: Question about ARM instruction: STMIA / STMEA Simon Clubley <clubley@remove_me.eisner.decus.org-Earth.UFP> - 2015-08-07 11:52 +0000
    Re: Question about ARM instruction: STMIA / STMEA Theo Markettos <theom+news@chiark.greenend.org.uk> - 2015-08-07 19:12 +0100
  Re: Question about ARM instruction: STMIA / STMEA Nobody <nobody@nowhere.invalid> - 2015-08-08 02:46 +0100
  Re: Question about ARM instruction: STMIA / STMEA Robert Willy <rxjwg98@gmail.com> - 2015-08-08 15:39 -0700
    Re: Question about ARM instruction: STMIA / STMEA Richard Damon <Richard@Damon-Family.org> - 2015-08-08 19:56 -0400

csiph-web