ARM Assembler Question

Discussion of development of software for any "obsolete" computer or video game system. See the WSdev wiki and ObscureDev wiki for more information on certain platforms.
tepples
Posts: 22993
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)

Re: ARM Assembler Question

Post by tepples »

"Store multiple to full-descending stack" means "push", and "load multiple from full-descending stack" means "pull". It's the RISC principle: if they already have "load multiple" and "store multiple", why create new instructions just for the stack?
AWJ
Posts: 433
Joined: Mon Nov 10, 2008 3:09 pm

Re: ARM Assembler Question

Post by AWJ »

nicklausw wrote:
nicklausw wrote:Um...does anyone have any idea why lr might magically turn into pc in a subroutine? Because I have a problem where my subroutines will randomly turn into a bx lr loop sometimes, and I can't figure things out at all. Not sure what other information to provide.
Update, I figured this one out on my own.

Putting:

Code: Select all

stmfd  sp!, {lr}
at the beginning of subroutines, and:

Code: Select all

ldmfd  sp!, {pc}
at the end prevents recursive lr's. Now to figure out what the crap "stmfd" and "ldmfd" mean.
RISC architectures don't push the return address onto a RAM stack when a subroutine call occurs. They store it in a register instead (the "link register"). If a subroutine is a leaf subroutine it can just leave the return address there, but if it calls other subroutines then it needs to explicitly push the link register onto the stack.
psycopathicteen
Posts: 3198
Joined: Wed May 19, 2010 6:12 pm

Re: ARM Assembler Question

Post by psycopathicteen »

Jarhmander wrote:
Bregalad wrote:In this case

Code: Select all

lda r0, =something
is probably equivalent to something like

Code: Select all

here:
    lda r0, [r15], #something-here-8
The PC is always 2 words (8 bytes) ahead because of the pipeline.
Hell no, not only you fetch the wrong word, you'll corrupt the PC, or it will fault. This is post-indexed addressing, instead of regular offset addressing, which is the only form accepted for base addresses based on PC.
So it's more like:

Code: Select all

    ldr r0, [pc, #off-8]
The -8 thing is true, PC is "ahead" because of pipeline. This is important to consider upon receiving imprecise faults (if I remember correctly!), the old PC points after the faulty instruction.
How do you know the offset anyway?
tepples
Posts: 22993
Joined: Sun Sep 19, 2004 11:12 pm
Location: NE Indiana, USA (NTSC)

Re: ARM Assembler Question

Post by tepples »

Ideally, the assembler computes the offset for you.
User avatar
Jarhmander
Formerly ~J-@D!~
Posts: 570
Joined: Sun Mar 12, 2006 12:36 am
Location: Rive nord de Montréal

Re: ARM Assembler Question

Post by Jarhmander »

psycopathicteen wrote: How do you know the offset anyway?
tepples wrote:Ideally, the assembler computes the offset for you.
When using the right instructions, you don't have to compute any offsets, the assembler does that job for you. For example, ldr r0, =const is transformed by the assembler for you to ldr r0, [pc, #magicoffset], like Bregalad said, where the magic offset is computed by the assembler so it loads a word after the subroutine from the so-called literal pool. When using labels, like any other assemblers, it does put the right offset in the instruction, just like in any 6502 assembler when you do things like ex: beq Label.
((λ (x) (x x)) (λ (x) (x x)))