This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Which instruction format does Cortex-R support,encoding A1 orA2?

I see it support encoding T2 for Thumb-2 instruction set.But which instruction format does Cortex-R support for ARM instruction,encoding A1 orA2?

Parents Reply Children
  • I believe it is at the discretion of the assembler whether it will use the A2 encoding to encode a MOV instruction with a 16-bit constant (assuming that you are using an ARMv7 processor as all these support both coding).

    In general, assemblers will do this wherever possible. Note that the A2 encoding cannot set the flags (the S is not an available option with MOVW) so if you wrote MOVS with a 16-bit constant, it would not be able to use the A2 coding and would most likely generate an assembly error.

    Chris

  • Do you mean that the instruction I wrote(MOV or MOVW) is the only one reson for assembler to use A1 or A1 encoding?

    But the picture below shows that MOV is permitted by all encodings.

    1.png
  • Yes, the mnemonic you write in assembler (MOV or MOVW) is only one part of the choice of the encoding which the assembler will emit.

    If you write MOV, the assembler is free to choose from all available encodings (provided the registers used, the choice of flag-setting and the length of the constant fit options for the encoding).

    So, if you write MOV r0, #8, the assembler can choose from all available encodings for the instruction except T1 (because T1 always sets the flags).

    If you write MOVS r0, #8, it could choose from T1, T2 or A1. It will choose T1 because it's the shortest. For other values of the constant, it might prefer T2 or A1.

    If you write MOV with a 16-bit constant which cannot be encoded in the 12-bit format, the assembler will use encoding T3 or A2. The only difference between them is that A2 cannot be used when the destination register is PC, and T3 cannot be used when the destination register is PC or SP.

    However, if you write MOVW, it will be restricted to use T3 or A2. So, if you really must have one of those two, write MOVW.

    Hope that makes sense!

    Chris

  • I think I should point out that A1 format is not a 12-bit constant. It is an 8 bit constant rotated around by a power of 0,2,4,..30 so that for instance

    0x00057000 can be encoded

    0x345 cannot be encoded

    whereas for MOVW ( which will be used automatically if necessray)

    0x00057000 cannot be encoded

    0x345 can be encoded

  • You're absolutely right - thanks for pointing that out. 12-bit AREM constants are strange beasts!

  • They're very useful though. The Aarch64 also has a lot of strange but very useful constant encodings, a characteristic of the ISA that has thankfully been kept whatever about all the other simplifications.