How to decode ARMv7 instructions?

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.


In the ARMv7-m ARM that I am looking at encoding T3 for subtract immediate which is supported by ARMv7-M architecture is in the form

SUB{S}<c>.W <Rd>,<Rn>,#<const>

the bit pattern 11110i01101S.... which matches with the 0xF1A of the instruction, sp is 13 and the two instances of 0XD in the encoding line up with that along with the immediate #8.

If you look at LDR (literal) the encoding is 0x4800 with a register and immediate. this instruction as documented does a pc relative load, so the pc is implied. likewise this is a 32 bit load, so when we assume 32 bit alignment the offset makes sense 0x34 is 110100, being 32 bit aligned we dont need the lower two bits they burn instruction space so 1101 which is a 0x0D giving 0x490D as the encoding.

It is all right there in the document you are looking at.

Tags:

Assembly

Arm

Arm7