Logical Instructions ..
The simpler way to understand the Logical Instructions is to think of them in Binary format. and, or, xor, not, test, as they only apply on Bits.
And
0 and 0 > 0
0 and 1 > 0
1 and 0 > 0
1 and 1 > 1
The result is 1 only when both bits are 1
Example, we have a Char in AL. This Char is known to be in the range of 'A-z'. Hexa ASCII code for 'A' is 041. Hexa ASCII code for 'a' is 061. The difference between 'A' and 'a' is 020 (decimal 32, Binary 0010_0000. So, we can consider that, for insuring that a Character will be Upper Case, we just have to ensure that this bit is zeroed:
mov al 'd'
and al 00_1101_1111 ; al = 'D'
Or
0 or 0 > 0
0 or 1 > 1
1 or 0 > 1
1 or 1 > 1
As you can see if either of the compared bits is 1 the result is 1.
Example: Ensure that a number is odd:
mov al 10
or al 1 ; al = 11
Xor
0 xor 0 > 0
0 xor 1 > 1
1 xor 0 > 1
1 xor 1 > 0
If the source Bit is set to 1, the destination Bit is inverted.
Example, the user of our application can set a feature On/Off with a Check Button. We retrieve this given information in a Value that can be either TRUE or FALSE to enable disable the feature:
If B§UserClickOnConfig1CheckBox = &TRUE
xor B§FlagForFeature1 &TRUE
End_If
Or even more concise:
mov al B§UserClickOnConfig1CheckBox
xor B§FlagForFeature1 al
Not
Not reverses all the target bits:
mov eax 0FF
not eax ; eax = 0_FFFF_FF00
You can consider this operation as a reversing sign one (for signed numbers), but:
mov eax 12
not eax ; eax = -13
...because of the Data Representation of signed Numbers. neg is the instruction of choice for this:
mov eax 12
neg eax ; eax = -12
Test
Test is just like some and operation that would not modify the target. The flags are set, depending on the result of this and operation. Example; checking if a signed Byte value is negative or positive:
test al 080 | jz Positive
; if here sign bit was on.
Positive:
(080 = 00_1000_0000 = high bit for a signed Octet, used as a '-' marker)
~~~~~~~