User:No92/ARM Instruction Encoding
This page summarizes the encoding of instructions for ARM. These encodings are tested on a Raspberry Pi, which is ARMv6.
One of the most awesome features of the ARM instruction set is conditional execution of instructions. These codes are 4-byte values that most instructions support. If the instructions support it, they are placed in bits 31-28.
|eq||equals / equals zero||0000|
|cs / hs||carry set / unsigned higher or same||0010|
|cc / lo||carry clear / unsigned lower||0011|
|pl||positive or zero||0101|
|ls||unsigned lower or same||1001|
|ge||signed greater or same||1010|
|lt||signed less than||1011|
|le||signed less than or equal||1101|
No suffix defaults to al (always), which is hexadecimal '0xE'.
This instruction changes the flow of the program by setting pc to a value encoded in the instruction.
|bits 31 - 28||bits 27 - 24||bits 23 - 0|
|condition code||1010 for b
1011 for bl
|signed 24-bit immediate|
The signed 24-bit immediate specifies the number of instructions (they are 4 bytes each) to go up/down in memory.
pc is pointing 8 bytes higher that the address of the current instruction. You have to take this into account when calculating an offset.
swi (Software Interrupt)
swi calls a software interrupt. It is used to provide syscalls. On Linux, the swi number for any syscall is always 0, as the syscall number is in r7.
|bits 31-28||bits 27-24||bits 23-0|
|condition code||1111||24-bit immediate|