Arithmetic and Logic |
Arithmetic | Logic | Bitwise |
Add - Addition | AND - Logical AND - 1 AND 1 gives 1. Any other input gives 0. | ROL - Rotate bits left. Bit at left end moved to right end. |
Sub - Subtraction | OR - Logical OR - 0 OR 0 gives 0. Any other input gives 1. | ROR - Rotate bits right. Bit at right end moved to left end. |
Mul - Multiplication | XOR - Logical exclusive OR - Equal inputs give 0. Non equal inputs give 1. | SHL - Shift bits left and discard leftmost bit. |
Div - Division | NOT - Logical NOT - Invert the input. 0 gives 1. 1 gives 0. | SHR - Shift bits right and discard rightmost bit. |
Mod - Remainder after division | ||
Inc - Increment (add one) | ||
Dec - Decrement (subtract one) |
COMMANDS |
DIRECT EXAMPLES | ||
OP |
Assembler | Machine Code | Explanation |
ADD |
ADD AL,BL | A0 00 01 | Add BL to AL |
SUB |
SUB CL,DL | A1 02 03 | Subtract DL from CL |
MUL |
MUL AL,CL | A2 00 02 | Multiply AL by CL |
DIV |
DIV BL,DL | A3 01 03 | Divide BL by DL |
MOD |
MOD DL,BL | A6 03 01 | Remainder after dividing DL by BL |
INC |
INC AL | A4 00 | Add one to AL |
DEC |
DEC BL | A5 01 | Deduct one from BL |
AND |
AND CL,AL | AA 02 00 | CL becomes CL AND AL |
OR |
OR CL,DL | AB 02 03 | CL becomes CL OR DL |
XOR |
XOR BL,AL | AC 01 00 | BL becomes BL XOR AL |
NOT |
NOT CL | AD 02 | Invert the bits in CL |
ROL |
ROL DL | 9A 03 | Bits in DL rotated one place left |
ROR |
ROR AL | 9B 00 | Bits in AL rotated one place right |
SHL |
SHL BL | 9C 01 | Bits in BL shifted one place left |
SHR |
SHR CL | 9D 02 | Bits in CL shifted one place right |
COMMANDS |
IMMEDIATE EXAMPLES | ||
OP |
Assembler | Machine Code |
Explanation |
ADD |
ADD AL,15 | B0 00 15 |
Add 15 to AL |
SUB |
SUB BL,05 | B1 01 05 |
Subtract 5 from BL |
MUL |
MUL AL,10 | B2 00 10 |
Multiply AL by 10 |
DIV |
DIV BL,04 | B3 01 04 |
Divide BL by 4 |
MOD |
MOD DL,20 | B6 03 20 |
Remainder after dividing DL by 20 |
AND |
AND CL,55 | BA 02 55 |
CL becomes CL AND 55 (01010101) |
OR |
OR CL,AA | BB 02 AA |
CL becomes CL OR AA (10101010) |
XOR |
XOR BL,F0 | BC 01 F0 |
BL becomes BL XOR F0 |
ADD CL,AL - Add CL to AL and put the answer into CL.
ADD AL,22 - Add 22 to AL and put the answer into AL.
The answer always goes into the first register in the command.
DEC BL - Subtract one from BL and put the answer into BL.
The other commands all work in the same way.
If a calculation gives a zero answer, set the Z zero flag.
If a calculation gives a negative answer, set the S sign flag.
If a calculation overflows, set the O overflow flag.
An overflow happens if the result of a calculation has more bits than will fit into the available register. With 8 bit registers, the largest numbers that fit are -128 to + 127.
© C Neil Bauers 2003