rev16

Reverse Bytes Halfword (Thumb)

REV16 <Rd>, <Rm>

Reverse bytes in halfwords (Thumb).

Pseudocode Operation

Rd ← (Rm[7:0] << 8) | Rm[15:8] | (Rm[23:16] << 8) | Rm[31:24]

Example

REV16 r0, r2

Encoding

Binary Layout
10111010
15:8
01
7:6
Rm
5:3
Rd
2:0
 
Format Thumb Data Proc
Opcode 0xBA40
Extension T32 (Thumb)

Operands

  • Rd
    Destination general-purpose register
  • Rm
    Second source / offset general-purpose register

Related

Other forms of rev16

  • rev16 Reverse Bytes in Halfwords
  • rev16 Reverse Bytes in Halfwords (Thumb)

Across architectures

Byte Swap (Endianness Reversal) : how x86, ARM, RISC-V, and PowerISA each do this.

More in T32 (Thumb)

Reference

Instruction Forms

Encoding Instruction ISA Bit pattern
0x06BF0FB0 REV16{<c>}{<q>} <Rd>, <Rm> A32 cond | 01101 | 0 | 11 | 1 | 1 | 1 | 1 | Rd | 1 | 1 | 1 | 1 | 1 | 011 | Rm
0xBA40 REV16{<c>}{<q>} <Rd>, <Rm> T32 10111010 | 01 | Rm | Rd
0xFA90F090 REV16{<c>}.W <Rd>, <Rm> T32 111110101 | 001 | Rn | 1111 | Rd | 10 | 01 | Rm

Description

Byte-Reverse Packed Halfword reverses the byte order in each16-bit halfword of a 32-bit register.

Operation

if ConditionPassed() then
    EncodingSpecificOperations();
    bits(32) result;
    result<31:24> = R[m]<23:16>;
    result<23:16> = R[m]<31:24>;
    result<15:8>  = R[m]<7:0>;
    result<7:0>   = R[m]<15:8>;
    R[d] = result;