0

I see a lot of ARM assembly where immediate opcode values are prefixed with a #, and plenty of examples where it's not used. I've been searching everywhere to try a find a grammar or description for when it is needed, but found nothing.

In my testing all the below produce the same expected machine code output (i.e. 16 multiplied by an integer to be added to the stack pointer), however some of the formats cause my syntax highlighter issues.

    stp x2, x3, [sp, #16]
    stp x4, x5, [sp, (16 * 2)]
    stp x6, x7, [sp, #16 * 3]
    stp x8, x9, [sp, 64]
    stp x10, x11, [sp, #(16 * 5)]

Some forms are rejected by the compiler, such as the hash inside the parens [sp, (#16 * 2)] or on the second integer [sp, #16 * #2]

Is the # prefix required for any use-cases? Or is it entirely optional? (And is it documented anywhere?)

Bill Ticehurst
  • 1,728
  • 12
  • 14
  • Just found this in the "ARM arch reference manual" section "C2.1.5 A list of the assembler symbols for the instruction" - "# This usually precedes a numeric constant. All uses of # are optional in A64 assembler source code. Arm recommends that disassemblers output the # where the assembler syntax prototype includes it." Still, as can be seen above, where it can or can't be used on numeric constants (or parenthesized expressions) is quite inconsistent. – Bill Ticehurst May 18 '22 at 06:52
  • Thanks @NateEldredge! How the hell did all my search permutations miss that one :-/ – Bill Ticehurst May 18 '22 at 06:57

0 Answers0