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
  • It should assemble a MOV with the 16-bit constant as a MOVW if the cpu option specifies an ARMv7 device, have you done that?

    You can see the MOVW encoding only came in with ARMv6T2, so one could only use 8 bit shifted constants before then.


    MOV and MOVN  are good for loading common constants where most of the bits are zero or one. They load an 8-bit constant or its negated value and rotate the 32 bit register, so MOV can for instance load 0x00520000.
    MOVW is especially useful paired with MOVT to load a 32 bit address.

Reply
  • It should assemble a MOV with the 16-bit constant as a MOVW if the cpu option specifies an ARMv7 device, have you done that?

    You can see the MOVW encoding only came in with ARMv6T2, so one could only use 8 bit shifted constants before then.


    MOV and MOVN  are good for loading common constants where most of the bits are zero or one. They load an 8-bit constant or its negated value and rotate the 32 bit register, so MOV can for instance load 0x00520000.
    MOVW is especially useful paired with MOVT to load a 32 bit address.

Children
  • Now I just talk about ARMv7 Architecture.

    The picture above shows that ARMv7 Architecture support both encoding A1 and A2.

    So I think MOV should be with 12bit constant.

    But in my project I did assemble a MOV with the 16-bit constant,and CCS didn't shows any errors.Why?


  • And does one project support encoding A1 and A2 at the same time?

  • 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.