Logical instruction and shift instruction

Source: Internet
Author: User

 

I. Functions of logic operation commands

1, and (logical and): place a position 0,

Method: Set the corresponding bitwise to 0 and the other bitwise to 1 for another operand.

Example: mov Al, 0001 1101b

And Al, 1111 1110b

Result: Al = 0001 1100b (0 ).

2, or (logical or): Put a straight 1,

Method: Set the corresponding bitwise to 1 and other bitwise to 0 for another operand.

Example: mov Al, 0001 1101b

And Al, 0000 0010b

Result: Al = 0001 11B (Place 1 ).

3, not (logical not ):,,,.

4, XOR (exclusive or ):

A. Reverse the operand;

Method: In another operand, the opposite position 1 is to be obtained, and the other value is set to 0.

Example: mov Al, 1010 1001b

XOR Al, 3

Result: Al = 1010 1010b.

B. test whether the two operands are equal.

Method: See the example.

Example: XOR ax, 4c11h

JZ match

Result: If AX = 4c11h, the page jumps to match.

5. Test: similar to the and operation, but the result is not saved.

A. test whether a user is 0.

B. test whether a user is 1.

Method: test the corresponding position 1 on another operand, And the other positions are 0. If ZF = 1, the bit is 0. If ZF = 0, the bit is 1,

The preceding five commands do not allow immediate count, and the not command does not affect the flag. The other four commands set the CF bit and of bit to 0, and the AF command is not defined. SF, ZF, PF depends on the result

Second, the shift instruction is less efficient.

Logical left shift: SHL can be used to multiply the unsigned number by 2

Logically shift right; SHR can be used to divide the number of unsigned characters by 2

Features: 0 is promoted, and the last bit is pushed to CF

 

Arithmetic shift left: Sal can be used to multiply the number of symbols by 2

Arithmetic shift right: SAR can be used to divide the number of symbols by 2

Feature: 0 is promoted when you move left, and the sign bit is promoted when you move right.

 

Cycle left shift: rol

Shift right of loop: ror

Features, starting from beginning to end are pushed forward, and the last release space is given to CF

 

Shift left of the bitwise loop: RCL

Shift right of the bitwise loop: RCR

Features: release data to CF. The original CF is pushed in and connected to the beginning and end

 

The preceding instruction operand rules

For example:

SHL opr, CNT

OPR: Any addressing method other than immediate number

CNT: can be 1 or CL

 

Double-precision left shift command: shld DST, Reg, CNT

Dual-precision right shift command: shrd DST, Reg, CNT

. Dst: Any addressing method for the number of immediate exceptions

 

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.