The string operation command can operate on a block (string) byte or word in the storage area. The block length can be 64 K bytes, before any of these basic operation commands, you can use a repeated prefix to repeat them. Execute the string operation command repeatedly (the number of times controlled by CX) to perform string operations.
Note: All basic string operation commands are agreed: The Source string is addressable with the register Si. When no prefix is exceeded, the segment address is taken from the data segment register Ds; the destination string uses the register di for addressing, and its segment address is always taken from the additional segment register es. After each operation, the string operation command can automatically modify the address pointer Si and Di to point to the address of the next element in the string. However, if you change the address based on increment or decrease, it depends on the direction sign DF. If df = 0, then Si and Di are automatically incremental (byte operation plus 1, word operation plus 2); otherwise, Si and Di are automatically reduced. The status of DF is controlled by the instruction STD (set Direction Flag) and CLD (clear direction flag.
Note: movs, lods, and STOs commands have no effect on the flag bit. The effects of CMPs and SCAs commands on the flag bit are the same as those of CMP commands.
(1) Serial Transmission commands
Movs DST, SRC
Movsb (byte Operation)
Movsw (word Operation)
Perform the following operations: (DI) Merge (SI ))
After the operation is completed: (SI) ← (SI) ± 1, (DI) ← (DI) ± 1
(SI) lead (SI) ± 2, (DI) lead (DI) ± 2
DF = 0, +
DF = 1, get-
The string transmission command can be used together with the repeated operation prefix to transmit data strings.
In the second and third formats, the annotation is to transmit bytes and words. In the first format, it should indicate in the operand whether it is a word or a byte operation. For example:
MoV ES: byte PTR [di], DS: [Si]
Repeated operation prefixes can be in the following three forms:
1) Duplicate prefix
Rep Application Command: movs, STOs
2) equal duplicate prefixes
Repe/repz Application Command: CMPs, SCAs
3) Duplicate prefixes are not equal
Repne/repnz Application Command: CMPs, SCAs
Example:
Rep movsb:
1. Source string first address --> Si
2. Destination string first address --> Di
3. String Length --> CX
4. Set the Direction Flag
CLD ---> df = 0 Address Auto-Increment
STD ---> df = 1 address automatically subtracted
5. Execute the string operation rep movsb
The program copies buffer1 (4 bytes) ---> buffer2
Lea Si, buffer1
Lea Di, buffer2
MoV CX, 4
ClD
Rep movsb
(2) string comparison commands
CMPS SRC DST
Cmpsb (byte Operation)
Cmpsw (word Operation)
Complete the operation: (SI)-(DI ))
For example, do two strings (14 bytes) in two arrays (string L and string2) be the same, that is, compared (string L) = (string2 )?
Program instance:
Lea Si, string1
Lea Si, string2
MoV CX, 14
ClD
Repz cmpsb
(3) string search commands
Scasb (byte Operation)
Scasw (word Operation)
Byte operation: (Al)-(DI), (DI) hour (DI) ± 1
Word operation: (ax)-(DI), (DI) hour (DI) ± 2
(4) Saving string commands
STOs DST
Stosb (byte Operation)
Stosw (word Operation)
Byte operations: (DI) ← (AL), (DI) ← (DI) ± L
Word operation: (DI) hour (ax), (DI) hour (DI) ± 2
(5) Obtain string commands
Lods
Lodsb (byte Operation)
Lodsw (word Operation)
Byte operation: (Al) bytes (SI), (SI) bytes (SI) ± 1
Word operation: (ax) Accuracy (SI), (SI) Accuracy (SI) ± 2
Example of a string command:
MoV Si, Buf
MoV CX, 30
ClD
Lods (equivalent to mov Al, [Si] Inc Si)
The combination of string operation commands and repeated operation prefixes:
Rep stored strings and serial transmission commands
Repe/repz string comparison command repne/repnz string SEARCH Command
No string FETCH Command