-
Arithmetic Operations:
-
Addition
-
Subtraction
-
Multiplication
-
Division
-
Comparison
-
Negation
-
Increment
-
Decrement
-
Logic Operations:
-
AND
-
OR
-
XOR
-
NOT
-
shift
-
rotate
-
compare (test)
-
Addition, Increment, Add-with-carry and Exchange-and-add:
-
Contents of the rightmost 8 bits of the FLAGS register can change (+ Overflow) for arithmetic and logic instructions.
-
Z (result zero?)
-
C (carry out?)
-
A (half carry out?)
-
S (result positive?)
-
P (result has even parity?)
-
O (overflow occurred?)
-
Subtraction,Decrement and Subtract-with-borrow:
-
Comparison:
-
Changes only the flag bits.
-
Often followed with a conditional branch:
-
Multiplication and Division:
-
imul/idiv:
Signed
integer multiplication/division.
-
mul/div:
Unsigned
.
-
al always holds the
multiplicand
(or ax or eax).
-
Result is placed in ax (or dx and ax or edx or eax).
-
C
and
O
bits are cleared if most significant 8 bits of the 16-bit product are zero (result of an 8-bit multiplication is an 8-bit result).
-
Division by zero and overflow generate errors.
-
Overflow occurs when a small number divides a large dividend.
-
Allow bits to be set, cleared and complemented.
-
Commonly used to control I/O devices.
-
Logic operations always clear the
carry
and
overflow
flags.
-
AND: 0 AND anything is 0.
-
Commonly used with a MASK to clear bits:
-
OR: 1 OR anything is 1.
-
Commonly used with a MASK to set bits:
-
XOR: Truth table: 0110.
-
Commonly used with a MASK to complement bits:
-
TEST: Operates like the AND but doesn't effect the destination.
-
Sets the Z flag to the
complement
of the bit being tested:
-
BT: Test the bit, BTC: Tests and complements...
-
NOT (logical one's complement)
-
NEG (arithmetic two's complement - sign of number inverted)
-
Shift: Logical shifts insert 0, arithmetic right shifts insert sign bit.
-
Double percision shifts (80386 and up):
-
Rotate: Rotates bits from one end to the other
or through the carry flag
.
-
Commonly used to operate on numbers wider than 32-bits:
-
Bit Scan Instruction (80386 and up):
-
Scan through an operand searching for a 1 bit.
-
Zero flag is set if a 1 bit is found, position of bit is saved in destination register.
-
String Scan Instructions:
-
scasb
/
w
/
d
compares the
al
/
ax
/
eax
register with a byte block of memory and sets the flags. Often used with
repe
and
repne
-
cmpsb
/
w
/
d
compares 2 sections of memory data.
-
Conditional and Unconditional Jumps, Calls, Returns, Interrupts
-
Unconditional Jumps:
-
Short jump
:
PC-relative
using two bytes (+127/-128 bytes).
-
(PC-relative: constant added to eip).
-
Near jump
:
-
Within segment (max of +/- 2G).
-
Far jump
:
-
Four bytes give the offset and two bytes give a new segment address.
-
The segment value refers to a descriptor in protected mode.
-
Conditional Jumps:
-
Test flag bits S, Z, C, P and O.
-
For either signed or unsigned:
-
Test cx instead of flags:
-
Conditional Set instructions:
-
Set a byte to either 01H or 00H, depending on the outcome of condition under test.
-
LOOP Instruction:
-
Combination of decrement ecx and jnz conditional jump.
-
Decrement ecx
-
If ecx != 0, jump to label
-
else fall through.