2 - Lecture 5
2 - Lecture 5
ADD AL, BL
ADD CL, [BP]
ADD BX, [EAX+2*ECX]
ADD [BX+DI], DL
Dr Nidal Al-Dmour Microprocessor and Assembly Language
However, there are over 32,000 variations of the
ADD instructions in the instruction set. It is
impossible to list all of them. The only types of
addition not allowed are memory-to-memory and
segment register. The segment registers can
only be moved, pushed, or popped.
ADD AX, BX
ADD AX, CX
ADD AX, DX
Whenever arithmetic and logic instructions
execute, the contents of the flag register
change. Any add instruction modifies the
contents of the sign, zero, carry, auxiliary carry,
parity, and overflow flags.
Dr Nidal Al-Dmour Microprocessor and Assembly Language
Immediate addition
MOV DL, 12H
ADD DL,33H
MOV AL, O
MOV SI, 3
ADD AL, ARRAY[SI]
ADD AL, ARRAY[SI+2]
ADD AL, ARRAY[SI+4]
INC BL
INC EAX
INC WORD PTR [EAX]
INC EAX
Dr Nidal Al-Dmour Microprocessor and Assembly Language
Increment instructions affect the flag bits, as do
most other arithmetic and logic operations. The
difference is that increment instruction do not
affect the carry lag bit. Carry does not change
because we often use increments in programs
that depend upon the contents of the carry flag.
Immediate subtraction
For example:
MOV CH, 22H
SUB CH, 44H
This example subtracted 34 from 68, resulting in
a DEH (-34). There is no overflow because the
overflow is greater than +127 or less than -128.
Dr Nidal Al-Dmour Microprocessor and Assembly Language
Decrement Subtraction
Decrement subtraction subtracts (DEC)
subtracts a 1 from register or the contents of the
memory location. The decrement indirect
memory data instructions require BYTE PTR,
WORD PTR, and DWORD PTR.
DEC BH
DEC CH
DEC BYTE PTR [BP]
DEC BH
DEC WORD PTR [BP]
SBB AH, AL
SBB DI, [BP+2]
SBB BYTE PTR [BP+2], 3
Dr Nidal Al-Dmour Microprocessor and Assembly Language
Dr Nidal Al-Dmour Microprocessor and Assembly Language
Compare
CMP AL,3
;if AL = 3 the result to zero (flag)
16-bit Multiplication
Word multiplication is very similar to byte
multiplication. The difference is that AX contains
the multiplicand instead of AL, and the product
appears in DX-AX instead of AX.
For example: MUL CX
Dr Nidal Al-Dmour Microprocessor and Assembly Language
32-bit Multiplication
In 0386 and above, 32 bit multiplication is
allowed because these microprocessors contain
32-bit registers. The contents of EAX are
multiplied by the operand specified with the
instruction. The product (64 bits wide) is found in
EDX-EAX.
MOV DX , 1234H
MOV BX, 3099H
MOV AL, BL
SUB AL, DL
DAS
MOV CL, AL
MOV AL, BH
SBB AL, DH
DAS
MOV CH, CL
Dr Nidal Al-Dmour Microprocessor and Assembly Language
Basic Logic Instructions
The basic logic instructions include AND, OR,
Exclusive-OR, NOT, NEG, and TEST. Logic
instructions allow bits to be set, cleared, or
complemented. All logic instructions affect the
flag bits.
TEST AL,3 ;test the right two bits (if both are zero the result is zero)
• There are 4 shift instructions. Two are logical shifts and two are
arithmetic shifts.
• The logical shifts reposition the bits in a number. The arithmetic
shifts multiply or divide signed numbers by powers of two.
• SHR and SHL are logical and SAR and SAL are arithmetic shifts.
SHL AL,3 or SHL AL,CL
• Rotates are shifts that re-circulate the bit that moves out of an end of
the register or memory location.
• Four rotates exist where two just rotate the target and two rotate the
target through the carry flag.
ROL AL,3 or RCL AL,3
SCAS
The SCAS (string scan) instruction compares
the AL register with a byte block of memory, the
AX register with a word block of memory, or the
EAX register with a double word block of
memory.
Dr Nidal Al-Dmour Microprocessor and Assembly Language
The opcode used for byte comparison is
SCASB, the opcode used for word comparison
is SCASW, and the opcode used for a
doubleword comparison is SCASD. In all cases
the contents of the extra segment memory
location addressed by DI is compared with AL,
AX, or EAX.