stosb

Store byte to string

Stores the byte in al at [rdi] and leaves the flags unchanged.

8086 and later

Intel's reference: STOS/STOSB/STOSW/STOSD/STOSQ

CFPFAFZFSFDFOF –––––––
  • Changes no flag
  • Reads DF

Forms

  • stosb

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

global _start

section .data
source: db 1, 2, 3, 4, 5, 6, 7, 8
destination: times 8 db 0

section .text
_start:
        cld                 ; count upwards
        mov rsi, source
        mov rdi, destination
        mov rax, 7
        stosb               ; writes al to [rdi]

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