stwbrx

Store Word Byte-Reverse Indexed

stwbrx RS, RA, RB

Swaps bytes and stores a word.

Details

The stwbrx instruction stores a word from a register to memory, reversing the byte order. The effective address is calculated by adding the contents of registers RA and RB. If RA is zero, it is treated as zero; otherwise, its value is used. The data from RS is stored in reverse byte order into the memory location specified by the effective address.

Pseudocode Operation

if RA = 0 then b ←0
else           b ←(RA)
EA ←b + (RB)
MEM(EA, 4) ←(RS)56:63 || (RS)48:55 || (RS)40:47 ||(RS)32:39

Programming Note

The stwbrx instruction is useful for storing a word in memory with its byte order reversed, which can be necessary for compatibility with systems that use different endianness. Ensure that the effective address (EA) calculated from registers RA and RB is properly aligned to avoid alignment exceptions. This instruction operates at user privilege level but will raise an exception if the EA is out of bounds or if there are insufficient permissions.

Example

stwbrx r3, r4, r5

Encoding

Binary Layout
31
0
RS
6
RA
11
RB
16
662
21
/
31
 
Format X-form
Opcode 0x7C00052C
Extension Base

Operands

  • RS
    Source
  • RA
    Base
  • RB
    Index