As far as I understand it, ARM Cortex-M CPUs are always in Thumb state, which means:
Thumb state indicated by program counter being odd (LSB = 1). Branching to an even address will cause an exception, since switching back to ARM state is not allowed.
However, while I am using CortexM0 and M4 CPU, the PC is always even. Each time I branch, the LR records PC+1 and each time I return, the PC gives LR-1.
For example, if lr = 0x0000_01D5,
Execute
BX lr
Then PC should be 0x0000_01D5, whereas it gives 0x0000_01D4.
Isn't this impossible?
Any comment will be appreciated.
As you'd expect, the chip draws much less power when the ARM Cortex-M0 core is running and the ARM Cortex-M4 core is sleeping than vice versa. The ARM Cortex-M4 with its SIMD and floating-point capabilities ran the tests 12 to 174 times faster than the ARM Cortex-M0 core and consumed 2x to 9x more power.
3.1. R14 is the link register (LR). Inside an assembly program, you can write it as either R14 or LR. LR is used to store the return program counter (PC) when a subroutine or function is called—for example, when you're using the branch and link (BL) instruction: main ; Main program.
R15: PC (Program Counter). The Program Counter is automatically incremented by the size of the instruction executed. This size is always 4 bytes in ARM state and 2 bytes in THUMB mode.
From Cortex-M4 Technical Reference Manual:
2.3.1 Program counter
Register R15 is the Program Counter (PC).
Bit [0] is always 0, so instructions are always aligned to word or halfword boundaries.
Reading from PC
shouldn't return an odd address. However when you write to PC
, LSB of value is loaded into the EPSR T-bit. From Cortex-M3 Devices Generic User Guide - 2.1.3. Core registers
Thumb state
The Cortex-M3 processor only supports execution of instructions in Thumb state. The following can clear the T bit to 0:
instructions BLX, BX and POP{PC} restoration from the stacked xPSR value on an exception return bit[0] of the vector value on an exception entry or reset.
Attempting to execute instructions when the T bit is 0 results in a fault or lockup. See Lockup for more information.
In other words, you can read even values from PC
but can't write such values under normal circumstances.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With