wsbh

Word swap bytes within halfwords

Sets $t1 to $t2 with the two bytes of each halfword exchanged, so 0xAABBCCDD becomes 0xBBAADDCC.

Forms

  • wsbh ,

Operands

$t1
Any general-purpose register, $0 to $31, using its numeric or named spelling, such as $8 or $t0 ($zero is $0; $ra is $31).
$t2
A general-purpose register. It may be the same register as $t1.

Combined with 'rotr $t1,$t1,16' this reverses all four bytes, converting between little and big endian.

# Apply wsbh to initialized pattern 0x80FF. Inspect $t2: 0x0000FF80.
li $t0, 0x80FF
wsbh $t2, $t0