# `bswap`

[x86-64 Documentation](https://asm-editor.specy.app/documentation/x86.md) › [Instructions](https://asm-editor.specy.app/documentation/x86/instruction.md)

Web page: https://asm-editor.specy.app/documentation/x86/instruction/bswap

**Byte swap**

Category: Logic

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](https://intel.github.io/SDM/instruction/BSWAP.html)

## Flags

| Flag | Effect |
| --- | --- |
| CF | not changed |
| PF | not changed |
| AF | not changed |
| ZF | not changed |
| SF | not changed |
| DF | not changed |
| OF | not changed |

## Forms

- `bswap reg` (32, 64)
  - `bswap reg32`
  - `bswap reg64`
- `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`.

## Description

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`.

## Example

```x86
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
```
