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!

Ani
  • 109
  • 2
  • 12
  • 2
    Have you checked the answers to [this question](http://stackoverflow.com/q/11785973/1072229) ? – Grisha Levit Jan 31 '17 at 20:31
  • What processor or architecture are you assuming when using the site? What class are you taking and is this just homework? – InfinitelyManic Jan 31 '17 at 20:32
  • @GrishaLevit Thank you. I have missed this. I will check it out. – Ani Jan 31 '17 at 20:34
  • @InfinitelyManic processor/architecture is ARM – Ani Jan 31 '17 at 22:02
  • @Ani - Yes - but there are different micro-architectures under ARM. See https://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. – InfinitelyManic Jan 31 '17 at 22:07
  • I think you want to read https://www.pjrc.com/teensy/beta/DDI0403D_arm_architecture_v7m_reference_manual.pdf this reference manual – Tommylee2k Feb 01 '17 at 07:52
  • On an unrelated note: I once wrote a fairly thorough peripheral emulator for the Armulator to simulate our foreseen SoCs. There was the Arm, the Thumb instructions, and my stuff--"If you can't give them the hardware, give them the Finger". Turns out marketing had a problem with that so we went a different direction. – Dave Newton Feb 02 '17 at 02:52
  • @Tommylee2k thank you so much! This will come in very handy :) – Ani Feb 02 '17 at 19:23
  • @DaveNewton Good story lol I wish I could do that with this project – Ani Feb 02 '17 at 19:23

2 Answers2

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.

Colin
  • 3,394
  • 1
  • 21
  • 29
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.

old_timer
  • 69,149
  • 8
  • 89
  • 168
  • 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 Feb 02 '17 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 Feb 02 '17 at 19:53