Changing sign in assembly (16 bit)

1

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

assembly
arm
bit
16-bit
asked on Stack Overflow Jul 22, 2020 by Deividgp

1 Answer

1

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.

answered on Stack Overflow Jul 22, 2020 by fuz

User contributions licensed under CC BY-SA 3.0