bswap

Byte swap

Reverses the byte order of a 32-bit or 64-bit register, so the lowest byte swaps places with the highest.

486 and later

Intel's reference: BSWAP

CFPFAFZFSFDFOF –––––––
  • Changes no flag

Forms

  • bswap ax 8086 and later
  • bswap cx 8086 and later
  • bswap dx 8086 and later
  • bswap bx 8086 and later

Operands

reg
A general-purpose register matching the operation’s size, for example al, ax, eax or rax. The byte registers ah, bh, ch and dh cannot be used with a REX prefix, which is required by spl, bpl, sil, dil and r8–r15.

For example, bswap rax exchanges byte 0 with byte 7, byte 1 with byte 6, and so on. A 32-bit result also clears the register's upper 32 bits. There is no defined 16-bit form; xchg al, ah swaps the bytes of ax.

global _start

section .text
_start:
        mov rax, 12
        mov rbx, 5
        mov rcx, 3
        mov rsi, 9

        bswap rax

        mov rax, 60         ; syscall 60: exit
        xor rdi, rdi
        syscall