Logic Operation commands

Source: Internet
Author: User
Document directory
  • 5.2.4 logical operation commands

5.2.4 logical operation commands

Logical operation commands are another important group of commands, including: logic and (and), logic or (OR), logical non-(not) and XOR commands (XOR ), logical operation commands are also frequently used commands.

1. Logic and operation commands and (logical and instruction)

Command Format: And REG/MEM, Reg/MEM/IMM
Affected flag locations: CF (0), of (0), PF, SF, and ZF (not defined by AF)
The function of the command is to logically "and operate" each binary value in the source operand and the corresponding binary value in the destination operand, and save the operation result to the target operand.

For example, if 5.6 is known (BH) = 67 h, The 0th, 1, and 5 locations must be 0.

Solution: You can construct an immediate number. The values of 0th, 1, and 5 are 0, and the values of other bits are 1. The immediate number is 0dch or 11011100b, then run the command"And BH, 0dch.

The calculation process is shown in the right figure.

2. Logic or operation command or (logical or instruction)

Command Format: Or REG/MEM, Reg/MEM/IMM
Affected flag locations: CF (0), of (0), PF, SF, and ZF (not defined by AF)
The function of the command is to logically "or operate" each binary value in the source operand and the corresponding binary value in the target operand, and save the operation result to the target operand.

For example 5.7 (BL) = 46 h, the 1st, 3, 4, and 6 positions must be 1.

Solution: Construct an immediate number so that the values of 1st, 3, 4, and 6 are 1, and the values of other bits are 0. The immediate number is 5ah or 01011010b, then use the command "or BL, 5ah" to implement this function.

The calculation process is shown in the right figure.

3. Logical non-operation command not (logical not instruction)

Command Format: Not REG/MEM
The function is to reverse each of the operands, that is, 1 limit 0, 0 limit 1. The execution of commands does not affect any flag spaces.

For example, 5.8 known (Al) = 46 h. After the command "not Al" is executed, what is the value of Al?

Solution: After the command is executed, (Al) = 0b9h. The calculation process is as follows.

4. Logic exception or operation command XOR (exclusive or instruction)

Command Format: xor reg/MEM, Reg/MEM/IMM
Affected flag locations: CF (0), of (0), PF, SF, and ZF (not defined by AF)
The function of a command is to logically perform "operations" on each binary in the source operand and the corresponding binary in the target operand, and save the operation results to the target operand.

For example, if 5.9 is known (AH) = 46 h, the binary values of 0th, 2, 5, and 7 must be reversed.

Solution: Construct an immediate number so that the values of 0th, 2, 5, and 7 are 1, and the values of other bits are 0. The immediate number is 0a5h or 10100101b, then run the command "XOR ah, 0a5h" to implement this function.

The calculation process is shown in the right figure.

5. Summary of logical operation commands

The following is a control for learning and mastering logical commands. commands such as and, or, not, and XOR can be simulated.

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.