2

I'm learning assembly language and I'm trying to understand how to convert between assembly-language to machine-language. I'm trying to read up sources and such, even asking my professors, but none has been helpful.This is the following code that I'm working on:

MOV R10, #63488 
LSL R9, R6, #7 
STR R4, [R11, R8] 
ASR R6, R7, R3

I found an ARM to HEX converter website and this is the conversion:

3EABA0E3
8693A0E1
08408BE7
5763A0E1

Can someone help explain to me how this works? Thank you so much!

9
  • 2
    Have you checked the answers to this question ? Commented Jan 31, 2017 at 20:31
  • What processor or architecture are you assuming when using the site? What class are you taking and is this just homework? Commented Jan 31, 2017 at 20:32
  • @GrishaLevit Thank you. I have missed this. I will check it out.
    – Ani
    Commented Jan 31, 2017 at 20:34
  • @InfinitelyManic processor/architecture is ARM
    – Ani
    Commented Jan 31, 2017 at 22:02
  • @Ani - Yes - but there are different micro-architectures under ARM. See en.wikipedia.org/wiki/List_of_ARM_microarchitectures . If I use the assembly code assuming an ARMv7 instruction set then the machine codes would be different than what you posted. For example, e3a0ab3e, e1a09386, e78b4008, e1a06357 using a Raspberry Pi2. Commented Jan 31, 2017 at 22:07

2 Answers 2

4

What you need is the ARM ARM (architecture reference manual) which is available freely from Arm's website, though you may need to register. It contains the encoding for all available instructions.

1
  • It is not the most user-friendly :P but I'll try it again!
    – Ani
    Commented Feb 2, 2017 at 19:24
3

Colin's answer is basically THE answer, just adding some more info. The tool you need is called an assembler, not an arm to hex converter. You can then use a disassembler to see it, for example with your program using gnu tools:

arm-none-eabi-as so.s -o so.o
arm-none-eabi-objdump -D so.o

produces

00000000 <.text>:
   0:   e3a0ab3e    mov r10, #63488 ; 0xf800
   4:   e1a09386    lsl r9, r6, #7
   8:   e78b4008    str r4, [r11, r8]
   c:   e1a06357    asr r6, r7, r3

And how the processor interprets the machine code is well documented in the ARM ARM, probably start with the ARMv5 one, which the older less complicated one. ARMv6, ARMv7 have a lot more operating system and protection features, mostly the same instruction set, although more thumb instructions, then ARMv8 is a hybrid with aarch32 the older ARMv4 to ARMv7 instruction set then a completely new aarch64 instruction set in the same core. So google arm architectural reference manual, some folks have illegally left them laying around or go to infocenter.arm.com to get the real ones.

2
  • I worked with some people and got the same answer as you suggest. We're using a tool called uVision by Keil to build target and debug. I'm about to try to see if the debug process shows me anything helpful. But I would like to be able to trace it by hand without using any tool eventually :P
    – Ani
    Commented Feb 2, 2017 at 19:30
  • Trace what machine code? While technically possible, it is a pain, not worth the badge of honor. ARM encodings are all over the place so it takes a ton of work let the tool do it. If it were mips for example or some others it is significantly easier to look at the machine code and decode it yourself by hand. What would be more interesting/useful is to write your own disassembler from scratch, same knowledge, applied differently.
    – old_timer
    Commented Feb 2, 2017 at 19:53

Not the answer you're looking for? Browse other questions tagged or ask your own question.