Presentation is loading. Please wait.

Presentation is loading. Please wait.

Boolean and Comparison Instructions Operation Description ANDAND Destination, Source OROR Destination, Source XORXOR Destination, Source NOTNOT Destination.

Similar presentations


Presentation on theme: "Boolean and Comparison Instructions Operation Description ANDAND Destination, Source OROR Destination, Source XORXOR Destination, Source NOTNOT Destination."— Presentation transcript:

1

2 Boolean and Comparison Instructions Operation Description ANDAND Destination, Source OROR Destination, Source XORXOR Destination, Source NOTNOT Destination TEST Implied AND Destination, Source, Only FLAGS changed BT,BTC,BTR, BTS

3 AND Instruction Bitwise AND (result placed in destination) Bitwise AND (result placed in destination) Moval, 00001111b Andal, 00111011bal = ? al = 00001011b (0Bh) al = 00001011b (0Bh) Moval, 6Dh Andal, 4Ahal = ? al = 48h al = 48h AND with a 0 to clear bits AND with a 0 to clear bits AND with a 1 to preserve bits (bit extraction) AND with a 1 to preserve bits (bit extraction) Always clears the Overflow and Carry flags. Always clears the Overflow and Carry flags. May modify the Sign, Zero, and Parity flag May modify the Sign, Zero, and Parity flag

4 Application:Converting Characters to Uppercase Lowercase A (‘a’) is 610 1 1 0 0 0 0 1 Lowercase A (‘a’) is 610 1 1 0 0 0 0 1 Uppercase A (‘A’) is 410 1 0 0 0 0 0 1 Uppercase A (‘A’) is 410 1 0 0 0 0 0 1 Need to clear bit 5 Need to clear bit 5 Moval, 61h AND al, 11011111b;(DFh) ;al = 41h

5 OR Instruction Bitwise OR (result placed in destination) Bitwise OR (result placed in destination) Mov al, 0Fh Or al, 61hal = ? al = 6Fh al = 6Fh Mov al, 3Dh Or al, 74hal = ? al = 7Dh al = 7Dh OR with 1 to set selected bits OR with 1 to set selected bits OR with 0 to preserve bits OR with 0 to preserve bits Always clears the Overflow and Carry Flags Always clears the Overflow and Carry Flags May modify the Sign, Zero, and Parity Flags May modify the Sign, Zero, and Parity Flags

6 Application: Converting a Decimal Digit (byte) to ASCII Binary representation for 90 0 0 0 1 0 0 1 Binary representation for 90 0 0 0 1 0 0 1 Ascii 9 is 39h0 0 1 1 1 0 0 1 Ascii 9 is 39h0 0 1 1 1 0 0 1 Need to set bits 4 and 5 Need to set bits 4 and 5 Moval, 9 OR al, 30h ;al = 00111001b(39h)

7 Application:Determining the sign of a value by ORing register with itself OR al, al Zero FlagSign FlagValue in AL is … clear greater than 0 setclearequal to 0 clearsetless than 0

8 XOR Instruction Bitwise XOR (result stored in destination) Bitwise XOR (result stored in destination) Moval, 94h XORal, 37hal = ? al = 10100011b Moval, 72h Xoral, 0DChal = ? al = 10101110b XOR reverses itself when applied twice to the same operand (data encryption) XOR reverses itself when applied twice to the same operand (data encryption) Clears the Overflow and Carry flags. Clears the Overflow and Carry flags. May modify the sign, zero, and parity flags May modify the sign, zero, and parity flags

9 Parity Flag Indicates if the LOWEST BYTE of the result of a bitwise or arithmetic operation has an even or odd number of 1 bits. Moval, 10110101b XORal, 0 ; al unchanged parity flag clear (PO) Moval, 11001100b XORal, 0 ; al unchanged parity flag set (PE)

10 Application:How to check the parity of 16-bit registers Perform an XOR between upper-and lower bytes Movax, 64C1h;0110 0100 1100 0001 XORah, al ;ah = 10100101 Parity bit set (PE)

11 Application: How to check the parity of 32-bit registers Perform an XOR between bytes Moveax, 56D764C1h ;0101 0110 1101 0111 0110 0100 1100 0001 XORah, al;ah = 1010 0101 Shreax, 8 XORah, al;ah = 0111 0010 Shr eax, 8 XORah, al;ah = 0010 0100 Parity bit set (PE)

12 NOT Instruction Toggles all bits in an operand Toggles all bits in an operand No flags are affected No flags are affected

13 TEST Instruction Implied AND (no registers are changed) Implied AND (no registers are changed) (flags may be modified) (flags may be modified) Valuable for determining if individual bits are set. Valuable for determining if individual bits are set. Always clears the Overflow and Carry flags Always clears the Overflow and Carry flags May modify the sign, zero, and parity flags May modify the sign, zero, and parity flags

14 CMP Instruction Implied SUB (no registers are changed) Implied SUB (no registers are changed) (flags may be modified) (flags may be modified) May modify Overflow, Sign, Zero, Aux. Carry, and Parity flags May modify Overflow, Sign, Zero, Aux. Carry, and Parity flags

15 CMP Instruction Results Zero FlagCarry FlagCMP Results 01 destination < source CMP 5, 10 00 destination > source CMP 105, 10 10 destination = source CMP 10, 10

16 CMP of Signed Integers FlagsCMP Results SF ≠ OFdestination < source SF = OFdestination > source ZF = 1destination = source

17 In Class Problems 1.Write a single instruction that clears the high 8 bits of AX and does not change the low 8 bits. AND AX, 00FFh

18 In Class Problems 2.Write a single instruction that sets the high 8 bits of AX and does not change the low 8 bits. OR AX, FF00h

19 In Class Problems 3.Write a single instruction that complements all the bits in EAX (do not use the NOT instruction) XOR EAX, FFFFFFFFh

20 In Class Problems 4.Write instructions that set the Zero flag if the 32-bit value in EAX is even, and clear the Zero flag if EAX is odd. TEST EAX, 0000 0000 0000 0000 0000 0000 0000 0001b


Download ppt "Boolean and Comparison Instructions Operation Description ANDAND Destination, Source OROR Destination, Source XORXOR Destination, Source NOTNOT Destination."

Similar presentations


Ads by Google