MOD_3!4!8086 Assembly Language Programming - Basic Programs
MOD_3!4!8086 Assembly Language Programming - Basic Programs
Data of SI moved to AX IF
NO CX=00
?
Counter CX is assigned by 05
yes
YES
0000 is assigned to SI
Increment SI by 02 times
STOP
PROGRAM
Memory address label mnemonics MEMORY DATA IN
ADDRESS
3000 MOV SI, 1200
1200 AB96
MOV AX, [SI]
1202 89CD
MOV CX, 05
1204 AB96
L1 INC SI
1206 4EDF
INC SI
1208 9197
CMP AX, [SI] 120A 9600
JE L2
DEC CX
JNZ L1 MEMORY DATA OUT
ADDRESS
MOV SI, 0000
1400 1204
JMP L3
L2 MOV [1400], SI
L3 HLT
Write a 8086 ALP to count the number of odd and even numbers in a given set of
data array
Start
Move contents of AX to
1400 memory location
Stop
Program
MOV SI, 1200
SHR BX, 01
XOR AX, BX
MOV [1400], AX
HLT
Flowchart Start
No If equal
?
Yes
Move contents of AX to
Stop
1400 memory location
Program
Mnemonics
MOV SI, 1200
MOV AX, [ SI ]
MOV BX, [ SI ]
LOOP 1 SHR BX, 01
XOR AX, BX
CMP BX, 0000
JE LOOP 2
JMP LOOP 1
LOOP 2 MOV [ 1400 ], AX
HLT
Program to find Greatest common divisor (GCD) of
given numbers
MOV SI, 2300H ;Store Offset address 2300h in SI
MOV DI, 2400H ;Store offset address 2400h in DI
MOV AX, [SI] ;Move the first number to AX.
MOV BX, [SI+1] ;Move the second number to BX.
UP: CMP AX, BX ;Compare the two numbers.
JE EXIT ;If equal, go to EXIT label.
JB EXCG ;If first number is below than second, go to EXCG label.
UP1: MOV DX,0000H ;Initialize the DX.
DIV BX ;Divide the first number by second number.
CMP DX,0000H ;Compare remainder is zero or not.
JE EXIT ;If zero, jump to EXIT label.
MOV AX,DX ;If non-zero, move remainder to AX.
JMP UP ;Jump to UP label.
EXCG: XCHG AX,BX ;Exchange the remainder and quotient.
JMP UP1 ;Jump to UP1.
EXIT: MOV [DI], BX ;Store the result in DI.
HLT ; Stop
Program to find least common multiple (LCM) of a
given numbers
MOV SI, 2300H ;Store Offset address 2300h in SI
MOV DI, 2400H ;Store offset address 2400h in DI
MOV DX,0000H ;Initialize the DX
MOV AX,[SI] ;Move the first number to AX
MOV BX,[SI+2] ;Move the second number to AX
UP: PUSH AX ;Store the quotient/first number STACK
PUSH DX ;Store the remainder STACK
DIV BX ;Divide the first number by second number
CMP DX,0000H ;Compare the remainder.
JE EXIT ;If remainder is zero, go to EXIT label
POP DX ;If remainder is non-zero, ;Retrieve the remainder from stack
POP AX ;Retrieve the quotient from stack
ADD AX,[SI] ;Add first number with AX
JNC DOWN ;If no carry jump to DOWN label
INC DX ;Increment DX
DOWN: JMP UP ;Jump to Up label
EXIT: MOV [DI], AX ;If remainder is zero, store the value of LCM at destination
HLT ;Stop
Some important programs
• Program to count logical 1’s and 0’s in a given data
• Program for getting square of array of numbers
• Program to find LCM of a given numbers
• Program to find GCD of a given numbers
• Program to check a number is Bit wise palindrome or not
• Program to check a 16 bit number is Nibble wise palindrome or not
• Program to reverse a string
• Program to search for a character in a string
Q1. Write an 8086 ALP to add two numbers stored at 1020H and 2010H memory locations.
Store the result at location 3000H.
Q2. Add two arrays each having 05 elements each of size 8 bits stored at 1020H and 2010H.
Store the result in a new array having starting location 3000H.
Q3. Reverse an array having 10 elements each of size 16 bits stored at 4000H.
Q4. Transfer the data of an array having 10 elements from 2000H to a new location 4000H.