This follows on from the issue I raised on Github.
https://github.com/micropython/micropython/issues/1111
It seems that registers above r7 aren't safe to use so the question is how to proceed when you run out of registers. One solution is to push registers onto the stack; alas the STFMFD and LDFMFD instructions aren't implemented. One suggestion is that you can implement arbitrary instructions using the data command thus data(bytesize, data, ...); e.g.
While this is very useful to know, it isn't the most readable solution. Is there any reason not to use the stack as follows? r13 is the stack pointer, it grows downwards and you pre-decrement it for a push and post increment for a pop (at least from my reading of the well written tutorial on
http://www.davespace.co.uk/arm/introduc ... stack.html) and assuming MicroPython uses the Full Descending stack - the tutorial suggests anything else is "rare". Thus
Code: Select all
sub(r13, 4)
str(r0, [r13, 0])
...
ldr(r0, [r13, 0])
add(r13, 4)
As far as I can see this should be safe even if the code is interrupted, but I'm a total noob regarding low level ARM stuff so any comments would be appreciated.