Search code examples
assemblyarm

What is the purpose of putting an immediate value in parens in ARM assembly?


What, if anything, is the difference between these two instructions?

subs    r2, r2, #(32)

subs    r2, r2, #32

What are the parentheses () for?


Solution

  • Actually, those are parentheses, not brackets.

    There is no difference between:

    subs    r2, r2, #(32)
    

    and

    subs    r2, r2, #32
    

    I suspect the (32) used to be something like (32 - 8) or something that was interesting / meaningful / necessary at the time, then the "- 8" was removed but the parentheses were simply kept since they do no harm.


    For the sake of completeness, even though it's not what you asked & you probably already know it:

    The code

    LDR r0, [r1]
    

    with "brackets" (register indirect) loads r0 with the value whose address is stored in r1 -- in other words, if r1 holds 1000, r0 will be loaded from MEM[1000]