-
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(80486):
-
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.
-
Logic Instructions:
-
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:
-
Logic Instructions:
-
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:
-
Additional operations available in 80386 and up.
-
BT: Test the bit in the left operand specified by the right operand.
-
BTC: Tests and complements...
-
BTR: Tests and clears...
-
BTS: Tests and sets...
-
Puts bit under test in
C
flag. Latter three change the bit afterwards.
-
Logic Instructions:
-
NOT (logical one's complement)
-
NEG (arithmetic two's complement - sign of number inverted)
-
Shift:
-
Commonly used for control of I/O devices.
-
Also used for multiplication and division by powers of 2.
-
Logical shifts insert 0, used with unsigned numbers
-
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.
-
Program Control Instructions:
-
Conditional and Unconditional Jumps
-
Calls
-
Returns
-
Interrupts
-
Unconditional Jumps:
-
Short jump
:
PC-relative
using two bytes (+127/-128 bytes).
-
Short jumps are PC-relative (Offset added to IP: relocatable).
-
Unconditional Jumps:
-
Near jump
:
PC-relative
using three bytes (+/- 32K).
-
Since segments are cyclic, wrap around allows any location to be reached within the 64K segment.
-
In protected mode, near jumps ranges are +/-2G.
-
Far jump
:
Direct
jump using five bytes (address in instr. stream).
-
Two bytes give the offset and two bytes give a new segment address.
-
Protected mode: The segment value refers to a descriptor.
-
(Note: The linker needs to fill in the values in this case when the program files are combined.)
-
Indirect Jumps
: (EIP value in reg/mem, not in the instruction stream).
-
Uses a 16- or 32-bit register as an operand.
-
Unconditional Jumps:
-
Indirect Jumps
(register indirect address mode):
-
Usually a 16-bit offset is used and CS is left alone.
-
Using a FAR PTR directive loads both CS and IP.
-
Conditional Jumps:
-
Either
short
or
near
jumps on the 80386 and up (only short, otherwise).
-
Test flag bits S, Z, C, P and O.
-
Conditional Jumps:
-
For either signed or unsigned:
-
Test CX instead of flags:
-
Conditional Set instructions: (80386 and up)
-
Set a byte to either 01H or 00H, depending on the outcome of condition under test.
-
Useful if a condition must be tested much later in the program.
-
LOOP Instruction:
-
Combination of decrement CX and JNZ conditional jump.
-
Decrement CX
-
If CX != 0, jump to label
-
else fall through.
-
In 80386 and up, CX or ECX are decremented, depending on instruction mode.
-
Use LOOPW and LOOPD to force.