# `stosw`

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

**Store word to string**

Category: Block and string

Stores ax at [rdi], then advances rdi by 2, backward when DF is set.

8086 and later

[Intel's reference: STOS/STOSB/STOSW/STOSD/STOSQ](https://intel.github.io/SDM/instruction/STOS-STOSB-STOSW-STOSD-STOSQ.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 |

Reads: DF

## Forms

- `stosw`

## Description

The w suffix selects an element of 2 bytes. After each element, the instruction increases `rdi` by 2 when DF = 0, or decreases `rdi` by 2 when DF = 1. In 64-bit mode the default addresses use `rdi`. The `a32` address-size prefix instead uses `edi`; 16-bit string addressing is unavailable.

`rep` repeats until the counter reaches zero. The counter is `rcx` by default or `ecx` with `a32`. If it starts at zero, a repeated instruction accesses no element. The data width is independent of this address and counter width.

## Example

```x86
global _start

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

        stosw

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