Computer Architecture &
Assembly Language
Topic (Arithmetic & Logic)
Introduction of ALU
• A Mathematician John Von Neumann proposed the ALU in
1945
• ALU stand for Arithmetic Logic Unit
• It’s part of computer microprocessor
• ALUs typically include these operations :
1. Arithmetic operations
2. Logical operations
ALU Location
ARITHMETIC OPERATION
• Arithmetic operation using for basic operations:
1. Addition
2. Subtraction
3. Multiplication
4. Division
• The computer uses binary code system to do arithmetic
operations
LOGICAL OPERATION
• It performs operations like comparing two data items to
find which data item is greater than, equal to , or less
than the other
• Logical operation Include
1. AND
2. OR
3. Exclusive-OR
4. NOT
ALU Diagram
Arithmetic Instructions:
Addition
• The instruction ADD is used to add two operands
• ADD A , Source ; A = A + Source
• Destination operand is always in register
• Source operand can be a register, immediate data, or in
memory
• Memory-to-memory arithmetic operations are never allowed
in Assembly language
Addition Formats
• Immediate Addition – Immediate addition is employed whenever
constant or known data are added. Examples are
1. MOV AL, 01H ; Load the value
ADD AL, 02H ; Addition of AL and immediate data 02
CF=0, AL=03H
2. ADD DX, BX; Add content of BX to content of DX
• Memory-to-Register Addition –Moves memory data to be added
to the AL (and other) register
ADD DX, [SI]; Add word from memory at [SI] in DS to content of DX
ADD Destination, Source
These instructions add a number from some SOURCE to a
number in some DESTINATION and put the result in the
specified DESTINATION.
ADD AL, 74H ;
Add immediate number 74H to content of AL. Result in AL
ADD DX, BX;
Add content of BX to content of DX
Example
MOV AL, 01H ; AL= 01 hex
ADD AL, 02H ; CF=0, AL=03H
Solution:
01H 0000 0001
+ 02H + 0000 0010
______________________
03H 0000 0011
ADC Destination, Source
A second form of addition, called ADD-WITH-CARRY, is introduced
with the ADC instruction.
ADC CL, BL;
Add content of BL plus carry status to content of CL
(CL= CL+BL+Carry Flag)
Example
MOV AX, F5H ;A=F5 hex
ADD AX, 0BH ;A=F5+0B=00 ; CF=1
Solution:
F5H 1111 0101
+ 0BH + 0000 1011
______________________
1 00H 0000 0000
Add 3 numbers using registers
MOV AX, 4DH; 4DH
MOV BX, 50H; + 50H
MOV CX, 8BH; _______
ADD AX, BX; 9DH
ADC AX,CX; + 8BH
_______
1 28H
Addition Example
SUBTRACTION
• Many forms of subtraction (SUB) appear in the instruction set.
• These use any addressing mode with 8-, 16-, or 32-bit data
• A special form of subtraction (decrement, or DEC) subtracts 1 from
any register or memory location
• Subtract-with-borrow instruction (SBB) performs this type of
subtraction
• SUB AX,BX ; B is subtracted from A with borrow (carry-in)
• Register Subtraction –after each subtraction, the microprocessor
modifies the contents of the flag register
• Immediate Subtraction –the microprocessor also allows immediate
operands for the subtraction of constant data
Example
MOV AX, F5H ;A=F5 hex
SUB AX, 0BH ;A=F5-0B=00 ;
Solution:
F5H 1111 0101
- 0BH - 0000 1011
______________________
EAH 1110 1010
SUBTRACT 3 numbers using registers
MOV AX, B4H; B4H
MOV BX, 87H; - 87H
MOV CX, 18H; _______
SUB AX, BX; 2DH
SUB AX,CX; - 18H
_______
15H
Subtraction Example