Electronic – How to decode ARMv7 instructions

armarm7assembly

I'm trying to understand ARM instruction encoding.

The following image shows C code along with its corresponding assembly instructions:

enter image description here

I looked at the ARMv7 reference manual. However, I couldn't find the relationship between the machine code and the corresponding assembly instruction.

For example,

I couldn't relate the machine code

F1AD0D08

to the assembly instruction

sub.w sp, sp, #8

Could you help me with this?

======================================================

Based on the answers and after looking at the reference manual, I added the following information.

The processor name is Cortex-M4F.

The processor architecture of the microcontroller I use is ARMv7.

Specifically, the microcontroller profile employed is ARMv7-M.

From the manual:

ARMv7-M The microcontroller profile for systems supporting only the
Thumb instruction set
, and where overall size and deterministic
operation for an implementation are more important than absolute
performance.

Best Answer

The ARMv7-M reference manual does not have a decode lookup table, but the encoding for each instruction is listed.

In the specific manual you have linked, you will find this in the section A6.7 - Alphabetical list of ARMv7-M Thumb instruction.

This contains - as stated - a list of every instruction, and their corresponding binary encoding. For example, page A6-16 has the binary encoding for the ADC (immediate) instruction. We can see that it starts with 11110... and spans two words.

The problem is going "backwards". The manual does indeed contain all the necessary information, but it is difficult to search. The disassembler has the data structures in place to do that for you, and if you want a table and do it manually, I suggest looking at the source code files for an ARM disassembler, for example GNU binutils.