Thumb-2 have 32 and 16 bits instruction sizes that are aligned to 2 bytes. Moreover when an instruction is executed the PC register has the value of the two instructions ahead of it. That is when you type :
0x1 - MOV R1, [PC #xx]
The PC value is not 0x1, but 0x1 + the size of the two instructions ahead, so in the case of :
- Two 16 bits instructions :
PC = 0x1 + 4 - One 16 bits and one 32 bits instruction :
PC = 0x1 + 6 - Two 32 bits instruction :
PC = 0x1 + 8
That was the theory (correct me if I'm wrong). But in my assembly code, I've got weird things : Here when 0x1AE is executed PC is equal to 0x1EC - 60, that is 0x1B0, so the PC has just been incremented by 2.
0x1AE 490F LDR r1,[pc,#60] ; @0x1EC
0x1B0 6008 STR r0,[r1,#0x00]
0x1B2 F7FFFFE9 BL.W dly (0x08000188)
And here with a similar scenario when 0x1D4 is executed PC is equal to 0x1F0 - 24, that is 0x1D8, so the PC has been incremented by 4.
0x1D4 4906 LDR r1,[pc,#24] ; @0x1F0
0x1D6 6008 STR r0,[r1,#0x00]
0x1D8 F7FFFFD6 BL.W dly (0x08000188)
I'm confused with this PC behaviour, this Thumb-2 assembly code seems illogical to me. Could you explain me why this happen and what I don't understand with the Thumb-2 PC register behaviou. It should have a logic because compiler know at compile time the PC value.