STM32F103VB与Keil uVision4环境下反汇编窗口{pc}+2含义咨询
Hey there! Let's unpack this confusion step by step—this is a super common gotcha with ARM/Cortex-M assembly and how debuggers like Keil display pseudo-instructions like ADR.
First, let's clarify two key PC behaviors on Cortex-M3 (STM32F103):
- Execution-time PC: When the CPU runs Thumb instructions (the default for STM32), the PC value used in calculations points to two instructions ahead of the current one. For 16-bit Thumb instructions, this means the execution-time PC equals
current_instruction_address + 4. - Assembler calculation PC: When the assembler processes pseudo-instructions like
ADR, it uses an adjusted PC value as the baseline for calculating offsets. For 16-bit Thumb instructions, this baseline iscurrent_instruction_address + 2(the address of the very next instruction).
What does {pc}+2 mean in Keil's disassembly?
The curly braces {} here are Keil's way of explicitly showing you the assembler's adjusted PC baseline that was used to compute the target address for the ADR instruction.
Let's tie this directly to your example:
- You’re seeing
ADRload the address0x08000338. - The disassembly shows
{pc}+2as the source of this address.
Here’s why a raw [pc, #2] calculation doesn’t match:
- Suppose your
ADRinstruction lives at0x08000334(a 16-bit Thumb instruction, taking up 2 bytes). - The assembler uses
0x08000334 + 2 = 0x08000336as its PC baseline. - Adding
#2to this baseline gives exactly your target address:0x08000336 + 2 = 0x08000338. - If you tried using the CPU’s real execution-time PC (
0x08000334 + 4 = 0x08000338), adding#2would give0x0800033A—which isn’t your target. That’s why the raw[pc, #2]doesn’t line up.
In short: The curly braces highlight that this isn’t the CPU’s real-time PC value—it’s the adjusted baseline the assembler used to turn the ADR pseudo-instruction into actual machine code (usually an ADD or SUB instruction under the hood).
Quick recap:
{pc}= The assembler's adjusted PC baseline (current instruction address + 2 for 16-bit Thumb instructions)+2= The offset added to this baseline to reach your target address0x08000338- Keil uses this notation to make the pseudo-instruction’s logic transparent in disassembly.
内容的提问来源于stack exchange,提问作者HyeonGeun Park

