This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Why does this piece of assembly not work?

Hello all,

Can you tell mw why this piece of code:

LDMDB   R13, {R0 - LR}^
NOP
MOVS    PC, LR // hand over control to task

does not update registers R13 and R14 (but does update R0 - R12)? The write back operator (!) is indeed not present (i.e.

LDMDB R13!...

but this does not compile) which may explain R13, but why isn't then R14 being updated? Even if I try to separately extract R13, R14 from by buffer (pointed by R13) it does not work. Any ideas?

  • LDMDB R13, {R0 - LR}^

    The optional ^ symbol at the end of a load multiple instruction indicates the special form of this instruction which restores the CPSR from the SPSR.

    This instruction is switching mode, therefore a different R13 and R14 are visible.

    This is similar in operation to MOVS PC, LR which also restores the CPSR from the SPSR. You need one or the other, not both.

  • Patrick,
    Thanks for your reply. The assembly guide for the RealView compiler states that the ^ sign can also be used to access user mode registers. I forgot to mention that the posted code is executed inside an IRQ handler.

  • Ok, I wasn't aware that this syntax operated differently if the PC wasn't in the register list. That might come in useful someday!

    Just tried it and it works - as I now expect it to work - on ARM7TDMI silicon and also the Keil simulator. R13_usr and R14_usr get updated when this instruction is executed in irq mode.

    I can't explain your problem though.

  • Patrick,
    Funny: I have "discovered" the mode-dependent register value pane at the left hand side...my mistake - no problem after all. I am wearing the C166 helmet on my head! :-0