How to store signed numbers in arm using MOV or MVN?

0

I am trying to learn ARM assembly and I wanted to store a signed number in a register, it has to be something like -

MOV R0, #-10

But this stores the number normally and not as a signed number. I tried using LDRSB as -

LDRSB R0, =0x0000000A, but it gave me errors.

assembly
arm
arm7

1 Answer

1

Assembly language is specific to the assembler. Did you mean arm7 or armv7?

This is gnu assembler

mov r0,#-10
ldr r0,=-10

.thumb

mov r0,#-10
ldr r0,=-10

.syntax unified

mov r0,#-10
ldr r0,=-10

so.s: Assembler messages:
so.s:12: Error: cannot honor width suffix -- `mov r0,#-10'
so.s:7: Error: invalid immediate: -10 is out of range

try again

mov r0,#-10
ldr r0,=-10

.thumb

@mov r0,#-10
ldr r0,=-10

.syntax unified

@mov r0,#-10
ldr r0,=-10


00000000 <.text>:
   0:   e3e00009    mvn r0, #9
   4:   e3e00009    mvn r0, #9
   8:   4800        ldr r0, [pc, #0]    ; (c <.text+0xc>)
   a:   4800        ldr r0, [pc, #0]    ; (c <.text+0xc>)
   c:   fffffff6    .word   0xfffffff6

so were you looking at (full sized) ARM then?

   0:   e3e00009    mvn r0, #9
   4:   e3e00009    mvn r0, #9

Which is the easiest one of the three to encode. And you can easily see the encoding in the ARM documentation. And the tools have already done half the work for you (0xfffffff6).

If you meant armv7 then

mov r0,#-10
ldr r0,=-10

.thumb

@mov r0,#-10
ldr r0,=-10

.syntax unified

mov r0,#-10
ldr r0,=-10

00000000 <.text>:
   0:   e3e00009    mvn r0, #9
   4:   e3e00009    mvn r0, #9
   8:   f06f 0009   mvn.w   r0, #9
   c:   f06f 0009   mvn.w   r0, #9
  10:   f06f 0009   mvn.w   r0, #9
answered on Stack Overflow Feb 1, 2021 by old_timer

User contributions licensed under CC BY-SA 3.0