Dept of E.C.
E MICRO PROCESSORS & MICRO CONTROLLERS LAB
INTRODUCTION TO MASM
1. Switch on the computer.
2. Select “start-> run” button.
3. Type “cmd” & click ok.
4. Press alt+enter to get full screen.
5. Type cd.. & press “enter” button.
6. Repeat step 4.
7. Type ” cd MASM (or) Term 86E” & press enter button.
8. Type “edit” & press “enter” button
9. Type the program & select “file ->save as”
10. Save the file with an exetenxion “.asm”,([Link])
11. Select “file->exit”
12. Type the command “MASM (or) Term 86E [Link]” & press enter 4 times.
13. Check if any errors / warnings are there in ur program ..if any errors are there modify
the program by giving the command ”edit [Link]”
14. Again save the program.
15. Repeat step 12 until u get 0 errors & 0 warnings.
16. Then type the command “link [Link]” ([Link]) & press enter 4 times
17. Then type the command “debug [Link]”([Link]) & press enter.
18. Give the command ” u “ to note the address & opcode of program.
19. Give the command ” t“ to check the registers update after each & every instruction
execution, repeat this process until the program ends.
20. If the RESULT is in memory location give the command “d ds:0000”
21. To quit from debugging mode type the command “q”
22. Repeat the same process from step 8 to execute the next program.
Vaagdevi Institute of Technology & Science, Proddatur Page 1
Dept of E.C.E MICRO PROCESSORS & MICRO CONTROLLERS LAB
1. PROGRAMS FOR 16 BIT ARITHMETIC OPERATIONS
(Using various addressing modes)
A. ADDITION & SUBTRACTION
Aim: To Write an Assembly Language Program to perforem addition & subtract two 16-Bit
Numbers.
Apparatus:
Software: MASM (or) TERM 86E
Hardware: PC, Key Board/ 8086 Trainer Kit, R.P.S
Program:
Adress Opcode Label Mnemonics Operands Comments
ASSUME CS:CODE, DS: DATA
DATA SEGMENT
X DW 4521H
Y DW 1324H
Z DW ?
DATA ENDS
CODE SEGMENT
MOV AX,DATA ;Copy Data Segment Starting Address
into AX Register
START:
MOV DS,AX ;Copy the Content of AX into DS
MOV AX,X ;Copy the Contents of X into AX
Register.
MOV BX,Y ;Copy the Contents of Y into BX
Register.
ADD AX, BX ;Add the Contents of AX with BX.
MOV Z,AX ;Copy the Contents of AX into memory
location pointed by Z.
INT 21H ;Return to DOS Prompt.
CODE ENDS
END START
Input: AX = 4521H, BX=1324H
Output: AX = 5645H
Subtraction Program:
Vaagdevi Institute of Technology & Science, Proddatur Page 2
Dept of E.C.E MICRO PROCESSORS & MICRO CONTROLLERS LAB
Adress Opcode Label Mnemonics Operands Comments
ASSUME CS:CODE, DS: DATA
DATA SEGMENT
X DW 4521H
Y DW 1324H
Z DW ?
DATA ENDS
CODE SEGMENT
START: MOV AX,DATA ;Copy Data Segment Starting
Address into AX Register
MOV DS,AX ;Copy the Content of AX into DS
MOV AX,X ;Copy the Contents of X into AX
Register.
MOV BX,Y ;Copy the Contents of Y into BX
Register.
SUB AX, BX ;Subtract the Contents of AX with BX.
MOV Z,AX ;Copy the Contents of AX into memory
location pointed by Z.
INT 21H ;Return to DOS Prompt.
CODE ENDS
END START
Input: AX = 4521H, BX=1324H
Output: AX = 31FDH
RESULT: The Assembly Language Program to add & subtract two 16-bit numbers was successfully
executed.
B. 16-BIT UNSIGNED & SIGNED MULTIPICATION & DIVISION
Vaagdevi Institute of Technology & Science, Proddatur Page 3
Dept of E.C.E MICRO PROCESSORS & MICRO CONTROLLERS LAB
Aim: To Write an Assembly Language Program to Perform Multiplication and Division of signed
and unsigned Hexadecimal numbers.
Apparatus:
Software: MASM (or) TERM 86E
Hardware: PC, Key Board, 8086 Trainer Kit, R.P.S
Unsigned Multiplication Program:
Adress Opcode Label Mnemonics Operands Comments
ASSUME CS:CODE, DS: DATA
DATA SEGMENT
X DW 4521H
Y DW 1324H
Z DW ?
DATA ENDS
CODE SEGMENT
START: MOV AX,DATA ;Copy Data Segment Starting
Address into AX Register
MOV DS,AX ;Copy the Content of AX into DS
MOV AX,X ;Copy the Contents of X into AX
Register.
MOV BX,Y ;Copy the Contents of Y into BX
Register.
MUL BX ;Multiply the Contents of AX with BX.
MOV SI, OFFSET Z ;Copy the Address pointed by Z into SI.
MOV [SI],AX ;Copy the Contents of AX into Memory
location pointed by SI.
ADD SI,02H ;Add 02 to SI Register.
MOV [SI],DX ;Copy the Contents of DX into memory
location pointed by SI.
INT 21H ;Return to DOS Prompt.
CODE ENDS
END START
Input: AX = 4521H, BX=1324H
Output: DX = 052BH & AX = 2BA4H (Multiplication Of 4521H * 1324H = 052B2BA4 H)
UNSIGNED DIVISION Program:
Adress Opcode Label Mnemonics Operands Comments
Vaagdevi Institute of Technology & Science, Proddatur Page 4
Dept of E.C.E MICRO PROCESSORS & MICRO CONTROLLERS LAB
ASSUME CS:CODE, DS: DATA
DATA SEGMENT
X DW 4521H
Y DW 1324H
Z DW ?
DATA ENDS
CODE SEGMENT
START: ;Copy Data Segment Starting
MOV AX,DATA Address into AX Register
MOV DS,AX ;Copy the Content of AX into DS
MOV AX,X ;Copy the Contents of X into AX
Register.
MOV BX,Y ;Copy the Contents of Y into BX
Register.
DIV BX ;Divide the Contents of AX with BX.
MOV SI, OFFSET Z ;Copy the Address pointed by Z into SI.
MOV [SI],AX ;Copy the Contents of AX into Memory
location pointed by SI.
ADD SI,02H ;Add 02 to SI Register.
MOV [SI],DX ;Copy the Contents of DX into memory
location pointed by SI.
INT 21H ;Return to DOS Prompt.
CODE ENDS
END START
Input: AX = 4521H, BX=1324H
Output: DX = 0BB5H (Remainder) & AX = 0003H (Quotient)
SIGNED MULTIPLICATION Program:
Adress Opcode Label Mnemonics Operands Comments
ASSUME CS:CODE, DS: DATA
DATA SEGMENT
X DW 4521H
Y DW 1324H
Z DW ?
DATA ENDS
CODE SEGMENT
START: MOV AX,DATA ;Copy Data Segment Starting
Address into AX Register
MOV DS,AX ;Copy the Content of AX into DS
XOR AX,AX ;Clear Contents of AX Register.
MOV AX,X ;Copy the Contents of X into AX
Register.
Vaagdevi Institute of Technology & Science, Proddatur Page 5
Dept of E.C.E MICRO PROCESSORS & MICRO CONTROLLERS LAB
MOV BX,Y ;Copy the Contents of Y into BX
Register.
NEG BX ;Perform 2’s Complement of BX.
CWD ;Convert Word into Double Word
IMUL BX ;Multiply the Contents of AX with BX
Including Sign.
MOV SI, OFFSET Z ;Copy the Address pointed by Z into SI.
MOV [SI],AX ;Copy the Contents of AX into Memory
location pointed by SI.
ADD SI,02H ;Add 02 to SI Register.
MOV [SI],DX ;Copy the Contents of DX into memory
location pointed by SI.
INT 21H ;Return to DOS Prompt.
CODE ENDS
END START
Input: AX = 4521H, BX=1324H
Output: DX = FAD4H & AX = D45CH ( Multiplication of 4521H * -1324H =FAD4D45C H)
SIGNED DIVISION Program:
Adress Opcode Label Mnemonics Operands Comments
ASSUME CS:CODE, DS: DATA
DATA SEGMENT
X DW 4521H
Y DW 1324H
Z DW ?
DATA ENDS
CODE SEGMENT
START: MOV AX,DATA ;Copy Data Segment Starting
Address into AX Register
MOV DS,AX ;Copy the Content of AX into DS
XOR AX,AX ;Clear Contents of AX Register.
MOV AX,X ;Copy the Contents of X into AX
Register.
MOV BX,Y ;Copy the Contents of Y into BX
Register.
NEG BX ;Perform 2’s Complement of BX.
CWD ;Convert Word into Double Word
IDIV BX ;Divide the Contents of AX with BX
Including Sign.
MOV SI, OFFSET Z ;Copy the Address pointed by Z into SI.
MOV [SI],AX ;Copy the Contents of AX into Memory
location pointed by SI.
ADD SI,02H ;Add 02 to SI Register.
MOV [SI],DX ;Copy the Contents of DX into memory
location pointed by SI.
Vaagdevi Institute of Technology & Science, Proddatur Page 6
Dept of E.C.E MICRO PROCESSORS & MICRO CONTROLLERS LAB
INT 21H ;Return to DOS Prompt.
CODE ENDS
END START
Input: AX = 4521H, BX=1324H
Output: AX = FFFDH (QUOTIENT)
DX = 0BB5H (REMAINDER)
RESULT: The Assembly Language Program to Perform Multiplication and Division of signed and
unsigned Hexadecimal numbers was successfully executed.
Vaagdevi Institute of Technology & Science, Proddatur Page 7
Dept of E.C.E MICRO PROCESSORS & MICRO CONTROLLERS LAB
C. FACTORIAL, SQUARE & CUBE OF A NUMBER
Aim: To Write an ALP to find square, cube and factorial of a given number.
Apparatus:
Software: MASM (or) TERM 86E
Hardware: PC, Key Board, 8086 Trainer Kit, R.P.S
Factorial Program:
Adress Opcode Label Mnemonics Operands Comments
ASSUME CS:CODE,DS:DATA
DATA SEGMENT
N DB 04H
RES DW ?
DATA ENDS
CODE SEGMENT
MOV AX,DATA ;Copy Data Segment Starting
START: Address into AX Register
MOV DS, AX ;Copy the Content of AX into
DS
XOR AX,AX ;Clear Contents of AX Register.
MOV AL, N ;Copy the Contents of X into AX
Register.
XOR BX,BX ;Clear Contents of BX Register.
MOV BL,AL ;Copy Contents of AL in to
Register BL
UP: DEC BL ; Decrement BL by 01
CMP BX, 01 ;Compare BX register contents
with 01H
JZ EXIT ; Jump to Label EXIT if ZF = 1
MUL BL ;Multiply contents of AL with BL
JMP UP ;Jump to Label UP
EXIT: MOV RES, AX ; Copy the Factorial of N into
Memory Location RES.
INT 21H ; Return to DOS Prompt
CODE ENDS
END START
Input: N =[0000]= 04H
Output: RES =[0001]= 18H
Square of a Number Program:
Vaagdevi Institute of Technology & Science, Proddatur Page 8
Dept of E.C.E MICRO PROCESSORS & MICRO CONTROLLERS LAB
Adress Opcode Label Mnemonics Operands Comments
ASSUME CS:CODE,DS:DATA
DATA SEGMENT
X DB 08H
SQR DW (?)
DATA ENDS
CODE SEGMENT
MOV AX,DATA ;Copy Data Segment Starting
START: Address into AX Register
MOV DS, AX ;Copy the Content of AX into
DS
XOR AX,AX ;Clear Contents of AX Register.
MOV AL, X ;Copy the Contents of X into AX
Register.
MUL AL ;Multiply contents of AL with AL
& RESULT is stored in AX.
MOV SQR,AX ;Copy the contents of AX into SQR
Memory Location
INT 21H ; Return to DOS Prompt
CODE ENDS
END START
Input: X =[0000]= 08H
Output: SQR =[0001]= 40H
Cube of a Number Program:
Adress Opcode Label Mnemonics Operands Comments
ASSUME CS:CODE,DS:DATA
DATA SEGMENT
X DB 08H
CUBE DW (?)
DATA ENDS
CODE SEGMENT
MOV AX,DATA ;Copy Data Segment Starting
START: Address into AX Register
MOV DS, AX ;Copy the Content of AX into
DS
XOR AX,AX ;Clear Contents of AX Register.
MOV AL, X ;Copy the Contents of X into AX
Register.
MOV BL,AL ;Copy the Contents of Register BL
into AL Register.
MUL BL ;Multiply contents of AL with BL
& RESULT is stored in AX.
Vaagdevi Institute of Technology & Science, Proddatur Page 9
Dept of E.C.E MICRO PROCESSORS & MICRO CONTROLLERS LAB
MUL BL ;Multiply contents of AL with BL
& RESULT is stored in AX.
MOV CUBE,AX ;Copy the contents of AX into SQR
Memory Location
INT 21H ; Return to DOS Prompt
CODE ENDS
END START
Input: X =[0000]= 08H
Output: AX= 200H
RESULT: The Assembly Language Program to find square, cube and factorial of a given number
was successfully executed.
Vaagdevi Institute of Technology & Science, Proddatur Page 10
Dept of E.C.E MICRO PROCESSORS & MICRO CONTROLLERS LAB
3. PROGRAMS INVOLVING BIT MANIPULATION INSTRUCTIONS
A. Data is Positive or Negative
Aim:To Write an Assembly Language Program to find the given data is positive or negative.
Apparatus:
Software: MASM (or) TERM 86E
Hardware: PC, Key Board, 8086 Trainer Kit, R.P.S
Program:
Adress Opcode Label Mnemonics Operands Comments
ASSUME CS:CODE,DS:DATA
DATA SEGMENT
NUM DB 12H
MES1 DB 10,13,"DATA IS POSITIVE$"
MES2 DB 10,13,"DATA IS
NEGATIVE$"
DATA ENDS
CODE SEGMENT
MOV AX,DATA ;Copy Data Segment Starting
START: Address into AX Register
MOV DS, AX ;Copy the Content of AX into
DS
XOR AX,AX ;Clear Contents of AX Register.
MOV AL, NUM ;Copy the Contents of NUM into
AX Register.
ROL AL,01 ; Rotate Left the contents of AL by
1 time.
JC NEGA ;Jump to Label NEGA if CY=1
MOV DX,OFFSET MES1 ;Copy the offset of MES1 into DX
Register
JMP EXIT ; Jumo to Label Exit
NEGA: MOV DX,OFFSET MES2 ;Copy the offset of MES2 into DX
Register
EXIT: MOV AH,09H ; Display the mesaage or string
whose address is given in DX.
INT 21H
MOV AH,4CH ;Terminate the Current Process &
Return to DOS Prompt
INT 21H
CODE ENDS
END START
Input:NUM = [0000]= 08H
Vaagdevi Institute of Technology & Science, Proddatur Page 11
Dept of E.C.E MICRO PROCESSORS & MICRO CONTROLLERS LAB
Output:DATA IS POSITIVE
RESULT: The Assembly Language Program to find the given data is positive or negative was
successfully executed.
B. Data is EVEN or ODD
Aim: To Write an Assembly Language Program to find the given data is Even or Odd.
Vaagdevi Institute of Technology & Science, Proddatur Page 12
Dept of E.C.E MICRO PROCESSORS & MICRO CONTROLLERS LAB
Apparatus:
Software: MASM (or) TERM 86E
Hardware: PC, Key Board, 8086 Trainer Kit, R.P.S
Program:
Adress Opcode Label Mnemonics Operands Comments
ASSUME CS:CODE,DS:DATA
DATA SEGMENT
NUM DB 15H
MES1 DB 10,13,"NUMBER IS EVEN$"
MES2 DB 10,13,"NUMBER IS ODD$"
DATA ENDS
CODE SEGMENT
MOV AX,DATA ;Copy Data Segment Starting
START: Address into AX Register
MOV DS, AX ;Copy the Content of AX into
DS
XOR AX,AX ;Clear Contents of AX Register.
MOV AL, NUM ;Copy the Contents of NUM into
AX Register.
TEST AL,01 ; Perform AND operation between
contents of AL & 01H
JNZ EXIT ;Jump to Label EXIT if ZF = 0
MOV DX,OFFSET MES1 ;Copy the offset of MES1 into DX
Register & Display the string
MOV AH,09H pointed by MES1 on Screen
INT 21H
EXIT: MOV DX,OFFSET MES2 ;Copy the offset of MES1 into DX
Register & Display the string
MOV AH,09H pointed by MES1 on Screen
INT 21H
LAST: MOV AH,4CH ;Terminate the Current Process &
Return to DOS Prompt
INT 21H
CODE ENDS
END START
Input: NUM = [0000]= 15H
Output: DATA IS EVEN.
Vaagdevi Institute of Technology & Science, Proddatur Page 13
Dept of E.C.E MICRO PROCESSORS & MICRO CONTROLLERS LAB
RESULT: The Assembly Language Program to find the given data is Even or Odd was successfully
executed.
C. COUNTING LOGICAL 0s & 1s
Aim:To Write an Assembly Language Program to find Logical ones and zeros in a given data
Vaagdevi Institute of Technology & Science, Proddatur Page 14
Dept of E.C.E MICRO PROCESSORS & MICRO CONTROLLERS LAB
Apparatus:
Software: MASM (or) TERM 86E
Hardware: PC, Key Board, 8086 Trainer Kit, R.P.S
Program:
Adress Opcode Label Mnemonics Operands Comments
ASSUME CS:CODE,DS:DATA
DATA SEGMENT
X DB 02AH
ONE DB ?
ZERO DB ?
DATA ENDS
CODE SEGMENT
MOV AX,DATA ;Copy Data Segment Starting
START: Address into AX Register
MOV DS, AX ;Copy the Content of AX into
DS
XOR AX,AX ;Clear Contents of AX Register.
MOV AL,X ;Copy the Contents of memory
location X into AX Register.
MOV BL,08 ; copy 08 in to register BL
MOV CL,01 ;copy 01 in to register CL
UP: ROR AL,CL ;Rotate Right the contents of AL by
CL times
JNC DOWN ; Jump to Label Down if CY=0
INC ONE ;Increment the memory location
ONE contents by 1.
JMP DOWN1 ; Jump to Label Down1
DOWN: INC ZERO ;Increment the memory location
ONE contents by 1.
DOWN1 DEC BL ; Decrement BL Register Contents
: by 01
JNZ UP ; Jump to Label UP if ZF = 0
MOV AH,4CH ;Terminate the Current Process &
Return to DOS Prompt
INT 21H
CODE ENDS
END START
Input:X = [0000]= 2AH = (0010 1010)2
Output: ONE = [0001] = 03
ZERO = [0002] = 05
Vaagdevi Institute of Technology & Science, Proddatur Page 15
Dept of E.C.E MICRO PROCESSORS & MICRO CONTROLLERS LAB
RESULT: The Assembly Language Program to find Logical ones and zeros in a given data was
successfully executed.
3. PROGRAMS ON ARRAYS FOR 8086
[Link] of N no‘s.
Aim: To Write an Assembly Language Program to find Addition of N Numbers.
Apparatus:
Vaagdevi Institute of Technology & Science, Proddatur Page 16
Dept of E.C.E MICRO PROCESSORS & MICRO CONTROLLERS LAB
Software: MASM (or) TERM 86E
Hardware: PC, Key Board/ 8086 Trainer Kit, R.P.S
LARGEST NUMBER Program:
Adress Opcode Label Mnemonics Operands Comments
ASSUME
CS:CODE,DS:DATA
DATA SEGMENT
ARRAY DB
29H,15H,32H,08H,45H,17H
COUNT EQU 06H
DATA ENDS
CODE SEGMENT
START: MOV AX,DATA ;Copy Data Segment Starting
Address into AX Register
MOV DS,AX ;Copy the Content of AX into DS
XOR AX,AX ;Clear Contents of AX Register.
XOR BX,BX ;Clear Contents of BX Register.
MOV CL,COUNT-1
;Copy 05H into CL Register
MOV SI,OFFSET ;Copy the Address Pointed by ARRAY
ARRAY into SI Register.
MOV AL,[SI] ;Copy the Contents of Memory
Location pointed by SI Register into
AL Register.
INC SI ;Increment SI Contents by one.
L1: MOV BL,[SI] ;Copy the Contents of Memory
Location pointed by SI Register into BL
Register.
ADC AL,BL ;Add contents of AL & BL with carry.
INC SI ;Increment SI Contents by one.
DEC CL ;Decrement CL Contents by one.
JNZ L2 ;Jump to L2 if CL is not equal to Zero.
INT 21H ;Terminate the Current Process &
Return to DOS Prompt
CODE ENDS
END START
Input: LIST
[0000]= 29H
[0001]= 15H
[0002]= 32H
[0003]= 08H
[0004]= 45H
[0005]= 17H
Vaagdevi Institute of Technology & Science, Proddatur Page 17
Dept of E.C.E MICRO PROCESSORS & MICRO CONTROLLERS LAB
Output: AX=00D4H
RESULT: The Assembly Language Program to find Addition of N numbers was successfully
executed.
Vaagdevi Institute of Technology & Science, Proddatur Page 18
Dept of E.C.E MICRO PROCESSORS & MICRO CONTROLLERS LAB
B. LARGEST / SMALLEST NUMBER
Aim: To Write an Assembly Language Program to find Largest / Smallest number.
Apparatus:
Software: MASM (or) TERM 86E
Hardware: PC, Key Board/ 8086 Trainer Kit, R.P.S
LARGEST NUMBER Program:
Adress Opcode Label Mnemonics Operands Comments
ASSUME CS:CODE, DS: DATA
DATA SEGMENT
LIST DB
29H,15H,32H,08H,45H,17H
COUNT EQU 06H
DATA ENDS
CODE SEGMENT
START: MOV AX,DATA ;Copy Data Segment Starting
Address into AX Register
MOV DS,AX ;Copy the Content of AX into DS
XOR AX,AX ;Clear Contents of AX Register.
MOV CL,COUNT-1 ;Copy 05H into CL Register
MOV SI,OFFSET LIST ;Copy the Address Pointed by LIST
into SI Register.
MOV AL,[SI] ;Copy the Contents of Memory
Location pointed by SI Register into
AL Register.
CMP AL,[SI+1] ;Compare the Contents of AL with
L2: Contents of memory location pointed
by SI.
JNC L1 ;Jump to L1 if Carry Flag is Not Set.
MOV AL,[SI+1] ;Copy the Contents of memory pointed
by SI+1 into AL.
INC SI ;Increment SI Contents by one.
L1:
DEC CL ;Decrement CL Contents by one.
JNZ L2 ;Jump to L2 if CL is not equal to Zero.
INT 21H ;Return to DOS Prompt.
CODE ENDS
END START
Input:LIST
[0000]= 29H
[0001]= 15H
[0002]= 32H
[0003]= 08H
[0004]= 45H
[0005]= 17H
Output: AL=45H
SMALLEST NUMBER Program:
Vaagdevi Institute of Technology & Science, Proddatur Page 19
Dept of E.C.E MICRO PROCESSORS & MICRO CONTROLLERS LAB
Adress Opcode Label Mnemonics Operands Comments
ASSUME CS:CODE, DS: DATA
DATA SEGMENT
LIST DB
29H,15H,32H,08H,45H,17H
COUNT EQU 06H
DATA ENDS
CODE SEGMENT
START: MOV AX,DATA ;Copy Data Segment Starting
Address into AX Register
MOV DS,AX ;Copy the Content of AX into DS
XOR AX,AX ;Clear Contents of AX Register.
MOV CL,COUNT-1 ;Copy 05H into CL Register
MOV SI,OFFSET LIST ;Copy the Address Pointed by LIST
into SI Register.
MOV AL,[SI] ;Copy the Contents of Memory
Location pointed by SI Register into
AL Register.
CMP AL,[SI+1] ;Compare the Contents of AL with
L2: Contents of memory location pointed
by SI.
JC L1 ;Jump to L1 if Carry Flag is Set.
MOV AL,[SI+1] ;Copy the Contents of memory pointed
by SI+1 into AL.
INC SI ;Increment SI Contents by one.
L1:
DEC CL ;Decrement CL Contents by one.
JNZ L2 ;Jump to L2 if CL is not equal to Zero.
INT 21H ;Return to DOS Prompt.
CODE ENDS
END START
Input: LIST
[0000]= 29H
[0001]= 15H
[0002]= 32H
[0003]= 08H
[0004]= 45H
[0005]= 17H
Output: AL=08H
RESULT: The Assembly Language Program to find Largest & Smallest number was successfully
executed.
Vaagdevi Institute of Technology & Science, Proddatur Page 20
Dept of E.C.E MICRO PROCESSORS & MICRO CONTROLLERS LAB
C. ASCENDING ORDER / DESCENDING ORDER
Aim: To Write an Assembly Language Program to Sort the given numbers in Ascending /
Descending Order.
Apparatus:
Software: MASM (or) TERM 86E
Hardware: PC, Key Board/ 8086 Trainer Kit, R.P.S
ASCENDING ORDER Program:
Adress Opcode Label Mnemonics Operands Comments
ASSUME CS:CODE, DS: DATA
DATA SEGMENT
LIST DB
29H,15H,32H,08H,45H,17H
COUNT EQU 06H
DATA ENDS
CODE SEGMENT
START: MOV AX,DATA ;Copy Data Segment Starting
Address into AX Register
MOV DS,AX ;Copy the Content of AX into DS
XOR AX,AX ;Clear Contents of AX Register.
MOV DL,COUNT-1 ;Copy 05H into DL Register
MOV CL,DL ;Copy the Contents of DL into CL.
UP2:
MOV SI,OFFSET LIST ;Copy the Address Pointed by LIST
into SI Register.
UP1: MOV AL,[SI] ;Copy the Contents of Memory
Location pointed by SI Register into
AL Register.
INC SI ;Increment SI Contents by one.
CMP AL,[SI] ;Compare the Contents of AL with
Contents of memory location pointed
by SI.
JC L1 ;Jump to L1 if Carry Flag is Set.
XCHG AL,[SI] ;Exchange the Contents of AL With
Contents of memory pointed by SI.
DEC SI ;Decrement SI Contents by one.
MOV [SI],AL ;Copy the Contents of AL into memory
location pointed by SI.
JMP UP1 ;Jump to Label UP1
L1: LOOP UP1 ;Decrement CL & Jump to UP1 if CL is
not equal to zero.
DEC DL ;Decrement DL Contents by one.
JNZ UP2 ;Jump to UP2 if DL is not equal to
Zero.
MOV AL,[SI] ;Copy the Contents of AL With
Contents of memory pointed by SI.
INT 21H ;Return to DOS Prompt.
Vaagdevi Institute of Technology & Science, Proddatur Page 21
Dept of E.C.E MICRO PROCESSORS & MICRO CONTROLLERS LAB
CODE ENDS
END START
Input: LIST
[0000]= 29H
[0001]= 15H
[0002]= 32H
[0003]= 08H
[0004]= 45H
[0005]= 17H
Output:
[0000]= 08H
[0001]= 15H
[0002]= 17H
[0003]= 29H
[0004]= 32H
[0005]= 45H
Descending Order Program:
Adress Opcode Label Mnemonics Operands Comments
ASSUME CS:CODE, DS: DATA
DATA SEGMENT
LIST DB 29H,15H,32H,08H,45H,17H
COUNT EQU 06H
DATA ENDS
CODE SEGMENT
START: MOV AX,DATA ;Copy Data Segment Starting
;Address into AX Register
MOV DS,AX ;Copy the Content of AX into DS
XOR AX,AX ;Clear Contents of AX Register.
MOV DL,COUNT-1 ;Copy 05H into DL Register
MOV CL,DL ;Copy the Contents of DL into CL.
UP2:
MOV SI,OFFSET LIST ;Copy the Address Pointed by LIST
into SI Register.
UP1: MOV AL,[SI] ;Copy the Contents of Memory
Location pointed by SI Register into
AL Register.
INC SI ;Increment SI Contents by one.
CMP AL,[SI] ;Compare the Contents of AL with
Contents of memory location pointed
by SI.
JNC L1 ;Jump to L1 if Carry Flag is Not Set.
XCHG AL,[SI] ;Exchange the Contents of AL With
Contents of memory pointed by SI.
DEC SI ;Decrement SI Contents by one.
MOV [SI],AL ;Copy the Contents of AL into
memory location pointed by SI.
JMP UP1 ;Jump to Label UP1
Vaagdevi Institute of Technology & Science, Proddatur Page 22
Dept of E.C.E MICRO PROCESSORS & MICRO CONTROLLERS LAB
L1: LOOP UP1 ;Decrement CL & Jump to UP1 if CL
is not equal to zero.
DEC DL ;Decrement DL Contents by one.
JNZ
UP2 ;Jump to UP2 if DL is not equal to
Zero.
MOV AL,[SI] Copy the Contents of AL With
;Contents of memory pointed by SI.
INT 21H ;Return to DOS Prompt.
CODE ENDS
END START
Input: LIST
[0000]= 29H
[0001]= 15H
[0002]= 32H
[0003]= 08H
[0004]= 45H
[0005]= 17H
Output:
[0000]= 45H
[0001]= 32H
[0002]= 29H
[0003]= 17H
[0004]= 15H
[0005]= 08H
RESULT: The Assembly Language Program to arrange given list of numbers in Ascending and
Descending Order was successfully executed.
Vaagdevi Institute of Technology & Science, Proddatur Page 23
Dept of E.C.E MICRO PROCESSORS & MICRO CONTROLLERS LAB
4. STRING OPERATIONS
A. STRING LENGTH
Aim: To Write an Assembly Language Program to Comapre two strings are equal or not using
String Prefix.
Apparatus:
Software: MASM (or) TERM 86E
Hardware: PC, Key Board/ 8086 Trainer Kit, R.P.S
Program:
Adress Opcode Label Mnemonics Operands Comments
ASSUME CS:CODE,DS:DATA
DATA SEGMENT
STR1 DB "HELLO$"
MSG DB 10,13,"LENGTH OF
STRING IS:$"
LEN DB 03 DUP("$")
DATA ENDS
CODE SEGMENT
START: MOV AX,DATA ;Copy Data Segment Starting
;Address into AX Register
MOV DS,AX ;Copy the Content of AX into DS
MOV SI,OFFSET ;Clear adress of STR1 in to SI Registe
STR1
MOV CL,00H ;Copy 00H into DL Register
MOV AL,'$' ; Copy the Character $ in to AL
L1: CMP AL,[SI] ; Compare the Contents of AL with
Contents of memory location pointed
by SI.
JE L2 ;Jump to Label L2 if Equal or ZF = 1
INC SI ;Increment the contents of SI by 1
INC CL ; Increment CL register Contents by 1
JMP L1 ; Jump to Label L1
L2: ADD CL,30H ; ADD 30H to CL Register Contents
MOV DX,OFFSET ;Copy the offset of MSG into DX
MSG Register & Display the string pointed
MOV AH,09H by MSG on Screen
INT 21H
MOV DI,OFFSET ;Copy the Offset of LEN in to DI
LEN Register
MOV [DI],CL ;Copy the Contents of CL in to memory
location pointed by DI
MOV DX,OFFSET ;Copy the offset of MSG into DX
LEN Register & Display the string pointed
by MSG on Screen
MOV AH,09H
INT 21H
Vaagdevi Institute of Technology & Science, Proddatur Page 24
Dept of E.C.E MICRO PROCESSORS & MICRO CONTROLLERS LAB
MOV AH,4CH ;Terminate the Current Process &
INT 21H Return to DOS Prompt
CODE ENDS
END START
INPUT: STR1= HELLO
OUTPUT: Length of the String = 5.
RESULT: Assembly Language Program to find Length of the string was successfully executed.
Vaagdevi Institute of Technology & Science, Proddatur Page 25
Dept of E.C.E MICRO PROCESSORS & MICRO CONTROLLERS LAB
B. STRING DISPLAY
Aim: To Write an Assembly Language Program to display the given string .
Apparatus:
Software: MASM (or) TERM 86E
Hardware: PC, Key Board/ 8086 Trainer Kit, R.P.S
Program:
Adress Opcode Label Mnemonics Operands Comments
ASSUME CS:CODE,DS:DATA
DATA SEGMENT
STRING DB 10,13,”THIS IS A
SAMPLE STRING $”
DATA ENDS
CODE SEGMENT
START: MOV AX,DATA ;Copy Data Segment Starting
Address into AX Register
MOV DS,AX ;Copy the Content of AX into DS
LEA DX,STRING ;Copy the offset of MSG into DX
Register & Display the string pointed
MOV AH,09H by MSG on Screen
INT 21H
MOV AH,4CH ;Terminate the Current Process &
Return to DOS Prompt
INT 21H
CODE ENDS
END START
INPUT: STRING = THIS IS A SAMPLE STRING
OUTPUT:THIS IS A SAMPLE STRING
Vaagdevi Institute of Technology & Science, Proddatur Page 26
Dept of E.C.E MICRO PROCESSORS & MICRO CONTROLLERS LAB
READ A STRING FROM KEY BOARD& DISPLAY ON MONITOR:
ASSUME CS:CODE,DS:DATA
DATA SEGMENT
MSG1 DB 10,13,"ENTER A STRING:$"
MSG2 DB 10,13,"YOU ENTERED THE STRING:$"
STR DB 20 DUP("$")
DATA ENDS
CODE SEGMENT
START: MOV AX,DATA
MOV DS,AX
MOV DX,OFFSET MSG1
MOV AH,09H
INT 21H
MOV SI,OFFSET STR
MOV AH,01H
L1:INT 21H
MOV [SI],AL
INC SI
CMP AL,0DH
JNZ L1
L2: MOV DX,OFFSET MSG2
MOV AH,09H
INT 21H
MOV DX,OFFSET STR
MOV AH,09H
INT 21H
MOV AH,4CH
INT 21H
CODE ENDS
END START
INPUT: ENTER A STRING: HELLO
OUTPUT: YOU ENTERED THE STRING : HELLO
RESULT:Assembly Language Program to display given string are equal or not using String Prefix
was successfully executed.
Vaagdevi Institute of Technology & Science, Proddatur Page 27
Dept of E.C.E MICRO PROCESSORS & MICRO CONTROLLERS LAB
C. STRING COMPARISON
Aim: To Write an Assembly Language Program to Compare two strings are equal or not using
String Prefix.
Apparatus:
Software: MASM (or) TERM 86E
Hardware: PC, Key Board/ 8086 Trainer Kit, R.P.S
Program:
Adress Opcode Label Mnemonics Operands Comments
ASSUME CS:CODE,DS:DATA
DATA SEGMENT
STR1 DB "HELLO$"
MSG1 DB 10,13,"STRINGS ARE
EQUAL$"
MSG2 DB 10,13,"STRINGS ARE
NOT EQUAL$"
STR2 DB "HEPLO$"
DATA ENDS
CODE SEGMENT
ORG 1000H
START: MOV AX,DATA ;Copy Data Segment Starting Address
into AX Register
MOV DS,AX ;Copy the Content of AX into DS
MOV ES,AX ;Copy the Content of AX into ES
LEA SI,STR1 ;Copy the offset address of STR1 into
SI
LEA DI,STR2 ;Copy the address of STR1 into DI
MOV CL,05 ;Copy the Count Value 05 into CL
CLD ;Clear the Directional Flag
REP CMPSB ;Compare STR1 with STR2
JE L1 ;Jump if Equal or Zero to Address
Pointed by Label L1
MOV DX,OFFSET ;Write theString pointed by MSG2 on
MSG2 Standard Output.
MOV AH,09
INT 21H
L1: JMP L2 ;Jump to address pointed by L1
MOV DX,OFFSET ;Write theString pointed by MSG1 on
MSG1 Standard Output.
L2: MOV AH,09H
INT 21H
MOV AH,4CH ;Terminate the Current Process &
Return to DOS
INT 21H
CODE ENDS
END START
INPUT: STR1= HELLO
STR2= HEPLO
OUTPUT: Strings are not Equal.
RESULT: Assembly language program to Compare two strings are equal or not using String Prefix
was successfully executed.
Vaagdevi Institute of Technology & Science, Proddatur Page 28
Dept of E.C.E MICRO PROCESSORS & MICRO CONTROLLERS LAB
D. STRING REVERSE & PALINDROME
Aim: To Write an Assembly Language Program to Reverse a given String.
Apparatus:
Software: MASM (or) TERM 86E
Hardware: PC, Key Board/ 8086 Trainer Kit, R.P.S
Program:
Adress Opcode Label Mnemonics Operands Comments
ASSUME CS:CODE,DS:DATA
DATA SEGMENT
STR1 DB "HELLO$"
STR2 DB 255 DUP("$")
MSG1 DB 10,13,"STRING IS
PALINDROME$"
MSG2 DB 10,13,"STRING IS NOT
PALINDROME$"
MSG3 DB 10,13,"STRING IN REVERSE
IS:$"
DATA ENDS
CODE SEGMENT
START: MOV AX,DATA ;Copy Data Segment Starting Address into AX
Register
MOV DS,AX ;Copy the Content of AX into DS
MOV SI,OFFSET STR1 ;Copy the offset address of STR1 into SI
MOV CL, LENGTH STR1 ;Copy the Count Value 05 into CL
MOV DI,SI ;Copy the contents of SI into DI
ADD DI,04 ;Add 04H to DI Register
L1: MOV AL,[SI] ;Copy the contents pointed by memory
location of SI into AL.
CMP AL,[DI] ;Compare the contents pointed by memory
location of DI with AL.
JNE L2 ; Jump if Not Equal or ZF =0 to label L2
INC SI ; Increment SI Contents by 01.
DEC DI ; Decrement DI Contents by 01.
DEC CL ;Decrement CL Contents by 01.
JNZ L1 ;Jump to Label L1if ZF=0.
MOV DX,OFFSET MSG1 ;Write theString pointed by MSG1 on
Standard Output.
MOV AH,09H
INT 21H
JMP L3 ; Jump to Label L3
L2: MOV DX,OFFSET MSG2 ;Write theString pointed by MSG2 on
Standard Output.
MOV AH,09H
INT 21H
Vaagdevi Institute of Technology & Science, Proddatur Page 29
Dept of E.C.E MICRO PROCESSORS & MICRO CONTROLLERS LAB
L3: MOV SI,OFFSET STR1 ;Copy the offset address of STR1 into SI
Register
MOV CL,05H ; Copy 05 in to CL Registe
ADD SI,04 ;Add 04 to contents of SI
MOV DI,OFFSET STR2 ;Copy the offset address of STR1 into SI
Register
L4: MOV AL,[SI] ;Copy the contents pointed by memory
location of SI into AL.
MOV [DI],AL ;Copy the contents of AL in to memory
location pointed by DI.
DEC SI ; Decrement SI contents by 01
INC DI ; Increment DI contents by 01
DEC CL ; Decrement CL contents by 01
JNZ L4 ; Jump to Label L4 if ZF = 0
MOV DX,OFFSET MSG3 ;Write theString pointed by MSG3 on
Standard Output.
MOV AH,09H
INT 21H
MOV DX,OFFSET STR2 ;Write theString pointed by STR2 on
Standard Output.
MOV AH,09H
INT 21H
MOV AH,4CH ;Terminate the Current Process & Return to
DOS
INT 21H
CODE ENDS
END START
INPUT: STR1= HELLO.
OUTPUT: String in Reverse is: OLLEH.
String is not a Palindrome.
RESULT: The Assembly Language Program to Reverse the given string & checking wheteher it is a
palindrome or not was successfully executed.
Vaagdevi Institute of Technology & Science, Proddatur Page 30
Dept of E.C.E MICRO PROCESSORS & MICRO CONTROLLERS LAB
5. DIGITAL CLOCK DESIGN USING 8086
A. DESIGNING CLOCK USING INT 21H INTERRUPT.
Aim: To Write an Assembly Language Program for designing clock using int 21h interrupt.
Apparatus:
Software: MASM (or) TERM 86E
Hardware: PC, Key Board, 8086 Trainer Kit, R.P.S
Program:
ASSUME CS:CODE,DS:DATA
DATA SEGMENT
MESSAGE DB 'CURRENT TIME IS:$'
HR DB ?
MIN DB ?
SEC DB ?
MSEC DB ?
DATA ENDS
CODE SEGMENT
START:
MOV AX,DATA
MOV DS,AX
MOV AH,2CH
INT 21H
MOV HR,CH
MOV MIN,CL
MOV SEC,DH
MOV MSEC,DL
MOV AH,09H
LEA DX,MESSAGE
INT 21H
MOV AL,HR
Vaagdevi Institute of Technology & Science, Proddatur Page 31
Dept of E.C.E MICRO PROCESSORS & MICRO CONTROLLERS LAB
AND AL,AL
AAM
MOV BX,AX
CALL DISPLAY
MOV DL,':'
MOV AH,02H
INT 21H
MOV AL,MIN
AAM
MOV BX,AX
CALL DISPLAY
MOV DL,':'
MOV AH,02H
INT 21H
MOV AL,SEC
AAM
MOV BX,AX
CALL DISPLAY
MOV DL,'.'
MOV AH,02H
INT 21H
MOV AL,MSEC
AAM
MOV BX,AX
CALL DISPLAY
MOV AH,4CH
INT 21H
DISPLAY PROC NEAR
Vaagdevi Institute of Technology & Science, Proddatur Page 32
Dept of E.C.E MICRO PROCESSORS & MICRO CONTROLLERS LAB
MOV DL,BH
ADD DL,30H
MOV AH,02H
INT 21H
MOV DL,BL
ADD DL,30H
MOV AH,02H
INT 21H
RET
DISPLAY ENDP
CODE ENDS
END START
OUTPUT:
CURRENT TIME IS: [Link]
RESULT: Assembly Language Program for designing clock using int 21h interrupt was executed
successfully.
Vaagdevi Institute of Technology & Science, Proddatur Page 33
Dept of E.C.E MICRO PROCESSORS & MICRO CONTROLLERS LAB
B. DESIGNING CLOCK USING DOS INTERRUPT FUNCTIONS.
Aim: To Write an Assembly Language Program for designing clock using DOS interrupt functions.
Apparatus:
Software: MASM (or) TERM 86E
Hardware: PC, Key Board, 8086 Trainer Kit, R.P.S
Program:
;Used INTERRUPTS
;AH=2CH //Gets the system date
;AH=02h
;For 2CH
; Hours is in CH
; Minutes is in CL
; Seconds is in DH
.MODEL SMALL
.DATA
.CODE
START: MOV AX,@DATA
MOV DS,AX
HOUR:
MOV AH,2CH
INT 21H
MOV AL,CH
AAM
MOV BX,AX
CALL DISP
MOV DL,':'
MOV AH,02H
Vaagdevi Institute of Technology & Science, Proddatur Page 34
Dept of E.C.E MICRO PROCESSORS & MICRO CONTROLLERS LAB
INT 21H
MINUTES:
MOV AH,2CH
INT 21H
MOV AL,CL
AAM
MOV BX,AX
CALL DISP
MOV DL,':'
MOV AH,02H
INT 21H
Seconds:
MOV AH,2CH
INT 21H
MOV AL,DH
AAM
MOV BX,AX
CALL DISP
MOV AH,4CH
INT 21H
DISP PROC
MOV DL,BH
ADD DL,30H
MOV AH,02H
INT 21H
MOV DL,BL
ADD DL,30H
MOV AH,02H
Vaagdevi Institute of Technology & Science, Proddatur Page 35
Dept of E.C.E MICRO PROCESSORS & MICRO CONTROLLERS LAB
INT 21H
RET
DISP ENDP
END START
(OR)
.MODEL SMALL
.STACK 100H
.DATA
PROMPT DB 'CURRENT SYSTEM TIME IS : $'
TIME DB '[Link]$'
.CODE
MAIN PROC
MOV AX, @DATA
MOV DS, AX
LEA BX, TIME
CALL GET_TIME
LEA DX, PROMPT
MOV AH, 09H
INT 21H
LEA DX, TIME
MOV AH, 09H
INT 21H
MOV AH, 4CH
INT 21H
MAIN ENDP
GET_TIME PROC
PUSH AX
PUSH CX
MOV AH, 2CH
INT 21H
Vaagdevi Institute of Technology & Science, Proddatur Page 36
Dept of E.C.E MICRO PROCESSORS & MICRO CONTROLLERS LAB
MOV AL, CH
CALL CONVERT
MOV [BX], AX
MOV AL, CL
CALL CONVERT
MOV [BX + 3], AX
MOV AL, DH
CALL CONVERT
MOV [BX + 6], AX
POP CX
POP AX
RET
GET_TIME ENDP
CONVERT PROC
PUSH DX
MOV AH, 0
MOV DL, 10
DIV DL
OR AX, 3030H
POP DX
RET
CONVERT ENDP
END MAIN
OUTPUT:
CURRENT SYSTEM TIME IS : [Link]
RESULT: An Assembly Language Program for designing clock using DOS Interrupt functions was
executed successfully.
C. DESIGNING CLOCK BY READING SYSTEM TIME
Vaagdevi Institute of Technology & Science, Proddatur Page 37
Dept of E.C.E MICRO PROCESSORS & MICRO CONTROLLERS LAB
Aim: To Write an Assembly Language Program for designing clock by reading system time.
Apparatus:
Software: MASM (or) TERM 86E
Hardware: PC, Key Board, 8086 Trainer Kit, R.P.S
Program:
.MODEL SMALL
.DATA
MSG DB 10,13,"THE CURRENT TIME IS:"
HOUR DB 2 DUP(0),':'
MIN DB 2 DUP(0),':'
SEC DB 2 DUP(0),'$'
.CODE
MOV AX,@DATA
MOV DS,AX
MOV AH,2CH
INT 21H
MOV AL,CH
AAM
ADD AX,3030H
MOV HOUR,AH
MOV HOUR+1,AL
MOV AL,CL
AAM
ADD AX,3030H
MOV MIN,AH
MOV MIN+1,AL
MOV AL,DH
AAM
Vaagdevi Institute of Technology & Science, Proddatur Page 38
Dept of E.C.E MICRO PROCESSORS & MICRO CONTROLLERS LAB
ADD AX,3030H
MOV SEC,AH
MOV SEC+1,AL
MOV AH,09H
LEA DX,MSG
INT 21H
MOV AH,4CH
INT 21H
END
(OR)
.MODEL SMALL
.DATA
MSG DB "THE TIME IS: "
HRS DB ?,?,' : '
MINS DB ?,?,' : '
SEC DB ?,?,' (HH:MM:SS) ',10,13
DB "THE DATE IS: "
DA DB ?,?, '/'
MON DB ?,?, '/'
YEA DB ?,?, '(DD/MM/YY)', 10,13,'$'
.CODE
MOV AX,@DATA
MOV DS, AX
MOV AH,2CH
INT 21H
MOV AL,CH
AAM
Vaagdevi Institute of Technology & Science, Proddatur Page 39
Dept of E.C.E MICRO PROCESSORS & MICRO CONTROLLERS LAB
ADD AX, 3030H
MOV HRS, AH
MOV HRS+1, AL
MOV AL,CL
AAM
ADD AX, 3030H
MOV MINS, AH
MOV MINS+1,AL
MOV AL,DH
AAM
ADD AX, 3030H
MOV SEC, AH
MOV SEC+1,AL
MOV AH, 2AH
INT 21H
MOV AL, DL
AAM
ADD AX,3030H
MOV DA,AH
MOV DA +1, AL
MOV AL, DH
AAM
ADD AX, 3030H
MOV MON,AH
MOV MON+1,AL
ADD CX, 0F830H
MOV AL, CL
AAM
Vaagdevi Institute of Technology & Science, Proddatur Page 40
Dept of E.C.E MICRO PROCESSORS & MICRO CONTROLLERS LAB
ADD AX, 3030H
MOV YEA,AH
MOV YEA+1,AL
LEA DX,MSG
MOV AH,09H
INT 21H
MOV AH,4CH
INT 21H
END
OUTPUT:
THE TIME IS : [Link]
THE DATE IS : 21/12/22
RESULT: An Assembly Language Program for designing clock by reading system time was
executed successfully.
Vaagdevi Institute of Technology & Science, Proddatur Page 41
Dept of E.C.E MICRO PROCESSORS & MICRO CONTROLLERS LAB
6. STEPPER MOTOR
A. ANTI-CLOCK WISE ROTATION
Aim: To Write an ALP to 8086 processor to Interface a stepper motor and operate it in Anticlockwise
by choosing variable step-size.
Apparatus:
Software: TERM 86E
Hardware: PC, Key Board, 8086 Trainer Kit, R.P.S, Stepper Motor, Study Card Kit for Stepper
motor
Program:
ADDRESS OPCODE LABEL MNEMONICS OPERANDS COMMENTS
MOV AX,0000 ;ClearAX
MOV BL,05 ;LoadCounter
MOV DX,0ffe6 ;Load DX
MOV AL,80 withCWRof8255
Setallportsaso/p
OUT DX,AL
MOV DX,0FFE0 ;Initialized
MOV AL,11 bitpattern.BitPA0-PA3
used tocontrolmotor
BACK: OUT DX,AL
CALL DELAY ;CallDelay
RCL AL,1 ;Next
patterntobesent
DEC BL ;DecCounter
JNE BACK ;Go back to
sendthenextpattern
CS ;Clearscreen
LEA DX,@2035 ;Loadmessage
MOV AX,DX
CALLS 0FE00:0013 ;NewlineRoutine
INT 03 ;End
DELAY: MOV CX,FFFF ;Delay
L1: LOOP L1
L2: LOOP L2
L3: LOOP L3
L4: LOOP L4
Vaagdevi Institute of Technology & Science, Proddatur Page 42
Dept of E.C.E MICRO PROCESSORS & MICRO CONTROLLERS LAB
L5: LO0P L5
RET
INPUT:
S2035(PressEnter)
0A,0D,53,54,45,50,43,4F,55,4E,54,20,43,4F,4D,50,4C,45,54,45,44,20,20,20,20,00
The following Program Rotates Stepper Continuously in Anti Clock Wise Direction.
ADDRESS OPCODE LABEL MNEMONICS OPERANDS COMMENTS
MOV DX,0FFE6 ;Load DX with
CWR adress of
MOV AL,80
8255 & copy 80H
OUT DX,AL into CWR to Set all
ports as output
MOV AL,88 ; Copy 88H into Register
AL
MOV DX,0FFE0 ; Copy Port A Address as
L1: OUT DX,AL FFE0 & Write 88H in to
PORT A.
MOV CX,0FFFF ; Copy 0FFFFH in to CX
Resgister.
L2: NOP ; No Operation
NOP ; No Operation
NOP ; No Operation
LOOP L2 ; Decrement CX & Jump
to Label L2 if CX is not
equal to Zero
ROL AL,1 ;Rotate Left AL Contents
by 1 time
JMP L1 ;Jump to Label L1
RESULT: An ALP to 8086 processor to Interface a stepper motor and operate it in Anti clockwise by
choosing variable step-size was executed successfully.
Vaagdevi Institute of Technology & Science, Proddatur Page 43
Dept of E.C.E MICRO PROCESSORS & MICRO CONTROLLERS LAB
B. CLOCK WISE ROTATION
Aim: To Write an ALP to 8086 processor to Interface a stepper motor and operate it in anti-clockwise
by choosing variable step-size.
Apparatus:
Software: TERM 86E
Hardware: PC, Key Board, 8086 Trainer Kit, R.P.S, Stepper Motor, Study Card Kit for Stepper
motor
Program:
ADDRESS OPCODE LABEL MNEMONICS OPERANDS COMMENTS
MOV AX,0000 ;ClearAX
MOV BL,05 ;LoadCounter
MOV DX,0ffe6 ;Load DX
MOV AL,80 withCWRof8255
Setallportsaso/p
OUT DX,AL
MOV DX,0FFE0 ;Initialized
MOV AL,11 bitpattern.BitPA0-PA3
used tocontrolmotor
BACK: OUT DX,AL
CALL DELAY ;CallDelay
RCR AL,1 ;Next
patterntobesent
DEC BL ;DecCounter
JNE BACK ;Go back to
sendthenextpattern
CS ;Clearscreen
LEA DX,@2035 ;Loadmessage
MOV AX,DX
CALLS 0FE00:0013 ;NewlineRoutine
INT 03 ;End
DELAY: MOV CX,FFFF ;Delay
L1: LOOP L1
L2: LOOP L2
L3: LOOP L3
L4: LOOP L4
L5: LO0P L5
RET
Vaagdevi Institute of Technology & Science, Proddatur Page 44
Dept of E.C.E MICRO PROCESSORS & MICRO CONTROLLERS LAB
INPUT:
S2035(PressEnter)
0A,0D,53,54,45,50,43,4F,55,4E,54,20,43,4F,4D,50,4C,45,54,45,44,20,20,20,20,00
The following Program Rotates Stepper Continuously in Clock Wise Direction.
ADDRESS OPCODE LABEL MNEMONICS OPERANDS COMMENTS
MOV DX,0FFE6 ;Load DX with
CWR adress of
MOV AL,80
8255 & copy 80H
OUT DX,AL into CWR to Set all
ports as output
MOV AL,88 ; Copy 88H into Register
AL
MOV DX,0FFE0 ; Copy Port A Address as
L1: OUT DX,AL FFE0 & Write 88H in to
PORT A.
MOV CX,0FFFF ; Copy 0FFFFH in to CX
Resgister.
L2: NOP ; No Operation
NOP ; No Operation
NOP ; No Operation
LOOP L2 ; Decrement CX & Jump
to Label L2 if CX is not
equal to Zero
ROR AL,1 ;Rotate Right AL Contents
by 1 time
JMP L1 ;Jump to Label L1
RESULT: An ALP to 8086 processor to Interface a stepper motor and operate it in Clockwise by
choosing variable step-size was executed successfully.
7. INTERFACING ADC/DAC WITH 8086
Vaagdevi Institute of Technology & Science, Proddatur Page 45
Dept of E.C.E MICRO PROCESSORS & MICRO CONTROLLERS LAB
A. ANALOG TO DIGITAL CONVERTER INTERFACING WITH 8086
Aim: To Write an ALP to 8086 processor to Interface ADC.
Apparatus:
Software: TERM 86E
Hardware: PC, Key Board, 8086 Trainer Kit, R.P.S, Study Card Kit for 16-Channel ADC
Program:
TYPE A2000 THEN PRESS ENTER
TYPE MOV AX,0000H PRESS ENTER
MOV ES,AX
MOV DX,0FFE6H
MOV AL,8BH
OUT DX,AL
JMP 202C
TYPE S200D PRESS ENTER
TYPE 0D PRESS , TYPE 43 PRESS ,
TYPE 48 PRESS , TYPE 41 PRESS ,
TYPE 4E PRESS , TYPE 4E PRESS ,
TYPE 45 PRESS , TYPE 4C PRESS ,
TYPE 20 PRESS , TYPE 4E PRESS ,
TYPE 4F PRESS , TYPE 3A PRESS ,
TYPE 20 PRESS , TYPE 00 PRESS ,
TYPE 0A PRESS , TYPE 0D PRESS ,
TYPE 44 PRESS , TYPE 49 PRESS ,
TYPE 47 PRESS , TYPE 49 PRESS ,
TYPE 54 PRESS , TYPE 41 PRESS ,
TYPE 4C PRESS , TYPE 20 PRESS ,
TYPE 56 PRESS , TYPE 41 PRESS ,
TYPE 4C PRESS , TYPE 55 PRESS ,
TYPE 45 PRESS , TYPE 3A PRESS ,
TYPE 00 PRESS ,
TYPE A202C THEN PRESS ENTER
TYPE MOV CX,00H PRESS ENTER
CALL 203A
CALL 2073
CALL 20AF
JMP 202F
MOV AL,00H
OR AL,CL
MOV DX,0FFE0H
OUT DX,AL
MOV AL,20H
OR AL,CL
OUT DX,AL
NOP
NOP
NOP
MOV AL,00H
Vaagdevi Institute of Technology & Science, Proddatur Page 46
Dept of E.C.E MICRO PROCESSORS & MICRO CONTROLLERS LAB
OR AL,CL
OUT DX,AL
MOV DX,0FFE4H
IN AL,DX
AND AL,01H
JNZ 2052
IN AL,DX
AND AL,01
JE 2057
MOV AL,40H
OR AL,CL
MOV DX,0FFE0H
OUT DX,AL
MOV DX,0FFE2H
IN AL,DX
PUSH AX
MOV AL,00H
OR AL,CL
MOV DX,0FFE0H
OUT DX,AL
POP AX
RET
CALLS 0FE00:0031H
CALLS 0FE00:01EDH
PUSH AX
LEA DX,@200D
MOV AX,DX
CALLS 0FE00:0013H
MOV AL,CL
CMP AL,0AH
JB 2092
ADD AL,06H
CALLS 0FE00:0052H
CS
LEA DX,@201B
MOV AX,DX
CALLS 0FE00:0013H
POP AX
CALLS 0FE00:0052H
CALLS 0FE00:0031H
RET
CALLS 0FE00:00A9H
CMP AL,2CH
JE 20C6
CMP AL,2DH
JE 20D0
CMP AL,0DH
JE 20DA
CMP AL,1BH
JE 20DA
JMP 20AF
INC CL
CMP CL,10H
JNE 20CF
MOV CL,00H
Vaagdevi Institute of Technology & Science, Proddatur Page 47
Dept of E.C.E MICRO PROCESSORS & MICRO CONTROLLERS LAB
RET
DEC CL
CMP CL,0FFH
JNE 20D9
MOV CL,0FH
RET
INT 03
INPUT:
RESULT: An ALP to 8086 processor to Interface ADC was executed Successfully.
Vaagdevi Institute of Technology & Science, Proddatur Page 48
Dept of E.C.E MICRO PROCESSORS & MICRO CONTROLLERS LAB
B. Interface DAC and generate Square Wave/Triangular Wave/Sine Wave
Aim: To Write an ALP to 8086 processor to Interface DAC.
Apparatus:
Software: TERM 86E
Hardware: PC, Key Board, 8086 Trainer Kit, R.P.S, Study Card Kit for DUAL DAC
SQUARE WAVE Program:
ADDRESS OPCODE LABEL MNEMONICS OPERANDS COMMENTS
MOV DX,0FFE6H ;Initialize 8255 Port A,
Port B &Port C as Output
MOV AL,80H by configuring CWR.
OUT DX,AL
L1: MOV AL,00H ; Copy 00H into AL
register
MOV DX,0FFE0H ; Write AL contents 00H
to PORTA to for –ve
OUT DX,AL square pulse(Logic Low
State)
CALL DELAY ; Call Delay Subroutine
MOV AL,0FFH ; Copy 0FFH into AL
register
OUT DX,AL ; Write AL contents 00H
to PORTA to for +ve
square pulse(Logic High
State).
CALL DELAY ; Call Delay subroutine
program
JMP L1 ;Jump to Label L1
DELAY: MOV CX,015DH ; Copy 015DH in to CX
register.
L2: NOP ;No Operation
NOP ;No Operation
LOOP L2 ;Decrement CX by 01 &
Jump to Label L2 if CX is
not equal to Zero
RET ; Return to main Program
Note: After Execution of above program, connect CRO Probe to Xout or Yout Pin on DAC, we can
view Square Wave Form on the CRO.
Vaagdevi Institute of Technology & Science, Proddatur Page 49
Dept of E.C.E MICRO PROCESSORS & MICRO CONTROLLERS LAB
TRIANGULAR WAVE Program:
ADDRESS OPCODE LABEL MNEMONICS OPERANDS COMMENTS
MOV DX,0FFE6H ;Initialize 8255 Port A,
Port B &Port C as Output
MOV AL,80H by configuring CWR.
OUT DX,AL
MOV AL,00H ; Copy 00H into AL
register
MOV DX,0FFE0H ; Write AL contents to
PORTA
L1: OUT DX,AL
INC AL ; Increment AL Contents
by 1
CMP AL,0FFH ;Compare AL with 0FFH
JNZ L1 ; Jump to Label L1 if Non
Zero or ZF=0
L2: OUT DX,AL ;Write AL Contents to Port A
DEC AL ; Decrement AL Contents
by 1
JNZ L2 ; Jump to Label L2 if Non
Zero or ZF=0
JMP L1 ;Jump to Label L1
Note: After Execution of above program, connect CRO Probe to Xout or Yout Pin on DAC, we can
view Triangular Wave Form on the CRO.
SAWTOOTH WAVE Program:
ADDRESS OPCODE LABEL MNEMONICS OPERANDS COMMENTS
MOV DX,0FFE6H ;Initialize 8255 Port A,
Port B &Port C as Output
MOV AL,80H by configuring CWR.
OUT DX,AL
MOV AL,00H ; Copy 00H into AL
register
MOV DX,0FFE0H ; Write AL contents to
PORTA
L1: OUT DX,AL
INC AL ; Increment AL Contents
by 1
Vaagdevi Institute of Technology & Science, Proddatur Page 50
Dept of E.C.E MICRO PROCESSORS & MICRO CONTROLLERS LAB
CMP AL,0FFH ;Compare AL with 0FFH
JNZ L1 ; Jump to Label L1 if Non
Zero or ZF=0
MOV AL,00 ; Copy 00H into AL
register
JMP L1 ;Jump to Label L1
Note: After Execution of above program, connect CRO Probe to Xout or Yout Pin on DAC, we can
view SAWTOOTH Wave Form on the CRO.
SINE WAVE PROGRAM: (Vout = 25.6(5 + 5*Sin θ) )
ADDRESS OPCODE LABEL MNEMONICS OPERANDS COMMENTS
MOV AL,80H ;Initialize 8255 Port A,
Port B &Port C as Output
MOV DX,0FFE6 by configuring CWR.
OUT DX,AL
AGAIN: MOV CL,18H ; Copy 18H into CL
register
MOV SI,3000 ; Copy 3000H into SI
Register.
MOV DX,0FFE0H ; Write AL contents to
PORTA
BACK: MOV AL,[SI]
OUT DX,AL ; Increment AL Contents
by 1
INC SI ;Increment SI Contents by
01.
LOOP BACK ; Decrement CL & Jump
to Label Back if CL is non
Zero
JMP L1 ;Jump to Label L1
Substitute θ = 0o in above formula & increment θ by 15 Degrees to get different values of Vout &
convert the Vout into Hexa decimal, then we will obtain the values given below. After entering the
above program , type “S 3000” & enter the following data.
3000: 80,A1,C0,DA,EF,FC
3006: FF,FC,EF,DA,C0,A1
300C: 80,5F,40,26,11,04
Vaagdevi Institute of Technology & Science, Proddatur Page 51
Dept of E.C.E MICRO PROCESSORS & MICRO CONTROLLERS LAB
3012: 00,04,11,26,40,5F,80
After entering the above data in 3000H memory location, press reset button on the Kit. Execute the
program by giving the command “GO 2000” & Hit enter button on the Keyboard, & verify the output
on CRO, by connecting CRO Probe to Xout Pin DAC Kit.
OUTPUT:
Measure the Amplitude, time period of Square Wave, Triangular Wave & Sine Wave form displayed
on CRO & Plot the Graph.
RESULT: An ALP to 8086 processor to Interface DAC and generate Square wave & triangular wave
was executed successfully.
Vaagdevi Institute of Technology & Science, Proddatur Page 52
Dept of E.C.E MICRO PROCESSORS & MICRO CONTROLLERS LAB
; Assume the interface is connected over J4 of trainer
; This program generates a Square or Triangular wave at Xout or Yout
; The program can be executed in Stand alone or Serial mode
; Execute the program from memory location 2000H
ORG 2000H
MOV AX,0000H
MOV CS,AX
MOV ES,AX
MOV DX,0FFE6H ;Initialise all 8255
MOV AL,80H ;ports as O/P ports
OUT DX,AL
CALL FAR 0FE00:01EDH ;newline routine
JMP SHORT START ;display message string
MES: DB 0AH, 0DH, 'DUAL DAC INTERFACE '
DB 0AH, 0DH, 'S - SQUARE WAVE'
DB 0AH, 0DH, 'T - TRIAGLUAR WAVE', 0H
START: LEA DX,MES ;display message on LCD
MOV AX,DX ;or console
CALL FAR 0FE00:0013H
GETKEY: CALL FAR 0FE00:00A9H ;wait fo user entry
CMP AL,53H ;if S,jump to square
JE SQUARE ;wave routine
CMP AL,54H ;if T, jump to triangle
JE TRIANGLE ;wave routine
JMP SHORT GETKEY ;wait for valid key
;Triangular wave generation routine
TRIANGLE: CALL FAR 0FE00:0031H
RPT1: MOV CX,0FFH ;set count
Vaagdevi Institute of Technology & Science, Proddatur Page 53
Dept of E.C.E MICRO PROCESSORS & MICRO CONTROLLERS LAB
MOV AL,00H ;start from 0
UP: INC AL ;increment data for
MOV DX,0FFE0H ; +ive going slope and
OUT DX,AL ;output at port A & B
MOV DX,0FFE2H
OUT DX,AL
LOOP UP
MOV CX,0FFH ;set count
MOV AX,CX ;start from FFh
DOWN: DEC AL ;decrement data for
MOV DX,0FFE0H ;-ive going slope at
OUT DX,AL ;port A & B
MOV DX,0FFE2H
OUT DX,AL
LOOP DOWN
JMP SHORT RPT1 ;repeat continuously
SQUARE: CALL FAR 0FE00:0031H
RPT2: MOV AL,0FFH ;O/P FFh at ports
MOV DX,0FFE0H
OUT DX,AL
MOV DX,0FFE2H
OUT DX,AL
MOV CX,FFH ;delay
DLY1: LOOP DLY1
MOV AL,00H ;O/P 0 at ports
MOV DX,0FFE0H
OUT DX,AL
MOV DX,0FFE2H
Vaagdevi Institute of Technology & Science, Proddatur Page 54
Dept of E.C.E MICRO PROCESSORS & MICRO CONTROLLERS LAB
OUT DX,AL
MOV CX,FFH
DLY2: LOOP DLY2 ;delay
JMP SHORT RPT2 ;repeat continuously
END
RESULT: An ALP to 8086 processor to Interface DAC & generate a Square wave , triangular wave,
& Sine Wave was executed successfully.
Vaagdevi Institute of Technology & Science, Proddatur Page 55
Dept of E.C.E MICRO PROCESSORS & MICRO CONTROLLERS LAB
8. COMMUNICATION BETWEEN TWO
MICROPROCESSORS
A. PARELL COMMUNICATION BETWEEN TWO MICRO PROCESSOR KITS
USING 8255
Aim: To Write an ALP to have Parallel communication between two microprocessors using 8255
Apparatus:
Software: TERM 86E
Hardware: PC, Key Board, 8086 Trainer Kit-2, R.P.S, FRCS Cable
Program:
TRANSMITTER:
ADDRESS OPCODE LABEL MNEMONICS OPERANDS COMMENTS
MOV DX,0FFE6H ;Initialize 8255 Port A,
Port B&Port C as Output by
MOV AL,80H configuring CWR.
OUT DX,AL
MOV AX,0000H ; Copy 0000H into AX
register
MOV AL,55H ;Send 55H to PortA
MOV DX,0FFE0H
OUT DX,AL
MOV AL,66H ;Send 66H to PortB
MOV DX,0FFE2H
OUT DX,AL
MOV AL,0CCH ;Send CCH to PortC
MOV DX,0FFE4H
OUT DX,AL
INT 03H ; Break Point Interrupt
Note: Enter the above program in 8086 Micro Processor Kit-1 from Memory Location 2000H.
Vaagdevi Institute of Technology & Science, Proddatur Page 56
Dept of E.C.E MICRO PROCESSORS & MICRO CONTROLLERS LAB
RECEIVER:
ADDRESS OPCODE LABEL MNEMONICS OPERANDS COMMENTS
MOV DX,0FFE6H ; Initialize 8255 Port A
MOV AL,9BH Port B&Port C as input by
OUT DX,AL configuring CWR.
MOV AX,0000H ; Copy 0000H into AX
Register
MOV SI,2050H ;Copy 2050H into SI
Register
MOV DX,0FFE0H ;Read Data from PortA
IN AL,DX
MOV [SI],AL ;Save it in 2050H
MOV DX,0FFE2H ;Read Data from PortB
IN AL,DX
INC SI ;Increment SI Contents by
01
MOV [SI],AL ;Save it in 2051H
MOV DX,0FFE4H ;Read Data from PortC
IN AL,DX
INC SI ;Increment SI Contents by
01
MOV [SI],AL ;Save it in 2052H
INT 03 ; Break Point Interrupt
Note: Enter the above program in 8086 Micro Pocessor Kit-2 from Memory Location 2000H.
After entering the transmitter & receiver programs in Kit-1 & Kit-2 Respectively,Press Reset Button on Kits.
First execute Transmitter Program in Kit-1 by using command “Go 2000” & then execute Receiver Program in Kit-2
by using command “Go 2000”. Now Press Reset Button on Receiver Kit & type “S 2050” to check the ouput in
Receiver Kit.
INTPUT: TRANSMITTER KIT
PORT A = 55H
PORT B = 66H
PORT C = CCH
OUTPUT: RECEIVER KIT
[2050] = 55H
[2051] = 66H
[2052] = CCH
RESULT: An ALP to have Parallel communication between two microprocessors using 8255 was
executed successfully.
B. SERIAL COMMUNICATION BETWEEN TWO 8086 KITS
Vaagdevi Institute of Technology & Science, Proddatur Page 57
Dept of E.C.E MICRO PROCESSORS & MICRO CONTROLLERS LAB
Aim: To Write an ALP to have Serial communication between two microprocessors using 8251.
Apparatus:
Software: TERM 86E
Hardware: PC, Key Board, 8086 Trainer Kit-2, R.P.S, FRCS Cable, RS 232-Cable
Program:
TRANSMITTER:
ORG 2000H
MOV AL,36H ;Initilize Timer 0
MOV DX,0FFFFH
OUT DX,AL ;for mode3 operation
MOV DX,0FFF9H
MOV AL,0AH ;Load Timer0 Count
OUT DX,AL ;For 9600 baudrate
MOV AL,00H
OUT DX,AL
MOV SP,3000H
MOV DX,0FFF2H
OUT DX,AL
OUT DX,AL ;Reset 8251
OUT DX,AL
OUT DX,AL
CALL DELAY
MOV AL,40H ;Initialize 8251
OUT DX,AL ;for Asyncronous
CALL DELAY ;16xBaud,8 data bits,no parity
MOV AL,0CEH
OUT DX,AL
CALL DELAY
MOV AL,23H ;Test for DTR,RTS&
OUT DX,AL ;TxEN
CALL DELAY
MOV SI,2100H
AGAIN: MOV DX,0FFF2H ;Get USART status
IN AL,DX ;for Transmitter
AND AL,81H ;ready & DSR active
CMP AL,81H
JNE AGAIN ;If yes,Transmit
MOV AL,[SI] ;stored character
INC SI
CMP AL,00H
JE OVER
MOV DX,0FFF0H
OUT DX,AL
Vaagdevi Institute of Technology & Science, Proddatur Page 58
Dept of E.C.E MICRO PROCESSORS & MICRO CONTROLLERS LAB
JMP AGAIN
OVER: INT 03H
DELAY: MOV CX,02H
L1: LOOP L1
RET
ORG 2100H
DB 'HELLO WORLD' ,00H
END
Note: Enter the above program in 8086 Micro Pocessor Kit-1 from Memory Location 2000H.
RECEIVER:
ORG 3000H
MOV AL,36H ;Initilize Timer 0
MOV DX,0FFFFH ;for mode3 operation
OUT DX,AL
MOV DX,0FFF9H
MOV AL,0AH ;Load Timer0 Count
OUT DX,AL ;For 9600 baudrate
MOV AL,00H
OUT DX,AL
MOV SP,3000H
MOV DX,0FFF2H
OUT DX,AL ;Reset 8251
OUT DX,AL
OUT DX,AL
OUT DX,AL
CALL DELAY
MOV AL,40H ;Initialize 8251
OUT DX,AL ;for Asyncronous
CALL DELAY
MOV AL,0CEH ;16xBaud,8 data bits,no parity
OUT DX,AL
CALL DELAY
MOV AL,27H
OUT DX,AL
CALL DELAY
MOV SI,3100H ;Initialize Memort to
AGAIN: MOV DX,0FFF2H ;store characters
IN AL,DX ;Get USART status
AND AL,02H ;Receiver ready?
JE AGAIN ;No,wait
MOV DX,0FFF0H ;Yes,get character from USART
IN AL,DX
CMP AL,1BH ;If char=<Esc>
MOV BL,AL
JE OVER ;Exit
Vaagdevi Institute of Technology & Science, Proddatur Page 59
Dept of E.C.E MICRO PROCESSORS & MICRO CONTROLLERS LAB
MOV AL,BL ;Send same char
MOV DX,0FFF0H ;to USART
OUT DX,AL
MOV [SI],AL
INC SI
JMP AGAIN
OUT DX,AL
INC SI
JMP AGAIN
OVER: INT 03H
DELAY:MOV CX,02H
HERE: LOOP HERE
RET
END
Note: Enter the above program in 8086 Micro Pocessor Kit-2 from Memory Location 3000H.
Connect two Micro processor Kits by using RS-232 Male to Male Connector.
After entering the transmitter & receiver programs in Kit-1 & Kit-2 Respectively,Press Reset Button on Kits. First
execute Receiver Program in Kit-2 by using command “Go 3000” & then execute Transmitter Program in Kit-1 by
using command “Go 2000”. Now Press Reset Button on Receiver Kit & type “D2100,210A” to check the output in
Receiver Kit.
OUTPUT: IN RECEIVER KIT
“HELLO WORLD”
[2100] = 48 = H
[2101] = 45 = E
[2102] = 4C = L
[2103] = 4C = L
[2104] = 4F = O
[2106] = 57 = W
[2107] = 4F = O
[2108] = 52 = R
[2109] = 4C = L
[210A] = 44 = D
RESULT: An ALP to have Serial communication between two microprocessors using 8251 was
executed successfully.
Vaagdevi Institute of Technology & Science, Proddatur Page 60
Dept of E.C.E MICRO PROCESSORS & MICRO CONTROLLERS LAB
9. PROGRAMS USING ARITHMETIC AND LOGICAL
INSTRUCTIONS FOR 8051
A. 8-BIT ADDITION & SUBTRACTION
AIM: To Perform 8-bit addition & subtraction using 8051Micro Controller
APPARATUS:
Software: Keil u Vision / Term51E
Hardware: 8051 Micro Controller Trainer Kit, R.P.S, Key Board
ADDITION ALGORITHM:
1. Start.
2. Copy the immediate data 45H in to A Register.
3. Copy the immediate data 38H in to B Register.
4. Add the Contents of Register A, B & Update the RESULT in A register.
5. Stop.
ADDITION PROGRAM:
ADDRESS OPCODE LABEL MNEMONICS OPERANDS COMMENTS
ORG 0000H
MOV A,#45H ;Move Data 45H into Register A
MOV B,#38H ;Move Data 38H into Register B
ADD A,B ;Add the contents of Register B
to A & Update the RESULT in A
HERE: SJMP HERE ;Short Jump to Label Here
END ;End of Program
INPUT: A = 45H, B = 38H
OUTPUT:A = 7DH
SUBTRACTION ALGORITHM:
1. Start.
2. Copy the immediate data 48H in to A Register.
3. Copy the immediate data 33H in to B Register.
4. Add the Contents of Register A, B & Update the RESULT in A register.
5. Stop.
Vaagdevi Institute of Technology & Science, Proddatur Page 61
Dept of E.C.E MICRO PROCESSORS & MICRO CONTROLLERS LAB
SUBTRACTION PROGRAM:
ADDRESS OPCODE LABEL MNEMONICS OPERANDS COMMENTS
ORG 0000H
MOV A,#48H ;Move Data 48H into Register A
MOV B,#33H ;Move Data 33H into Register B
SUBB A,B ;Subtract the contents of Register
B to A & Update the RESULT in
A
HERE: SJMP HERE ;Short Jump to Label Here
END ;End of Program
INPUT: A = 48H, B = 33H
OUTPUT: A = 15H
RESULT:Assembly Language Program to Perform 8-bit addition & subtraction using 8051Micro
Controller was successfully executed.
Vaagdevi Institute of Technology & Science, Proddatur Page 62
Dept of E.C.E MICRO PROCESSORS & MICRO CONTROLLERS LAB
B. 8-BIT MULTIPLICATION & DIVISION
AIM: To Perform 8-bit Multiplication & Division using 8051Micro Controller.
APPARATUS:
Software: Keil u Vision / Term51E
Hardware: 8051 Micro Controller Trainer Kit, R.P.S, Key Board
ALGORITHM:
1. Start.
2. Copy the immediate data 48H in to A Register.
3. Copy the immediate data 33H in to B Register.
4. Multiply the Contents of Register A, B & Update the RESULT in B-A register.
5. Stop.
PROGRAM:
ADDRESS OPCODE LABEL MNEMONICS OPERANDS COMMENTS
ORG 0000H
MOV A,#48H ;Move Data 48H into Register A
MOV B,#33H ;Move Data 33H into Register B
MUL AB ;Multiply the contents of Register
A with B & Update the RESULT
Lower Byte in A & Upper Byte
in B
HERE: SJMP HERE ;Short Jump to Label Here
END ;End of Program
INPUT: A=48H, B=33H
OUTPUT: B= 0EH, A=58H (MULTIPLICATION OF 45*33 = 0E58H)
Vaagdevi Institute of Technology & Science, Proddatur Page 63
Dept of E.C.E MICRO PROCESSORS & MICRO CONTROLLERS LAB
DIVISION ALGORITHM:
1. Start.
2. Copy the immediate data 48H in to A Register.
3. Copy the immediate data 33H in to B Register.
4. Divide the Contents of Register A with B & Update the RESULT in A(Quotient)& B
(Remainder) .
5. Stop.
DIVISION PROGRAM:
ADDRESS OPCODE LABEL MNEMONICS OPERANDS COMMENTS
ORG 0000H
MOV A,#48H ;Move Data 48H into Register A
MOV B,#33H ;Move Data 33H into Register B
DIV AB ;Multiply the contents of Register
A with B & Update the RESULT
Quotient in A & Remainder in B
HERE: SJMP HERE ;Short Jump to Label Here
END ;End of Program
INPUT : A=48H,B=33H
OUTPUT: B=15H(REMAINDER), A= 01H(QUOTIENT)
RESULT: Assembly Language Program to Perform 8-bit Multiplication & Division using
8051Micro Controller was successfully executed.
C. LOGICAL OPERATIONS USING 8051 (AND, OR, XOR)
Vaagdevi Institute of Technology & Science, Proddatur Page 64
Dept of E.C.E MICRO PROCESSORS & MICRO CONTROLLERS LAB
AIM: To Perform Logical AND, OR, XOR Operations using 8051Micro Controller
APPARATUS:
Software: Keil u Vision / Term51E
Hardware: 8051 Micro Controller Trainer Kit, R.P.S, Key Board
AND Operation Algorithm:
1. Start.
2. Copy the immediate data 45H in to A Register.
3. Copy the immediate data 23H in to B Register.
4. Perform AND Operation between the Contents of Register A, R0 & Update the RESULT in
A register.
5. Stop.
AND OPERATION PROGRAM:
ADDRESS OPCODE LABEL MNEMONICS OPERANDS COMMENTS
ORG 0000H
MOV A,#45H Move Data 45H into Register A
MOV R0,#23H Move Data 23H into Register B
ANL A,R0 Perform AND operation between
Contents of Register A & R0 &
Update the RESULT in A.
HERE: SJMP HERE Short Jump to Label Here
END End of Program
INPUT: A=45H, R0=23H
OUTPUT: A= 01H
OR OPERATION ALGORITHM :
1. Start.
2. Copy the immediate data 45H in to A Register.
3. Copy the immediate data 23H in to B Register.
4. Perform OR Operation between the Contents of Register A, R0 & Update the RESULT in
A register.
5. Stop.
OR OPERATION PROGRAM:
Vaagdevi Institute of Technology & Science, Proddatur Page 65
Dept of E.C.E MICRO PROCESSORS & MICRO CONTROLLERS LAB
ADDRESS OPCODE LABEL MNEMONICS OPERANDS COMMENTS
ORG 0000H
MOV A,#45H ;Move Data 45H into Register A
MOV R0,#23H ;Move Data 23H into Register B
ORL A,R0 ;Perform OR operation between
Contents of Register A & R0 &
Update the RESULT in A.
HERE: SJMP HERE ;Short Jump to Label Here
END ;End of Program
INPUT: A = 45H, R0 = 23H
OUTPUT:A = 67H
XOR OPERATION ALGORITHM:
1. Start.
2. Copy the immediate data 45H in to A Register.
3. Copy the immediate data 23H in to B Register.
4. Perform XOR Operation between the Contents of Register A, R0 & Update the RESULT in
A register.
5. Stop.
XOR OPERATION PROGRAM:
ADDRESS OPCODE LABEL MNEMONICS OPERANDS COMMENTS
ORG 0000H
MOV A,#45H ;Move Data 45H into Register A
MOV R0,#23H ;Move Data 23H into Register B
XRL A,R0 ;Perform XOR operation between
Contents of Register A & R0 &
Update the RESULT in A.
HERE: SJMP HERE ;Short Jump to Label Here
END ;End of Program
INPUT: A=45H, R0=23H
Vaagdevi Institute of Technology & Science, Proddatur Page 66
Dept of E.C.E MICRO PROCESSORS & MICRO CONTROLLERS LAB
OUTPUT: A= 66H
RESULT: Assembly Language Program to Perform Logical AND, OR & XOR operations using
8051Micro Controller was successfully executed.
Vaagdevi Institute of Technology & Science, Proddatur Page 67
Dept of E.C.E MICRO PROCESSORS & MICRO CONTROLLERS LAB
D. PROGRAMS RELATED TO REGISTER BANKS
AIM: To Write a program to copy transfer data in to various register banks.
APPARATUS:
Software: Keil u Vision / Term51E
Hardware: 8051 Micro Controller Trainer Kit, R.P.S, Key Board
PROGRAM TO STORE DATA IN REGISTERS R0 & R1 OF BANK2:
ADDRESS OPCODE LABEL MNEMONICS OPERANDS COMMENTS
ORG 0000H
MOV A,#99H ;Move Data 99H into Register A
MOV B,#85H ;Move Data 85H into Register B
SETB PSW.4 ;Set RS1=1, to select Bank2 in
8051
MOV R0,A ;Copy the contents of
Accumulator into R0
MOV R1,B ;Copy the contents of B Register
into R1
HERE: SJMP HERE ;Short Jump to Label Here
END ;End of Program
INPUT: A=99H, B= 85H
OUTPUT: R0 = [0010] = 99H
R1 = [0011] = 85H
PROGRAM TO STORE DATA IN REGISTERS R0 & R1 OF BANK3:
ADDRESS OPCODE LABEL MNEMONICS OPERANDS COMMENTS
ORG 0000H
MOV A,#99H ;Move Data 99H into Register A
MOV B,#85H ;Move Data 85H into Register B
SETB PSW.4 ;Set RS1=1, RS1=1 to select
Vaagdevi Institute of Technology & Science, Proddatur Page 68
Dept of E.C.E MICRO PROCESSORS & MICRO CONTROLLERS LAB
SETB PSW.3 Bank 3 in 8051
MOV R0,A ;Copy the contents of
Accumulator into R0
MOV R1,B ;Copy the contents of B Register
into R1
HERE: SJMP HERE ;Short Jump to Label Here
END ;End of Program
INPUT: A=99H, B= 85H
OUTPUT: R0 = [0018] = 99H
R1 = [0019] = 85H
RESULT: Assembly Language Program to copy data in to various register banks was executed
successfully.
10. PROGRAM TO VERIFY TIMERS/COUNTERS OF 8051
Vaagdevi Institute of Technology & Science, Proddatur Page 69
Dept of E.C.E MICRO PROCESSORS & MICRO CONTROLLERS LAB
AIM: Write a program to create various delays using Timer 0 & Timer 1 in different modes.
APPARATUS:
Software: Keil u Vision / Term51E
Hardware: 8051 Micro Controller Trainer Kit, R.P.S, Key Board
a) Write a program to create a delay of 25msec using Timer0 in mode 1 and blink all the Pins of
P0.
ORG 0000H
AGAIN:MOV P0,#0FFH
ACALL DELAY
MOV P0,#00H ;
ACALL DELAY
SJMP AGAIN ;
ORG 300H
DELAY:
MOV TMOD,#01 ;Timer 0, 16-bitmode
MOV TL0,#0FFH ;TL0=FF, low byte of timer
MOV TH0,#0A5H ;TH0=A5, the high byte
SETB TR0 ;Start timer 0
BACK: JNB TF0,BACK ;until timer rolls over
CLR TR0 ;Stop the timer 0
CLR TF0 ;Clear timer 0 flag
RET
END
(OR)
ORG 0000H
MOV TMOD,#01H ;Timer 0, 16-bitmode
AGAIN:MOV TL0,#0FFH
MOV TH0,#0A5H
MOV P0,#0FFH
ACALL DELAY
MOV TL0,#0FFH
MOV TH0,#0A5H
MOV P0,#00H
ACALL DELAY
SJMP AGAIN
ORG 300H
DELAY:SETB TR0 ;Start timer 0
BACK: JNB TF0,BACK ;until timer rolls over
CLR TR0 ;Stop the timer 0
CLR TF0 ;Clear timer 0 flag
RET
END
Vaagdevi Institute of Technology & Science, Proddatur Page 70
Dept of E.C.E MICRO PROCESSORS & MICRO CONTROLLERS LAB
(or)
ORG 0000H
MOV TMOD,#01H ;Timer 0, 16-bitmode
AGAIN:MOV TL0,#0FFH ;TL0=FF, low byte MOV TH0,#0A5H ;TH0=A5, the high byte
MOV P0,#0FFH
ACALL DELAY
MOV TL0,#0FFH ;TL0=FF, low byte of timer
MOV TH0,#0A5H ;
MOV P0,#00H ;
ACALL DELAY
SJMP AGAIN ;
ORG 300H
DELAY:SETB TR0 ;Start timer 0
BACK: JNB TF0,BACK ;until timer rolls over
CLR TR0 ;Stop the timer 0
CLR TF0 ;Clear timer 0 flag
RET
END
(OR)
ORG 0000H
AGAIN: MOV TMOD,#01 ;Timer 0,16-bitmode
MOV TL0,#0FFH ;TL1=FF, low byte of timer
MOV TH0,#0A5H ;TH1=A5, the high byte
MOV P0,#0FFH
SETB TR0 ;Start timer 0
BACK: JNB TF0,BACK ;until timer rolls over
MOV P0,#00H ;
CLR TR0 ;Stop the timer 0
CLR TF0 ;Clear timer 0 flag
SJMP AGAIN ;Reload timer
END
b)Write a program to create a delay of 50 µsec using Timer1 in mode 0 and blink all the Pins of
P2.
ORG 0000H
MOV TMOD,#00H ;Timer 1, 13-bitmode
AGAIN:MOV TL1,#12H
MOV TH1,#0FEH ;TH1=FEH, the high byte
MOV P2,#0FFH
ACALL DELAY
MOV TL1,#12H ;
MOV TH1,#0FEH ;
Vaagdevi Institute of Technology & Science, Proddatur Page 71
Dept of E.C.E MICRO PROCESSORS & MICRO CONTROLLERS LAB
MOV P2,#00H ;
ACALL DELAY
SJMP AGAIN ;
ORG 300H
DELAY:SETB TR1 ;Start timer 1
BACK: JNB TF1,BACK ;until timer rolls over
CLR TR1 ;Stop the timer 1
CLR TF1 ;Clear timer 1 flag
RET
END
c)Write a program to create a delay of 75msec using counter0 in mode 2 and blink all the Pins
of P1.
ORG 0000H
MOV TMOD,#02H ;Timer 0,8-bit AUTO RELOAD mode
AGAIN: MOV P1,#0FFH
ACALL DELAY
ACALL DELAY
MOV P1,#00H ;
ACALL DELAY
ACALL DELAY
SJMP AGAIN ;
ORG 300H
DELAY:MOV R0,#86H
UP:MOV TH0,#00H ;
SETB TR0 ;Start timer 0
BACK: JNB TF0,BACK ;until timer rolls over
CLR TR0 ;Stop the timer 0
CLR TF0 ;Clear timer 0 flag
DJNZ R0,UP
RET
END
d) Write a program to create a delay of 80 µsec using counter1 in mode 1 and blink all the Pins
of P3.
ORG 0000H
MOV TMOD,#10H ;Timer 1, 16-BIT MODE-1
AGAIN:MOV TL1,#0B6H ;TL1=0B6H, low byte of timer
MOV TH1,#0FFH ;TH1=FFH, the high byte
MOV P3,#0FFH
ACALL DELAY
MOV TL1,#0B6H ;TL1=0B6H, low byte of timer
MOV TH1,#0FFH ;TH1=FFH, the high byte
MOV P3,#00H ;
ACALL DELAY
SJMP AGAIN ;
Vaagdevi Institute of Technology & Science, Proddatur Page 72
Dept of E.C.E MICRO PROCESSORS & MICRO CONTROLLERS LAB
ORG 300H
DELAY:SETB TR1 ;Start timer 1
BACK: JNB TF1,BACK ;until timer rolls over
CLR TR1 ;Stop the timer 1
CLR TF1 ;Clear timer 1 flag
RET
END
Note: To check the output of timers in Keil uvision, open peripherals & then select timer0 or timer1
& then open peripherals & then Select the port you want to check the delay.
To view the output wave form, open logic analyser & add the port number in settings.
RESULT: The Operations of 8051 Timers in different modes of was verifed successfully.
Vaagdevi Institute of Technology & Science, Proddatur Page 73
Dept of E.C.E MICRO PROCESSORS & MICRO CONTROLLERS LAB
11. UART OPERATION IN 8051
A. Transfer a character serially with a baud rate of 9600
AIM: To Write a program to transfer a character serially with a baud rate of 9600 using
UART.
APPARATUS:
Software: Keil u Vision / Term51E
Hardware: 8051 Micro Controller Trainer Kit, R.P.S, Key Board
PROGRAM:
ADDRESS OPCODE LABEL MNEMONICS OPERANDS COMMENTS
ORG 0000H
MOV TMOD,#20H ;timer 1,mode 2(auto reload)
MOV TH1,#-3 ;9600 baud rate
MOV SCON,#50H ;8-bit, 1 stop, REN enabled
SETB TR1 ;start timer 1
AGAIN: MOV SBUF,#'A' ;letter “A” to transfer
HERE: JNB TI,HERE ;wait for the last bit
CLR TI ;clear TI for next char
SJMP AGAIN ;keep sending A
END
Note: To check the output click peripherals & select serial window, observe the Baud Rate. Now
Open serial window in keil u vision & verify that the character A is Transmitting continuously.
RESULT: Assembly Language program to transfer a character serially with a baud rate of 9600
using UART was successfully executed.
Vaagdevi Institute of Technology & Science, Proddatur Page 74
Dept of E.C.E MICRO PROCESSORS & MICRO CONTROLLERS LAB
B. Transfer a character serially with a baud rate of 4800
AIM: To Write a program to transfer a character serially with a baud rate of 4800 using
UART.
APPARATUS:
Software: Keil u Vision / Term51E
Hardware: 8051 Micro Controller Trainer Kit, R.P.S, Key Board
PROGRAM:
ADDRESS OPCODE LABEL MNEMONICS OPERANDS COMMENTS
ORG 0000H
MOV TMOD,#20H ;timer 1,mode 2(auto reload)
MOV TH1,#-6 ;4800 baud rate
MOV SCON,#50H ;8-bit, 1 stop, REN enabled
SETB TR1 ;start timer 1
AGAIN: MOV SBUF,#'A' ;letter “A” to transfer
HERE: JNB TI,HERE ;wait for the last bit
CLR TI ;clear TI for next char
SJMP AGAIN ;keep sending A
END
Note: To check the output click peripherals & select serial window, observe the Baud Rate. Now
Open serial window in keil u vision & verify that the character A is Transmitting continuously.
RESULT:Assembly Language program to transfer a character serially with a baud rate of 4800 using
UART was successfully executed.
C. Transfer a character serially with a baud rate of 2400
Vaagdevi Institute of Technology & Science, Proddatur Page 75
Dept of E.C.E MICRO PROCESSORS & MICRO CONTROLLERS LAB
AIM: To Write a program to transfer a character serially with a baud rate of 2400 using
UART.
APPARATUS:
Software: Keil u Vision / Term51E
Hardware: 8051 Micro Controller Trainer Kit, R.P.S, Key Board
PROGRAM:
ADDRESS OPCODE LABEL MNEMONICS OPERANDS COMMENTS
ORG 0000H
MOV TMOD,#20H ;timer 1,mode 2(auto reload)
MOV TH1,#-12 ;2400 baud rate
MOV SCON,#50H ;8-bit, 1 stop, REN enabled
SETB TR1 ;start timer 1
AGAIN: MOV SBUF,#'A' ;letter “A” to transfer
HERE: JNB TI,HERE ;wait for the last bit
CLR TI ;clear TI for next char
SJMP AGAIN ;keep sending A
END
Note: To check the output click peripherals & select serial window, observe the Baud Rate. Now
Open serial window in keil u vision & verify that the character A is Transmitting continuously.
RESULT:Assembly Language program to transfer a character serially with a baud rate of 2400 using
UART was successfully executed.
Vaagdevi Institute of Technology & Science, Proddatur Page 76
Dept of E.C.E MICRO PROCESSORS & MICRO CONTROLLERS LAB
12. INTERFACING LCD WITH 8051
A. Interface16*2 LCD to 8051(Read from Key Board& display on LCD)
AIM: To Develop and execute the program to interface16*2 LCD to 8051.
APPARATUS:
Software: Keil u Vision / Term51E
Hardware: 8051 Micro Controller Trainer Kit, R.P.S, Key Board
PROGRAM:
CMD_PORT EQU 03H
PORT_A EQU 00H
PORT_B EQU 01H
GETKB EQU 142H
GETCH EQU 12A5H
ORG 8000H
ACALL INIT ;CALL LCD INITIALIZE
;SUBROUTINE
MOV A,#80H ;ADDRESS FOR FIRST LINE
CALL CMD ;DISPLAY THE MESSAGE WAITING
MOV DPTR,#DISP1 ;
MOV R3,#08H
CALL STRING
MOV A,#0C0H ;ADDRESS FOR SECOND LINE
CALL CMD ;DISPLAY THE MESSAGE FOR KEY
MOV DPTR,#DISP2
MOV R3,#08H
CALL STRING
START: MOV R6,#80H ;CHECK SERIAL OR
MOV DPTR,#0E102H ;KB MODE OF OPERATION
MOVX A,@DPTR
JB ACC.3,KBD
; CLR P3.4
CALL GETCH ;CHECK ANY KEY PRESSED
SJMP DISP
KBD: CALL GETKB
DISP: PUSH A
MOV A,#01H ;CLEAR DISPLAY AND
CALL CMD ;BRING THE CURSOR TO
;HOME POSITION
MOV A,#80H ;ADDRESS FOR FIRST LINE
CALL CMD
POP A
CALL DWR ;DISPLAY THE KEY
DELAY2: MOV R3,#01H
L1: MOV R1,#0FFH
CALL DELAY
Vaagdevi Institute of Technology & Science, Proddatur Page 77
Dept of E.C.E MICRO PROCESSORS & MICRO CONTROLLERS LAB
DJNZ R3,L1
MOV A,#0C0H
CALL CMD
MOV DPTR,#MESS
MOV R3,#08H
CALL STRING
MOV A,#02H
CALL CMD
JMP START
INIT: MOV A,#80H ;CONFIGURE PA,PB,PC AS O/P PORTS
MOV P2,#0E8H
MOV R0,#03H
MOVX @R0,A
MOV R1,#1FH
CALL DELAY
MOV R3,#03H ;SEND SOFTWARE RESER 3 TIMES
INIT1: MOV A,#38H ;TO RESET THE DISPLAY
CALL CMD
MOV R1,#3FH
CALL DELAY
DJNZ R3,INIT1
MOV A,#38H ;FUNCTION SET 8BIT,1 LINE
CALL CMD ;5*7 FONT
MOV A,#0CH ;DISPLAY ON/OFF CONTROL
CALL CMD ;DISP ON,CURSOR OFF,BLINK OFF
MOV A,#01H ;CLEAR DISPLAY
CALL CMD
RET
;COMMAND WRITE SUBROUTINE
CMD: MOV P2,#0E8H
MOV R0,#PORT_A
MOVX @R0,A
MOV A,#0FBH
MOV R0,#PORT_B
MOVX @R0,A
MOV A,#0F8H
MOV R0,#PORT_B
MOVX @R0,A
MOV A,#0FCH
MOV R0,#PORT_B
MOVX @R0,A
MOV A,#0F8H
MOV R0,#PORT_B
MOVX @R0,A
MOV R1,#10H
CALL DELAY
RET
;DATE WRITE SUBROUTINE
DWR: MOV P2,#0E8H
MOV R0,#PORT_A
Vaagdevi Institute of Technology & Science, Proddatur Page 78
Dept of E.C.E MICRO PROCESSORS & MICRO CONTROLLERS LAB
MOVX @R0,A
MOV A,#0FAH
MOV R0,#PORT_B
MOVX @R0,A
MOV A,#0F9H
MOV R0,#PORT_B
MOVX @R0,A
MOV A,#0FDH
MOV R0,#PORT_B
MOVX @R0,A
MOV A,#0F9H
MOV R0,#PORT_B
MOVX @R0,A
MOV R1,#10H
CALL DELAY
RET
;DELAY SUBROUTINE
DELAY: MOV R2,#02H
DLY:DJNZ R2,DLY
DJNZ R1,DLY
RET
;STRING WRITE SUBROUTINE
STRING: CLR A
MOVC A,@A+DPTR
JZ L3
CALL DWR
INC DPTR
DJNZ R3,STRING
L3: RET
MESS: DB 'IS TYPED',00H
DISP1: DB 'WAITING',00H
DISP2: DB 'FOR KEY',00H
END
RESULT: Assembly Language Program to interface16*2 LCD to 8051 was executed successfully.
B. Interface LCD to 8051 in 8-bit mode(Display a a message on LCD)
AIM: To Develop and execute the program to interface LCD to 8051 in 8-bit mode.
Vaagdevi Institute of Technology & Science, Proddatur Page 79
Dept of E.C.E MICRO PROCESSORS & MICRO CONTROLLERS LAB
APPARATUS:
Software: Keil u Vision / Term51E
Hardware: 8051 Micro Controller Trainer Kit, R.P.S, Key Board
PROGRAM:
ADDRESS OPCODE LABEL MNEMONIC OPERANDS COMMENTS
8000 ORG 8000H
8000 11 1F ACALL INIT ;CALL LCD INITIALISE SUBROUTINE
8002 74 80 MOV A,#80H ;ADDRESS FOR FIRST LINE
8004 12 80 36 LCALL CMD ;DISPLAY THE
8007 90 80 87 MOV DPTR,#DISP1 ;
800A 7B 08 MOV R3,#08H
800C 12 80 7D LCALL STRING
800F 74 C0 MOV A,#0C0H ;ADDRESS FOR
8011 12 80 36 LCALL CMD ;SECOND LINE
8014 90 80 90 MOV DPTR,#DISP2 ;DISPLAY THE
8017 7B 09 MOV R3,#09H ;
8019 12 80 7D LCALL STRING
801C 02 00 03 LJMP 03
;LCD INITIALISATION SUBROUTINE
801F 74 80 INIT: MOV A,#80H ;CONFIGURE PA,PB,PC AS O/P PORTS
8021 90 E8 03 MOV DPTR,#E803H
8024 F0 MOVX @DPTR,A
8025 74 38 MOV A,#38H ;FUNCTION SET 8BIT,1 LINE
8027 12 80 36 LCALL CMD ;5*7 FONT
802A 74 0C MOV A,#0CH ;DISPLAY ON/OFF CONTROL
802C 12 80 36 LCALL CMD ;DISP ON,CURSOR OFF,BLINK OFF
802F 74 01 MOV A,#01H ;CLEAR DISPLAY
8031 12 80 36 LCALL CMD
8034 22 RET
8035 00 NOP
;COMMAND WRITE SUBROUTINE
8036 75 A0 E8 CMD: MOV P2,#0E8H
8039 78 00 MOV R0,#PORT_A
803B F2 MOVX @R0,A
803C 74 FB MOV A,#0FBH
803E 78 01 MOV R0,#PORT_B
8040 F2 MOVX @R0,A
8041 74 F8 MOV A,#0F8H
8043 78 01 MOV R0,#PORT_B
8045 F2 MOVX @R0,A
8046 74 FC MOV A,#0FCH
8048 78 01 MOV R0,#PORT_B
804A F2 MOVX @R0,A
804B 74 F8 MOV A,#0F8H
Vaagdevi Institute of Technology & Science, Proddatur Page 80
Dept of E.C.E MICRO PROCESSORS & MICRO CONTROLLERS LAB
804D 78 01 MOV R0,#PORT_B
804F F2 MOVX @R0,A
8050 79 10 MOV R1,#10H
8052 12 80 76 LCALL DELAY
8055 22 RET
;DATA WRITE SUBROUTINE
8056 75 A0 E8 DWR: MOV P2,#0E8H
8059 78 00 MOV R0,#PORT_A
805B F2 MOVX @R0,A
805C 74 FA MOV A,#0FAH
805E 78 01 MOV R0,#PORT_B
8060 F2 MOVX @R0,A
8061 74 F9 MOV A,#0F9H
8063 78 01 MOV R0,#PORT_B
8065 F2 MOVX @R0,A
8066 74 FD MOV A,#0FDH
8068 78 01 MOV R0,#PORT_B
806A F2 MOVX @R0,A
806B 74 F9 MOV A,#0F9H
806D 78 01 MOV R0,#PORT_B
806F F2 MOVX @R0,A
8070 79 10 MOV R1,#10H
8072 12 80 76 LCALL DELAY
8075 22 RET
;DELAY SUBROUTINE
8076 7A 02 DELAY: MOV R2,#02H
8078 DA FE DLY: DJNZ R2,DLY
807A D9 FC DJNZ R1,DLY
807C 22 RET
;STRING WRITE SUBROUTINE
807D E4 STRING: CLR A
807E 93 MOVC A,@A+DPTR
807F 60 05 JZ L3
8081 11 56 ACALL DWR
8083 A3 INC DPTR
8084 DB F7 DJNZ R3,STRING
8086 22 L3: RET
8087 56 41 41 47 44 DISP1: DB
808C 45 56 49 00
8090 50 52 4F 44 44 DISP2: DB
8095 41 54 55 52 00
RESULT: Assembly Language program to interface LCD to 8051 in 8-bit mode & Display the
Message was executed successfully.
Vaagdevi Institute of Technology & Science, Proddatur Page 81