-1

I'm new to ARM assembly. I'm trying to compare with number 1200 and register r1. So I tried :

 mov r2, #1210
 cmp r2, r1

but it does not work. I'm doing this programming in Raspberry pi 3. I tried :

 cmp #1210, r1

but it does not work too. How can I solve this? And, if r6's address is 0x00010000 and assembly code is:

ldr r10, r6, #8

is it same with code below? if not, how can I change code without using r6? thanks.

ldr r10, #0x00010008
jajajen
  • 29
  • 4
  • 2
    Can you elaborate on what "it doesn't work" means? Doesn't assemble? Produces a different result than you expected? What was that different result? – Steve Friedl Jun 26 '20 at 04:58
  • I think using mov, number limit is 255. If I try with number under 255, it works but 1210 not works. (compile error) Is there any way that I can use 1210? – jajajen Jun 26 '20 at 05:00
  • 1
    The width of the immediate for a `mov` instruction is 8 bits (0-255). However, there is sometimes more to the story (see https://stackoverflow.com/questions/2624471/how-to-use-mov-instruction-in-arm-with-an-immediate-number-as-the-second-operand). – Chris Loonam Jun 26 '20 at 05:26
  • you should always have the documentation by your side when doing assembly language programming or at least learning a new instruction set. that is not a legal immediate for the mov instruction so you have to use another instruction or use the pseudo instruction ldr r2,=1210 which some assemblers support. gnu assembler will use the most optimal solution (as pointed out in an answer below). by using the pseudo instruction (for any immediate) with gnu assembler you get the "best" solution. but assembly is based on the assembler, not the target, so this isnt true for all tools – old_timer Jun 26 '20 at 13:30
  • loading immediates into registers has been asked and answered many times at this site as well as other places. and why this didnt work is documented. – old_timer Jun 26 '20 at 13:31

1 Answers1

1

movw will do the trick. It allows any 16 bit number (0~65535)

Jake 'Alquimista' LEE
  • 6,197
  • 2
  • 17
  • 25
  • 1
    Available only in ARMv6T2 and later (see [here](http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.dui0473c/Chdfgchf.html)). – TonyK Jun 26 '20 at 11:59
  • 2
    @TonyK: Since the Raspberry Pi 3 is using a Cortex-A53, and since ARMv8-A includes AArch32, which provides backwards compatibility with ARMv7-A, availability of `movw` should not be an issue. – Frant Jun 26 '20 at 12:40