cmpsq

Compare string quadwords

Compares the quadword at [rsi] with the quadword at [rdi], sets the flags, then advances rsi and rdi by 8, backward when DF is set.

x86-64 and later

CFPFAFZFSFDFOF ●●●●●–●
  • ● set from the result
  • – not changed
  • Reads DF

Forms

  • cmpsq

The q suffix selects an element of 8 bytes. After each element, the instruction increases rsi and rdi by 8 when DF = 0, or decreases rsi and rdi by 8 when DF = 1. In 64-bit mode the default addresses use rsi and rdi. The a32 address-size prefix instead uses esi and 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.

global _start

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

        cmpsq

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