String operations are one of the best ways to apply something to a range of memory locations. Typical string operations are copying from one range to another and filling a range of memory locations with a specified value. Some string operations are:
| rep movsd -- copy one DWORD from one string to another |
| rep stosd -- set the DWORD to the value in EAX |
The last letter "D" of MOVSD or STOSD signifies DWORD. WORDs and BYTEs can be specified by using "W" or "B," respectively.
To use a string operation, 5 steps should be taken:
Set the source segment and offset
Set the destination segment and offset
Specify the direction (usually forward) of processing
Specify the number of units (DWORDs, WORDs, BYTEs) to apply the operation to
Specify the operation
Use DS to point to the source segment:
mov ax, ScratchSeg ; from a defined segment
mov ds, ax
Use ES to point to the destination segment:
mov ax, 0A000h ; graphics segment
mov es, ax
Specify the direction:
cld ; set direction flag forward
Specify the source offset:
mov esi, ScratchPad ; set the source offset
Specify the destination offset:
xor edi, edi ; set to 0
Specify the number of times to repeat the operation:
mov ecx, 16000
Specify the operation:
rep movsd