EX.NO.1.
PROGRAMS FOR BASIC ARITHMETIC AND LOGICAL OPERATIONS
(USING 8086)
AIM:
To write an assembly language program to perform arithmetic operations using 8086
Microprocessor.
ALGORITHM:-
a) Addition:-
(i) Start the process
(ii) Initialize the count value
(iii) Get the two data.
(iv) Add the two data values
(v) If carry exists increment the count value.
(vi) Store the result.
(vii) Stop the process.
PROGRAM
Labe l Address Mnemonics Hex code Comments
Opcode Operand
1000 MOV CL , 00 C6, C1, 00 ; Initialize the count
st
1003 MOV AX, 0F0C C7, C0, 0C, 0F ; Move1 data to accumulator
nd
1007 MOV BX, 111F C7, C3, 1F, 11 ; Move2 data to register
100B ADD BX, AX 01, C3 ; Add the two data
100D JNC LOOP1 73, 02 ; Jump on no carry
100F INC CL FE, C1 ; Increment the counter
LOOP1: 1011 MOV [1100], BX 89,1E, 00, 11 ; Store the result
1015 MOV [1102], CL 88, 0E, 02,11 ; Store the carry
1019 HLT F4 ; Stop the process
OUTPUT
16 – BIT ADDITION
Address Output
1100 2B
1101 20
1102 00
1
16 BIT ADDITION
Start
Initialize count as zero for carry
Get the two data
Add the datas
If No
Carry
Yes
Increment the count
Store the result & carry
Stop
2
1 B) 16 BIT SUBTRACTION
ALGORITHM:-
(i) Start the process
(ii) Initialize the count value
(iii) Get the two data and subtract it.
(iv) If carry exists, get the 2‟s complement of the value.
(v) Store the result and carry value.
(vi) Stop the process.
PROGRAM
Labe l Address Mnemonics Hex code Comments
Opcode Operand
1000 MOV CL, 00 C6, C1, 00 ; Initialize the count
st
1003 MOV AX, [1100] 8B, 06, 00, 11 ; Move1 data to accumulator
nd
1007 MOV BX, [1102] 8B, 1E, 02, 11 ; Move 2 data to „B‟ register
100B SUB BX, AX 29, C3 ; Subtract the two datas
100D JNC LOOP1 73, 05 ; Jump on no carry
100F INC CL FE, C1 ; Increment the counter
1011 NOT BX F7, D3 ; Get the complement value
1013 INC BX 43 ; Increment the value
LOOP1: 1014 MOV [1104], BX 89, 1E, 04, 11 ; Store the result
1018 MOV [1106], CL 88, 0E, 06, 11 ; Store the carry
101C HLT F4 ; Stop the process
OUTPUT
16 – BIT SUBTRACTION
Address Input Address Output
1100 76 1104 31
1101 86 1105 65
1102 45 1106 00
1103 81
3
FLOWCHART:-
Subtraction:-
Start
Initialize count as zero for borrow
Get the two data
Subtract the datas
If No
Carry
exists
Yes
Take 2‟s complement
Store the result & carry
Stop
4
1.C) 16 BIT MULTIPLICATION
ALGORITHM:-
(i) Start the process
(ii) Get the two values
(iii) Multiply the two values.
(iv) Store the result and overflow
(v) Stop the process.
PROGRAM
Label Address Mnemonics Hex code Comments
Opcode Operand
1000 MOV SI, 1100 C7, C6,00, 11 ; Move the source index
1004 MOV AX, [SI] 8B, 04 value
1006 MOV BX, [SI + 02] 8B, 54, 02 ; Move the first data
1009 MUL BX F7, E3 ; Get the second data
100B MOV [SI + 04], 89, 44, 04 ; Multiply the data
100E MOV AX 89, 54, 0b ; Store the result
1011 HLT [SI + 06], F4 ; Store the over flow
DX ; Stop the process
INPUT OUTPUT
Address Input Address Output
1100 11 1104 00
1101 11 1105 21
1102 00 1106 22
1103 11 1107 01
5
FLOW CHART:-
Multiplication:-
Start
Get the two values
Multiply the values
Store the result & overflow
Stop
6
D) 16 BIT DIVISION
AIM:
To perform division of a 32 bit number by a 16 bit number and store the quotient and
remainder in memory
ALGORITHM:-
(i) Start the process
(ii) Get the two values
(iii) Initialize „DX‟ register as zero
(iv) Divide the values
(v) Store the quotient and remainder
(vi) Stop the process.
FLOWCHART:
7
D) 16 BIT DIVISION
PROGRAM
Label Address Mnemonics Hex code Comments
Opcode Operand
1000 MOV SI, 1100 C7, C6,00, 11 ; Get the source index value
1004 MOV Ax, [SI] 8B, 04 ; Get the first data
1006 MOV DX, [SI + 8B, 54, 02 ; Initialize „DX‟ register
1009 MOV 02] 8B, 5C, 04 value
100C DIV BX, [SI + 04] F7, E3 ; Get the dividend value
100E MOV BX 89, 44, 06 ; Divide the value
1011 MOV [SI + 06], 89, 54, 08 ; Move the quotient
1014 HLT AX F4 ; Move the remainder & store
[SI + 08], ; Stop the process
DX
16 – BIT DIVISIION
Address Input Address Output
1100 42 (DIVIDEND) 1106 21(QUOTIENT)
1101 24 1107 12
1102 00 1108 00(REMAINDER)
1103 00 1109 00
1104 02(DIVISOR)
1105 00
RESULT:-
Thus the assembly language program for 16 Bit Arithmetic and Logical operations has been done
and verified.