assemblyarmgnu-assemblerarmv7

ARM-GCC code directives for ArmV7A assembly code: .code vs .arm instruction mode directives


What is the difference between .code32, .code 32, and .arm directives in an assembly file?

The .S file will be compiled with arm-none-eabi-as

Are the three directives identical? None of these directives are explained in the programmer's guide (https://developer.arm.com/documentation/den0013/d/Introduction-to-Assembly-Language/Introduction-to-the-GNU-Assembler/Assembler-directives?lang=en), so it's hard to answer this myself.

Essentially, we wish to ensure that all functions writen in a given .S file are in ARM32 instruction mode (i.e. not Thumb).

-- Update: looks like I imagined .code32! The other two directives are identical, .arm is literally just shorthand for .code 32.

Cheers for fast replies!


Solution

  • They are documented in the GNU assembler manual at https://sourceware.org/binutils/docs/as/ARM-Directives.html#ARM-Directives.

    .code [16|32]

    This directive selects the instruction set being generated. The value 16 selects Thumb, with the value 32 selecting ARM.

    .arm

    This performs the same action as .code 32.

    So either one would do what you want.

    The .code32 variant is not mentioned. As you note, it doesn't actually work in GNU as. It could be a typo, or maybe some versions have permissive syntax that makes the space optional.