A couple of questions about ASM.
How does divmod2 work? I know that it'll divide using r0 as the numerator and r1 as the denominator, but where does the remainder go?
What does the 'and' and 'or' commands do? I can't find a comprehensive guide to those two commands, so when I see them in a disassembly I get lost.
Does the stack pointer store words for each register pushed? For example, if I wrote push {r0, lr}, there'd be 8 bytes (a word for each) stored wherever the stack pointer is, correct?
I'm guessing you understand and miswrote it, but just the be clear. The stack pointer does not store any words that were in the pushed registers. The
stack contains the contents of those registers. The stack pointer contains a
pointer to the most recent word pushed. A lot of people describe the stack as a literal stack. It's a fine explanation, but I have an easier time thinking about it as a plain old hex file that I'm editing, one word at a time. Don't think of the stack as anything magical. (I) think of it as a chunk of RAM that is constantly being edited.
Let's say the stack pointer begins at 0x038000000. I do a bl to a subroutine.
The subroutine begins push {r4-r7, lr}.
When you push/pop multiple registers, it is assumed that the highest register is pushed to or popped from the highest address in the stack.
So if we began
r4=abra
r5=bulbasaur
r5=caterpie
r6=dragonite
r7=electabuzz
lr=flareon
After push {r4-r7, lr} we have
0x037FFFFC: flareon
0x037FFFF8: electabuzz
0x037FFFF4: dragonite
0x037FFFF0: caterpie
0x037FFFEC: bulbasaur
0x037FFFE8: abra
And as a result of the push, the stack pointer is updated to 0x037FFFE8.
Then, the routine typically ends
{pop r4-r7}
{pop r0} or {pop r1} depending on whether a return exists
bx r0/r1
So after pop {r4-r7}, the contents of r4-r7 are again restored
r4=abra
r5=bulbasaur
r5=caterpie
r6=dragonite
r7=electabuzz
& the stack pointer contains the address 0x037FFFFC.
Then, pop {r0/r1} to get the value that was initially stored in the link register (for a return address}
& the stack pointer once again contains the address 0x038000000.
I don't know if any of that helped.
Edit: ninjad :(