Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
3 views

MOD_3!4!8086 Assembly Language Programming - Basic Programs

The document provides a series of assembly language programs for the 8086 microprocessor, covering various tasks such as searching data in an array, counting odd and even numbers, sorting arrays, checking for palindromes, and calculating GCD and LCM. It includes flowcharts and program code snippets for each task, detailing the memory addresses and instructions used. Additionally, it outlines several important programs and exercises for practice with the 8086 assembly language.

Uploaded by

jinu.23bce8495
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

MOD_3!4!8086 Assembly Language Programming - Basic Programs

The document provides a series of assembly language programs for the 8086 microprocessor, covering various tasks such as searching data in an array, counting odd and even numbers, sorting arrays, checking for palindromes, and calculating GCD and LCM. It includes flowcharts and program code snippets for each task, detailing the memory addresses and instructions used. Additionally, it outlines several important programs and exercises for practice with the 8086 assembly language.

Uploaded by

jinu.23bce8495
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 25

Module – 3

8086 Microprocessor : Assembly Language


Programming
Searching the existence of a certain data in a given data array
FLOW CHART
IF
START AX=[SI] YES
?
Initialize SI to 1200 memory
location NO

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

compare the content contents of SI moved


of AX with [SI] to 1400 memory location

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

Address Program Explanation


MOV CL, 06 Set counter in CL register
MOV SI, 1600 Set source index as 1600
MOV DI, 1500 Set Destination index as memory address 1500
Loop1: LODSB Load data from source memory
DEC CL Decrement the count
ROR AL, 01 Rotate AL once to right
JB Loop1 If bit is one Jump to Loop1
ROL AL,01 Rotate AL once to left
MOV [DI], AL Move result to Destination
INC DI Increment Destination index
CMP CL, 00H Compare CL to 00H
JNE Loop1 Jump if not equal to Loop1
HLT Stop the program
ALP to find the Sum of cubes of an array of size 10 by using 8086.
MOV SI,0200 H
MOV DI,0220H
MOV CL,0AH
MOV AX,0000 H
MOV [DI],AX
Up: MOV AL,[SI]
MOV BL,AL
MUL AL
MUL BL
ADD [DI],AX
INC SI
DEC CL
JNZ Up
HLT
CONVERSION OF BCD TO HEXADECIMAL
Write a program to sort a 8 bit data array in ascending order. The array consists of 5
numbers starting from location 3000H:4000H.
MOV AX,3000H
MOV DS,AX
MOV CH, 04H
L3: MOV CL,04H
MOV SI, 4000H
L2: MOV AL, [SI]
MOV AH, [SI+01H]
CMP AL, AH
JC L1
JZ L1
MOV [SI+1], AL
MOV [SI], AH
L1: INC SI
DEC CL
JNZ L2
DEC CH
JNZ L3
HLT
Program to check a number for bit wise palindrome. If
palindrome place FFH at 2500H or place 00H at 2500H
DATA SEGMENT
X DW 0FFFFH
MSG1 DB 10,13,'NUMBER IS PALINDROME$'
MSG2 DB 10,13,'NUMBER IS NOT PALINDROME$'
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE,DS:DATA
START: MOV AX,DATA ;Load the Data to AX. MOV AX, [2300H]
MOV DS,AX ;Move the Data AX to DS.
MOV AX,X ;Move DW to AX.
MOV CL,10H ;Initialize the counter 10.
MOV CL,10H ;Initialize the counter 10. UP: ROR AX,1 ;Rotate right one time.
UP: ROR AX,1 ;Rotate right one time. RCL DX,1 ;Rotate left with carry one time.
RCL DX,1 ;Rotate left with carry one time. DEC CL
LOOP UP ;Loop the process.
CMP AX,DX ;Compare AX and DX. JNZ UP ;Loop the process.
JNZ DOWN ;If no zero go to DOWN label. CMP AX,DX ;Compare AX and DX.
LEA DX,MSG1 ;Declare as a PALINDROME. JNZ DOWN ;If no zero go to DOWN label.
MOV AH,09H
INT 21H
MOV [2500H], FFH ;Declare as a PALINDROME.
JMP EXIT ;Jump to EXIT label. JMP EXIT ;Jump to EXIT label.
DOWN: LEA DX,MSG2 ; Declare as not a PALINDROME DOWN: MOV [2500H], 00H ; Declare as not a PALINDROME
MOV AH,09H EXIT: HLT
INT 21H
EXIT:MOV AH,4CH
INT 21H
CODE ENDS
END START
WAP to reverse a string of 100 bytes using stack. Check whether the
string is palindrome or not. If it is palindrome display FFH on a display
unit whose address is 64H else display 00H.
MOV SI, 2300H MOV SI, 2300H
MOV DI, 2500H MOV DI, 2500H
MOV CL, 64H MOV CL, 64H
L1: MOV AL, [SI] CLD
PUSH AL REPZ CMPSB
JNZ L3
INC SI MOV AL, FFH
DEC CL OUT 64H
JNZ L1 JMP Exit
MOV CL, 64H L3: MOV AL, 00H
L2: POP AL OUT 64H
MOV [DI], AL Exit: HLT
INC DI
DEC CL
JNZ L2
Program to get the square root of a number
M0V AX, [0500H] move the data from offset 500 to register AX
MOV CX, 0000H move 0000 to register CX
MOV BX, FFFFH move FFFF to register BX
L1: ADD BX, 0002H add BX and 02
INC CX increment the content of CX by 1
SUB AX, BX subtract contents of AX with BX
JNZ L1 jump to address 040A if zero flag(ZF) is 0
MOV [600], CX store the contents of CX to offset 600
HLT end the program
Write a program to get Factorial of 10 numbers stored from the starting
location 4000H:1000H. The results should be stored in 4000H:2000H
MOV 4000H, AX
MOV DS, AX
MOV SI,1000H
MOV DI, 2000H
Mov CL,0AH
MOV AL, 01H
Next:MOV BL,[SI]
LOOK:MUL BL
DEC BL
JNZ LOOK
MOV [DI], AL
INC SI
INC DI
LOOP NEXT
HLT
Write an ALP to convert binary number to gray code

Start

Initialize SI to 1200 memory location

Move contents of SI to AX and BX

Shift contents of BX to one bit right

Perform XOR operation on AX and BX

Move contents of AX to
1400 memory location

Stop
Program
MOV SI, 1200

MOV AX, [SI]

MOV BX, [SI]

SHR BX, 01

XOR AX, BX

MOV [1400], AX

HLT
Flowchart Start

Initialize SI to 1200 memory location

Move contents of SI to AX and BX

Shift contents of BX to one bit right

Perform XOR operation on AX and BX

Compare contents of BX with 0000

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.

You might also like