Oh and as prplz mentioned, any self-respecting compiler nowadays will use only registers any way you decide to implement this little stub of a function. Yes yes, the question is very contrived too, but hey.
I went to bed, and realized that my answer is wrong. Exchanging the values in register is completely invisible to the function caller. Here's the correct answer.
Very contrived, only works on ARM, not even acceptable by all C compilers, but you never constrained the problem that way!
Oh and as prplz mentioned, any self-respecting compiler nowadays will use only registers any way you decide to implement this little stub of a function. Yes yes, the question is very contrived too, but hey.
Aren't you using a third register though?
Are you're thinking that you can do that because it's not in RAM?
The way the question is formulated, you're limited by having a certain amount of memory. Any register use doesn't count against that at all.
I went to bed, and realized that my answer is wrong. Exchanging the values in register is completely invisible to the function caller. Here's the correct answer.
Further, as
R0-R3
are all caller-save registers in the ARM ABI, the function body, excluding the function entry stack shenanigans, uses zero memory.