ARMv7中如何写入R14(LR链接寄存器)?中断加载0xFFFFFFF9遇阻求助
Got it, let's break this down. On ARM architectures (especially older ARMv7-A/R cores), the value 0xFFFFFFF9 is the exception return address used to exit interrupts and return to Handler mode (with interrupts enabled). The problem with MOV here is that ARM's MOV instruction can't directly load 32-bit immediate values that don't fit its restricted format—only 8-bit values rotated by even positions are allowed. 0xFFFFFFF9 doesn't meet this criteria, hence the failure.
Here are three reliable workarounds, tailored to different scenarios:
Use the LDR Pseudo-Instruction (Simplest Approach)
This is the most straightforward method, as the assembler handles the heavy lifting for you. It stores the target value in a nearby "literal pool" and generates a PC-relative load instruction:LDR LR, =0xFFFFFFF9 ; Assembler translates this to a PC-relative LDR BX LR ; Trigger the exception returnThe pseudo-instruction
LDR Rd, =immautomatically places0xFFFFFFF9in a readable memory location near your code, then loads it into LR without immediate value restrictions.Build the Value with MOV + MVN
Since0xFFFFFFF9is the bitwise NOT of0x6, you can use theMVN(Move Not) instruction to construct it:MOV R0, #0x6 ; Load the 8-bit immediate that's the inverse of our target MVN LR, R0 ; LR = ~R0, which equals 0xFFFFFFF9 BX LRThis avoids accessing memory entirely, making it a good choice if you want a pure register-based solution.
Thumb Mode: Use MOVW + MOVT (ARMv6T2+)
If your interrupt handler runs in Thumb mode, you can split the 32-bit value into two 16-bit halves and load them withMOVW(Move Wide) andMOVT(Move Top):MOVW LR, #0xFFF9 ; Load the lower 16 bits of 0xFFFFFFF9 MOVT LR, #0xFFFF ; Load the upper 16 bits BX LRThis is clean for Thumb-2 environments and works without relying on a literal pool.
Just a quick reminder: Always double-check your core's exception return rules—0xFFFFFFF9 corresponds to returning to Handler mode with interrupts enabled (depending on your ARM version), so make sure this aligns with your system's requirements.
内容的提问来源于stack exchange,提问作者Jyothi Bhat

