Rep repe repz repnz scasb scasw Learning

Source: Internet
Author: User

Repeated prefix rep/repe/repne/repz/repnz

Rep movsb

The Assembly syntax is described as follows:

S: movsb

Loop s

In this case, the command after rep/repe/repne/repz/repnz is executed first and then the condition is checked! Similar

. Repeat

Command


[. Break [. If exit condition]

[. Continue]

.

The repeated prefix is used to control whether the subsequent basic string operation commands are repeated. Therefore, the repeated prefix cannot be used separately.

(1 ). some string operation commands (such as movs, lods, and STOs) can be added with the repeated prefix rep. The operations specified by the command can be repeated. The number of repeated operations is determined by the content of the specified CX register. The CPU usage is as follows:

① Check the Cx register first. If (CX) = 0, exit the rep operation;

② Execute a basic string operation in the Command;

③ Modify the address pointer Based on the DF mark;

④ CX minus L (but does not change the flag );

⑤ Repeat ①-④.

(2) If the string operation commands, such as the basic operations of CMPs and SCAs, affect ZF with no sign, the repe/repz or repne/repnz prefix can be added. In this case, the condition for repeated string operations is (CX) 0, and the ZF value must meet the requirements in the repeated Prefix: repe/repz requirement (ZF) = 1; repne/repnz requirement (ZF) = 0.

--------------------------

Format: repe (or repz) String Primitive
Here, String Primitive can be a CMPs or SCAs command.
Operation:
1) exit if (CX) = 0 or ZF = 0 (that is, the result of a comparison is different from the two operands). Otherwise, execute the statement.
2) execute the subsequent string commands
3) (CX) Compute (CX)-1
4) Repeat 1)-3)
In fact, repe and repz are exactly the same, but the expressions are different. Compared with rep, in addition to the condition that (CX) = 0 is met, the operation can be terminated, and the condition that ZF = 0 is added. It does not mean that the comparison can be continued as long as the two numbers are equal. If the two numbers are not equal, the operation can be terminated in advance.

----------------------------

Format: repne (or repnz) String Primitive
Here, String Primitive can be CMPs and SCAs commands.
Operation:
Except for the exit condition (CX) = 0 or ZF = 1, other operations are identical to the repe. That is to say, as long as the two numbers are not equal, you can continue to execute the string processing command. For example, if the two numbers are equal or (CX) = 0, the operation can be terminated.

--------

Format: SCAs CST
Scasb (bytes)
Scasw (word)
Operation:
Byte operations: (Al)-(DI), (DI) bytes (DI) ± 1
Word operation: (ax)-(DI), (DI) hour (DI) ± 2
The command compares the content of Al (or ax) with a byte (or word) specified by (DI) in the append segment, does not save the result, but sets the condition code based on the result, other features of the command are the same as those of the movs command.
The preceding two string processing commands can be combined with repe/repz or repne/repnz to compare two data strings or find a specified character from a string.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.