ARM Assembler Question
-
tepples
- Posts: 22993
- Joined: Sun Sep 19, 2004 11:12 pm
- Location: NE Indiana, USA (NTSC)
Re: ARM Assembler Question
"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
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.nicklausw wrote:Update, I figured this one out on my own.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.
Putting:at the beginning of subroutines, and:Code: Select all
stmfd sp!, {lr}at the end prevents recursive lr's. Now to figure out what the crap "stmfd" and "ldmfd" mean.Code: Select all
ldmfd sp!, {pc}
-
psycopathicteen
- Posts: 3198
- Joined: Wed May 19, 2010 6:12 pm
Re: ARM Assembler Question
How do you know the offset anyway?Jarhmander wrote: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.Bregalad wrote:In this caseis probably equivalent to something likeCode: Select all
lda r0, =somethingThe PC is always 2 words (8 bytes) ahead because of the pipeline.Code: Select all
here: lda r0, [r15], #something-here-8
So it's more like: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.Code: Select all
ldr r0, [pc, #off-8]
-
Jarhmander
- Formerly ~J-@D!~
- Posts: 570
- Joined: Sun Mar 12, 2006 12:36 am
- Location: Rive nord de Montréal
Re: ARM Assembler Question
psycopathicteen wrote: How do you know the offset anyway?
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.tepples wrote:Ideally, the assembler computes the offset for you.
((λ (x) (x x)) (λ (x) (x x)))