Search code examples
assemblyarmcortex-m

"Change instruction set" in ARM assembly - what exactly does this mean?


BX changes the instruction set says the manual we have over here, as far as I could find out by searching far and near, this means that while the CPU runs 16bit Thumb instruction set, it accepts a 32bit address just this time (I have found no indication that anything changes for following commands) so that you can branch to a point much further, do I understand it right? if yes, is that all?
We are said to be using the Atmel AT91, presumably Cortex M3 type, but anything I could get my hands on concerning Cortex M3 seemed notably different than what we do, while I cannot find the AT91 in Keil uVision, they also way we use a platform developed by one of the professors so I suspect it's not exactly the real thing we are doing, but still I'd like to know what is this thing as I am thinking of looking into assembly in general...


Solution

  • The processor your mentioned (the Cortex M3) doesn't support ARM instructions, so BX is unavailable to you. You can only use the base Thumb instructions.

    That being said, it's worth giving you some background:

    The BX instruction performs a branch (i.e. a jump) and switches the processor into ARM or Thumb mode based upon the 0th bit of the branch address. The purpose of this is not to allow you to jump further, but simply to switch between modes. Since all processors that support this instruction start in ARM mode, switching over to Thumb mode doesn't increase your jump distance.

    The details around Thumb vs. ARM mode are subtle and too many to list here, but a good resource can be found here. Since links alone might go dead, here's a summary:

    • In Thumb mode, "program-relative branches, particularly conditional branches, are more limited in range than in ARM code, and branches to subroutines can only be unconditional".
    • ARM mode has access to more general purpose registers, and Thumb mode has only limited access to r8-r15.