# Illustration of Intel string instructions. # The STOS (STOre String) family of instructions do an extremely fast # copy of a given string to a bunch of consecutive memory locations, # much faster than one could do with MOV instructions in a programmer- # written loop. # The stosl instruction copies the word in EAX to the memory word # pointed to by the EDI register, and increments EDI by 4. # If we add the "prefix" rep, this effectively becomes the equivalent of # a loop: The stosl instruction will be executed repeatedly, with ECX # being decremented by 1 each time, until ECX reaches 0. Note that the # rep is in effect an extra op code, prepended before the instruction # itself. # EDI, EAX and ECX are wired-in operands for this instruction. The # programmer has no option here, and thus they do not appear in the # assembly code. The way to remember EDI is that the D stands for # "destination." # The STOS family of instructions includes 4-byte, 2-byte and 1-byte # versions. The latter two use AX and AL for the source string, # respectively, and in AT&T syntax are named stos and stosb. # There is also the MOVS family, which copies one possibly very long # string in memory to another place in memory. EDI again plays the # destination role, i.e. points to the place to be copied to, and the # ESI resgister points to the source string. .data x: .space 20 # set up 5 words of space .text .globl _start _start: movl $x,%edi movl $5,%ecx # we will copy our string to 5 words movl $0x12345678,%eax # the string to be copied is 0x12345678 rep stosl done: