Chapter 3.2 Arthemetic and Logic Instruction Instruction Set
Chapter 3.2 Arthemetic and Logic Instruction Instruction Set
2
Arithmetic instructions
Addition
Subtraction
Multiplication
Division
BCD and ASCII arithmetic
instruction
Basic logic operation
AND, OR, NOT, XOR
Shift and Rotate instruction
3
4
5
Syntax:- ADD Destination, source
Algorithm:- destination = destination + source
Where (Destination , source combination)
Flag affected
6
Syntax:- ADC Destination, source
Algorithm:-destination = destination + source + cf
Where (Destination , source combination)
Flag affected
7
The source and destination can not be both
memory
Both source and destination must be the
same size (Both word and byte)
8
Syntax:- INC Destination
Algorithm:-destination = destination + 1
Where destination can be
Flag affected
9
10
Syntax:- SUB Destination, source
Algorithm:- destination = destination - source
Where (Destination , source combination)
Flag affected
11
They are special types of subtraction (dec)
instruction
Syntax: dec operand
Where operand can be register or memory
Function:sub 1 from operand
Algorithm operand= operand – 1
MOV AL,4
DEC AL
12
Mul (Unsigned multiplication)
Syntax:- mul operand
Algorithm:-
13
Syntax:- imul operand
Where operand can be
Algorithm (what it does)
Example
14
Div(unsigned division instruction)
Syntax:- DIV operand
Where operand can be
Algorithm
15
Syntax:- idiv operand
Where operand can be:-
Algorithm:-
16
BCD Arithmetic
DAA(decimal adjust after addition )
DAS (Decimal adjust after subtraction)
Syntax DAA (no operand)
Function:-
Corrects the result of addition of two packed
BCD values
Algorithm
17
18
Syntax:-DAS (no operand)
Function:
Corrects the result of subtraction of two packed
BCD values. It only work for AL registers
Algorithm
19
DAS
20
AAA (Ascii adjust after addition)
Function:
Corrects result in AH and AL after addition when
working with BCD values.
21
Algorithm:-
22
23
AAS (ascii adjust after sub..)
Aam (ascii adjust after
mul..)
AaD (ascii adjust before
div..)
24
add ax, bx ;axax+bx and set flags
adc ax, bx ;axax+bx+CF and set flags
inc ax ;axax+1 and set flags
aaa ;ASCII Adjust after Addition
daa ;Decimal (BCD) Adjust after Addition
sub ax, bx ;axax-bx and set flags
dec ax ;axax-1
das ;Decimal (BCD) Adjust after Subtraction
aas ;ASCII Adjust after Subtraction
mul cx ;dx:ax ax * cx (unsigned)
imul cx ;dx:ax ax * cx (2’s complement)
div cl ;alax/cl Quot. AND ahax/cl Rem.
idiv cx ;ax(dx:ax)/cx Quot. AND dx Rem.
Included in this groups of instruction are
AND,
OR,
XOR,
NOT and
TEST(which is a kinds of And
operator)
26
Syntax: AND operand1, operand2
Where OP1, op2 combination can be
27
Syntax: or operand1, operand2
Where op1,op2 combination can be
28
Syntax: xor operand1, operand2
Where op1,op2 combination can be
29
Syntax: not operand
Where op1,op2 combination can be
No flag is affected
30
Syntax: test operand1, operand2
Where op1,op2 combination can be
31
shl - Logical Shift Left
CF REG 0
REG CF
MSB
32
rol - Rotate Left
CF REG
CF REG
CF REG
33
BITWISE LOGICAL
not ax ;1’s Complement-Logical Invert
and ax, bx ;Bitwise logical and operation
or ax, bx ;Bitwise logical inclusive-or operation
xor ax, bx ;Bitwise logical exclusive-or operation
test ax, fffh ;Bitwise and but result discarded
SHIFT
shl ax, 4 ;Logical shift left
sal ax, 3 ;Arithmetic shift left
shr ax, 4 ;Logical shift right
sar ax, 3 ;Arithmetic shift right
ROTATE
rol bx, 3 ;Rotate left
ror cx, 4 ;Rotate right
rcl ax, 1 ;Rotate left through carry
rcr dx, 6 ;Rotate right through carry
34
35