1 / 19

Boolean and Comparison Instructions

Boolean and Comparison Instructions. AND Instruction. Bitwise AND (result placed in destination) Mov al, 00001111b And al, 00111011b al = ? al = 00001011b (0Bh) Mov al, 6Dh And al, 4Ah al = ? al = 48h AND with a 0 to clear bits AND with a 1 to preserve bits (bit extraction)

blaze
Télécharger la présentation

Boolean and Comparison Instructions

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Boolean and Comparison Instructions

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

  3. Application:Converting Characters to Uppercase • Lowercase A (‘a’) is 61 0 1 1 0 0 0 0 1 • Uppercase A (‘A’) is 41 0 1 0 0 0 0 0 1 • Need to clear bit 5 Mov al, 61h AND al, 11011111b ;(DFh) ;al = 41h

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

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

  6. Application:Determining the sign of a value by ORing register with itself OR al, al

  7. XOR Instruction • Bitwise XOR (result stored in destination) Mov al, 94h XOR al, 37h al = ? al = 10100011b Mov al, 72h Xor al, 0DCh al = ? al = 10101110b • XOR reverses itself when applied twice to the same operand (data encryption) • Clears the Overflow and Carry flags. • May modify the sign, zero, and parity flags

  8. 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. Mov al, 10110101b XOR al, 0 ; al unchanged parity flag clear (PO) Mov al, 11001100b XOR al, 0 ; al unchanged parity flag set (PE)

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

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

  11. NOT Instruction • Toggles all bits in an operand • No flags are affected

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

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

  14. CMP Instruction Results

  15. CMP of Signed Integers

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

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

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

  19. In Class Problems • 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

More Related