# `scasd`

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

**Scan string for a doubleword**

Category: Block and string

Compares eax with the doubleword at [rdi], sets the flags, then advances rdi by 4, backward when DF is set.

386 and later

[Intel's reference: SCAS/SCASB/SCASW/SCASD](https://intel.github.io/SDM/instruction/SCAS-SCASB-SCASW-SCASD.html)

## Flags

| Flag | Effect |
| --- | --- |
| CF | depends on the result |
| PF | depends on the result |
| AF | depends on the result |
| ZF | depends on the result |
| SF | depends on the result |
| DF | not changed |
| OF | depends on the result |

Reads: DF

## Forms

- `scasd`

## Description

The d suffix selects an element of 4 bytes. After each element, the instruction increases `rdi` by 4 when DF = 0, or decreases `rdi` by 4 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.

`repe` / `repz` repeats while ZF = 1, and `repne` / `repnz` repeats while ZF = 0. Each stops when the counter reaches zero; a nonzero initial counter permits the first comparison before testing its result. 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

        scasd

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