Flow Control Instructions
Flow Control Instructions
Instructions
Sir. Rameez Raja
Boolean Operation in Assembly Language
The four basic operations of Boolean algebra:
AND, OR, XOR, and NOT.
These operations can be carried at the binary bit level, using assembly
language instructions.
The techniques used here could be used to manipulate control bits
for hardware devices, implement communication protocols, or
encrypt data.
Selected Boolean Instructions
The CPU Flags
Boolean instructions affect the Zero, Carry, Sign, Overflow, and Parity
flags.
• The Zero flag is set when the result of an operation equals zero.
• The Carry flag is set when an operation generates a carry out of the
highest bit of the destination operand.
• The Sign flag is a copy of the high bit of the destination operand,
indicating that it is negative if set and positive if clear. (Zero is
assumed to be positive.)
• The Overflow flag is set when an instruction generates an invalid
signed result.
• The Parity flag is set when an instruction generates an even number
of 1 bits in the low byte of the destination operand.
AND Instruction
The AND instruction performs a Boolean (bitwise) AND operation
between each pair of matching bits in two operands and places the
result in the destination operand:
AND destination, source
Rules:
The following operand combinations are permitted:
AND reg, reg
AND reg, mem
AND mem, reg
The operands can be 8, 16, or 32 bits, and they must be the same
size.
For each matching bit in the two operands, the following rule applies:
If both bits equal 1, the result bit is 1; otherwise, it is 0.
Bit Masking
The AND instruction lets you clear 1 or more bits in an operand without
affecting other bits. The technique is called bit masking.
For example:
Suppose AL is initially set to 10101110 binary. After ANDing it with
11110110, AL equals 10100110:
MOV al,11100011b
OR al,00000100b ; result in AL = 11100111
Bit-Mapped Sets
Binary bits can indicate set membership. Rather than holding pointers
or references to objects in a container such as a Java HashSet, an
application can use a bit vector (or bit map) to map the bits in a binary
number to an array of objects.
We can easily check for set membership
by ANDing a particular member’s bit position with a 1:
mov eax,101111
not eax ; complement is 010000
Set Intersection
The AND instruction produces a bit vector that represents the intersection of
two sets. The following code generates and stores the intersection of SetX
and SetY in EAX:
mov eax, SetX
and eax, SetY
This is how the intersection of SetX and SetY is produced:
1000000 00000000 00000000 00000111 (SetX)
(AND) 1000001 01010000 00000111 01100011 (SetY)
----------------------------------------------------
1000000 00000000 00000000 00000011 (intersection)
Set Union
The OR instruction produces a bit map that represents the union of
two sets. The following code
generates the union of SetX and SetY in EAX:
MOV eax, SetX
OR eax, SetY
This is how the union of SetX and SetY is generated by the OR
instruction:
1000000 00000000 00000000 00000111 (SetX)
(OR) 1000001 01010000 00000111 01100011 (SetY)
------------------------------------------------------
1000001 01010000 00000111 01100111 (union)