# `sahf`

[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/sahf

**Store ah into flags**

Category: System

Loads SF, ZF, AF, PF and CF from bits 7, 6, 4, 2 and 0 of ah.

8086 and later

[Intel's reference: SAHF](https://intel.github.io/SDM/instruction/SAHF.html)

## Flags

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

## Forms

- `sahf`

## Description

Bits 5, 3 and 1 are ignored, and OF and the rest of `rflags` are unchanged. In 64-bit mode it needs the LAHF/SAHF feature, which every current x86-64 processor has and a few of the first ones lack. [`lahf`](https://asm-editor.specy.app/documentation/x86/instruction/lahf.md) copies the same flags into `ah`.

## Example

```x86
global _start

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

        sahf

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