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.