X86-assembly/Instructions/stos

From aldeid
Jump to navigation Jump to search
You might also see: rep
You are here:
stos[b|d|w]

Description

  • The stos (Store String) instruction copies the value in AL, AX or EAX into the location pointed to by ES:DI or ES:EDI (depending on the address-size attribute of the instruction, 32 or 16, respectively). (E)DI is then incremented (if the direction flag is cleared) or decremented (if the direction flag is set), in preparation for storing AX in the next location.
  • stosb stores a byte from the AL register into the destination operand.
  • stosw stores a word from the AX register into the destination operand.
  • stosd stores a doubleword from the EAX register into the destination operand.

Syntax

stos
stosb
stosw
stosd

Example

When used in conjunction with the REP prefixes, the Store String instructions are useful for initializing a block of memory.

For example, the following code would initialize the 100-byte memory block at BUFFER to 0:

MOV     AL,0            ;The value to initialize BUFFER to
LEA     DI,BUFFER       ;Starting location of BUFFER
MOV     CX,100          ;Size of BUFFER
CLD                     ;Let's move in forward direction
REP     STOS BUFFER     ;Compare this line to example for STOSB

(Source: http://www.cs.ubbcluj.ro/~forest/HtmlFolder/AC/NG/ng1cf0a.html)

Comments