User:No92/ARM Instruction Encoding

From OSDev Wiki
Jump to: navigation, search

This page is under construction! This page is a work in progress and may thus be incomplete. Its content may be changed in the near future.

This page summarizes the encoding of instructions for ARM. These encodings are tested on a Raspberry Pi, which is ARMv6.

Contents

condition codes

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.

instruction suffix description code
eq equals / equals zero 0000
ne not equal 0001
cs / hs carry set / unsigned higher or same 0010
cc / lo carry clear / unsigned lower 0011
mi negative 0100
pl positive or zero 0101
vs overflow 0110
vc no overflow 0111
hi unsigned higher 1000
ls unsigned lower or same 1001
ge signed greater or same 1010
lt signed less than 1011
gt signed greater 1100
le signed less than or equal 1101
al always 1110

No suffix defaults to al (always), which is hexadecimal '0xE'.

b (branch) and bl (branch with link)

This instruction changes the flow of the program by setting pc to a value encoded in the instruction.

Encoding

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.

Pitfalls

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.

Encoding

bits 31-28 bits 27-24 bits 23-0
condition code 1111 24-bit immediate

See also

External Links

Personal tools
Namespaces
Variants
Actions
Navigation
About
Toolbox