Search code examples
assemblyarmbit16-bit

Changing sign in assembly (16 bit)


I'm supposed to change a 16 bit value from positive to negative. After Googling for some minutes I found a solution, but I'm still not sure if it's the right one, so would be great if you could help me. Appreciated!

eor r4, r1, #0x80000000


Solution

  • Use the reverse subtract instruction rsb to perform the task.

    rsb r4, r1, #0   @ computes r4 = 0 - r1
    

    This instruction is available both in ARM and in Thumb state, though Thumb1 only has

    rsbs Rd, Rn, #0
    

    restricting the immediate operand to #0.