You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

STM32F103VB与Keil uVision4环境下反汇编窗口{pc}+2含义咨询

Understanding {pc}+2 in Keil's Disassembly for STM32F103

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 is current_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 ADR load the address 0x08000338.
  • The disassembly shows {pc}+2 as the source of this address.

Here’s why a raw [pc, #2] calculation doesn’t match:

  1. Suppose your ADR instruction lives at 0x08000334 (a 16-bit Thumb instruction, taking up 2 bytes).
  2. The assembler uses 0x08000334 + 2 = 0x08000336 as its PC baseline.
  3. Adding #2 to this baseline gives exactly your target address: 0x08000336 + 2 = 0x08000338.
  4. If you tried using the CPU’s real execution-time PC (0x08000334 + 4 = 0x08000338), adding #2 would give 0x0800033A—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 address 0x08000338
  • Keil uses this notation to make the pseudo-instruction’s logic transparent in disassembly.

内容的提问来源于stack exchange,提问作者HyeonGeun Park

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.21 08:08:39