Académique Documents
Professionnel Documents
Culture Documents
KONERU LAKSHMAIAH
UNIVERSITY
2012-13.
List of Experiments
Cycle - I: The following Programs/Experiments are to be written for the assembler
Using TASM software.
1. Programs on Data Transfer in forward and reverse direction using 8086.
2. Programs on Arithmetic Instructions with 16-bit data using 8086.
3. Programs on logical Instructions using 8086.
4. Programs on String manipulation using 8086.
5. Programs on Sorting and searching an array using 8086.
6. Programs on Procedures and Macros for BCD to Binary conversion, factorial
using 8086.
7. Programs on Interrupts for using 8086.
Cycle II: Interfaced with 8051 using Machine language program and some
Programs/Experiments are to be written for the assembler using TOP VIEW SIMULATOR
software for the interfacing.
8. Programs on Arithmetic, Logic& Bit manipulation Instructions 8051.
9. Interfacing 7-Segment Display 8051.
10. LCD Interfacing to 8051.
11. Interfacing of Binary Counters 8051.
12. Interfacing Stepper Motor 8051.
13. Interfacing A/D & D/A to 8051
14. Keyboard Interface 8051.
15. Data Transfer between two PCs using RS.232 C Serial Port.
Note: Minimum of 10 programs to be conducted.
Lab Incharge
HOD
INTRODUCTION
EDITOR
An editor is a program, which allows you to create a file containing the assembly language Statements for
your program. As you type in your program, the editor stores the ASCII codes for the letters and numbers in
successive RAM locations. When you have typed in all of your programs, you then save the file on a floppy
of hard disk. This file is called source file. The next step is to process the source file with an assembler. In
the TASM assembler, you should give your source file name the extension, ASM.
ASSEMBLER
An assembler program is used to translate the assembly language mnemonics for instructions to the
corresponding binary codes. When you run the assembler, it reads the source file of your Program the disk,
where you saved it after editing on the first pass thro ugh the source program the assembler determines the
displacement of named data items, the offset of labels and pails this information in a symbol table. On the
second pass through the source program, the assembler produces the binary code for each instruction and
inserts the offset etc that is calculated during the first pass. The assembler generates two files on floppy or
hard disk. The first file called the object file is given the extension. OBJ. The object file contains the binary
codes for the instructions and information about the addresses of the instructions. The second file generated
by the assembler is called assembler list file. The list file contains your assembly language statements, the
binary codes for each instructions and the offset for each instruction. In TASM assembler, TASM source file
name ASM is used to assemble the file. Edit source file name LST is used to view the list file, which is
generated, when you assemble the file.
LINKER
A linker is a program used to join several object files into one large object file and convert to an exe file.
The linker produces a link file, which contains the binary codes for all the combined modules. The linker
however doesnt assign absolute addresses to the program, it assigns is said to be relocatable because it can
be put anywhere in memory to be run. In TASM, TLINK source filename is used to link the file.
DEBUGGER
A debugger is a program which allows you to load your object code program into system memory, execute
the program and troubleshoot are debug it the debugger allows you to look at the contents of registers and
memory locations after your program runs. It allows you to change the contents of register and memory
locations after your program runs. It allows you to change the contents of register and memory locations and
return the program. A debugger also allows you to set break point at any point in the program. If you inset a
breakpoint the debugger will run the program upto the instruction where the breakpoint is set and stop
execution. You can then examine register and memory contents to see whether the results are correct at that
point. In TASM, td filename is issued to debug the file.
DEBUGGER FUNCTIONS
1. Debugger allows to look at the contents of registers and memory locations.
2. We can extend 8-bit register to 16-bit register which the help of extended register option.
3. Debugger allows to set breakpoints at any point with the program.
4. The debugger will run the program upto the instruction where the breakpoint is set and then stop
execution of program. At this point, we can examine registry and memory contents at that point.
5. With the help of dump we can view register contents.
6. We can trace the program step by step with the help of F7.
7. We can execute the program completely at a time using F8.
DEBUGGER COMMANDS
ASSEMBLE:
To write assembly language program from the given address.
A starting address <cr>
Eg: a 1000H <cr>
Starts program at an offset of 1000H.
DUMP:
To see the specified memory contents
D memory location first address last address
(While displays the set of values stored in the specified range, which is given above)
Eg: d 0100 0105 <cr>
Display the contents of memory locations from 100 to 105(including).
ENTER:
To enter data into the specified memory locations(s).
E memory location data data data data data <cr>
Eg: e 1200 10 20 30 40 .
Enters the above values starting from memory locations 1200 to 1203, by loading 10 into
1200, 20 into 1201 and soon.
GO:
To execute the program
G: one instruction executes (address specified by IP)
G address <cr>: executes from current IP to the address specified
G first address last addresses <cr>: executes a set of instructions specified between the given address.
MOVE:
Moves a set of data from source location to destination location
2. Set the PATH so that the TASM programs are available. The TASM programs are on the C drive; set the
path so that DOS can find them. This only needs to be done once each time you open an MSDOS prompt.
set PATH=%PATH%; C:\TASM\BIN.
3. Use a Text Editor to Edit the .ASM File.
Create your file using one of the following programs:
notepad proj.asm
WordPad proj.asm
edit proj.asm
4. Compile the source code to create an object module.
tasm/z/zi proj.asm
The /z switch causes TASM to display the lines that generate compilation errors. The /zi switch enables
information needed by the debugger to be included in the .OBJ file. Note that you should use "real mode"
assembler, TASM.EXE. Do not use the "protected mode" assembler TASM32.EXE for the assignments that
will be given in class
5. Run Linke r TLINK.EXE- generate .EXE file from the .OBJ file
tlink/v proj.
6. Run the Program
Your final program (if there were no errors in the previous step) will have an .EXE ending. To just run it,
type:
proj
If you want to use the debugger to examine the instructions, registers, etc., type:
td proj
This brings up the regular full-screen version of the Turbo debugger.
1. Tracing the Program's Execution
The Turbo debugger first starts, a Module Window which displays the Executable lines of program code,
marked with a bullet in the left column of the window. You can set breakpoints or step to any of these lines
of code. An arrow in the first column of the window indicates the location of the instruction pointer. This
always points to the next statement to be executed. To execute just that instruction use one of the two
methods listed under the Run menu item:
o Trace into (can use F7 key): executes one instruction; traces "into" procedures.
o Step over (can use F8 key): executes one instruction; skips (does not trace into) procedures.
Hitting either of these executes the instruction, and moves the arrow to the next instruction. As each
instruction executes, the effects might be visible in the Registers Window and Watches Window.
2. Setting and Removing Breakpoints
To set a breakpoint, position the cursor on the desired line of source code and press F2. The line containing
the breakpoint will turn red. Pressing F2 again removes the breakpoint. To execute all instructions from the
current instruction pointer up to the next encountered breakpoint, choose Run (can use F9 key) from the Run
menu item.
3. Examining Registers
Another window, the Registers Window, can be opened to examine the current value of the CPU registers
and flags. The View menu can be used to open this Registers Window. The registers and flags might change
as each instruction is executed.
4. Examining Memory
To examine memory, you will need to open an Inspector window. An Inspector window shows the contents
of a data structure (or simple variable) in the program you are debugging. It also allows you to modify the
contents of the data structure or variable. To open an Inspector window, place the cursor on what you want
to inspect and press CTRL-I. After you've examined the data item, press the ESC key to remove the
Inspector window.
5. Vie wing the Program's Output
Output written to the screen by a program is not immediately visible, since the main purpose of using a
debugger is to examine the internal operation of the program. To observe what the user would see, press
ALT-F5. The entire screen will change to a user-view showing the program's input and output (and possibly
that of previous programs as well). Press any key to return to the debugger screen.
Opcode
B0 05
Label Mnemonic
Mov AL,05
2002
B3 04
Mov BL,04
2004
02 C3
Add AL,BL
2006
CC
Int 03
comment
Data 05 is stored in reg AL
Data 04 is stored in reg BL
Data of AL and BL are
added and stored in AL
Stop
RESULT: AL: 09
b) AIM : Subtraction of two 8-bit numbers using immediate addressing mode.
Opcode
B0 05
Label Mnemonic
Mov AL,05
comment
Data 05 is stored in reg AL
Data 04 is stored in reg BL
2002
B3 04
Mov BL,04
2004
2B C3
Sub AL,BL
Data of BL is subtracted
from AL and stored in AL
2006
CC
Int 03
Stop
RESULT: AL: 01
(c) AIM : Multiplication of two 8-bit numbers using immediate addressing mode.
Opcode
B0 05
2002
B3 04
Mov BL,04
2004
F7 E3
Mul BL
2006
CC
Int 03
Stop
RESULT : AL
Label Mnemonic
Mov AL,05
comment
Data 05 is stored in reg AL
Data 04 is stored in reg BL
Opcode
B0 05
2002
B3 04
Label Mnemonic
Mov AL,05
Mov BL,04
2004
F6 F3
Div BL
2006
CC
Int 03
comment
Data 05 is stored in reg AL
Data 04 is stored in reg BL
Data of AL is divided by
BL and RESULT stored in
AL
Stop
Opcode
2000
8B060017
Mov AX,[1700]
2004
8B1E0217
Mov BX,[1702]
2008
01D8
Add AX,BX
200A
CC
Int 03
RESULT : AX=
Input:Location
Data
1700
88
1701
00
1702
44
1703
00
Label Mnemonic
comment
Move contents of 1700
in reg AX
Move contents of 1702
in reg BX
Data of AX and BX are
added and RESULT
stored in AX
Stop
Opcode
Label Mnemonic
2000
8B 06 00 17
Mov AX,[1700]
2004
8B 1E 02 17
Mov BX,[1702]
2008
29 D8
Sub AX,BX
200A
CC
Int 03
comment
Move contents of 1700
in reg AX
Move contents of 1702
in reg BX
Data
of
BX
is
subtracted from AX
and RESULT stored in
AX
Stop
RESULT : AX=
Input:Location
Data
1700
88
1701
00
1702
44
1703
00
Out put :
Opcode
2000
BE0017
Mov SI,1700
2003
8A04
Mov AL,[SI]
2005
46
Inc SI
2006
8A1C
Mov BL,[SI]
2008
02C3
Add AL,BL
200A
89060018
Mov [1800],AL
CC
Int 03
200E
Label Mnemonic
comment
Move Data from 2000
to SI
Move contents of SI to
reg AL
Incrementing SI
Moving data from SI to
BL
Adding data of AL and
BL
Move contents of AL
to 1800
Stop
RESULT :
Input:Location
Data
1700
04
1701
04
Output :1800
08
Opcode
2000
BE0017
Mov SI,1700
2003
8A04
Mov AL,[SI]
2005
46
Inc SI
2006
8A1C
Mov BL,[SI]
2008
2BC3
Sub AL,BL
200A
89060018
Mov [1800],AL
CC
Int 03
200E
RESULT :
Input:Location
Data
1700
09
1701
04
Output :1800
05
Label Mnemonic
Comment
Move Data from 2000
to SI
Move contents of SI to
reg AL
Incrementing SI
Moving data from SI to
BL
Subtract data of BL
from data of AL
Move contents of AL
to 1800
Stop
Ex.No.1
DATA TRANSFER
Date:
Aim:
A. Write an ALP to transfer the data stored in consecutive memory locations, in the forward direction.
B. Write an ALP to transfer the data stored in consecutive memory locations, in the reverse direction.
C. Write an ALP to transfer the data stored in consecutive memory locations, in the forward direction
overlapping.
Software Used:
Computer system with TASM.
PROGRAM:
A. Forward Direction
ASSUME CS: CODE, DS: DATA
DATA SEGMENT
ORG 2000H
ARR1
DB
0H,1H,2H,3H,4H,5H,6H,7H,8H,9H
COUNT
EQU 10D
ORG 3000H
ARR2
DB
DATA ENDS
CODE SEGMENT
ORG 1000H
START: MOV AX, DATA
MOV DS, AX
MOV SI, 2000H
MOV DI, 3000H
MOV CX, COUNT
BACK: MOV AH, [SI]
MOV [DI], AH
INC SI
INC DI
LOOP BACK
MOV AH, 4CH
INT21H
CODE ENDS
END START
B.Reverse Direction
ASSUME CS: CODE, DS: DATA
DATA SEGMENT
ORG 2000H
ARR1
DB
0H,1H,2H,3H,4H,5H,6H,7H,8H,9H
COUNT
EQU
10D
DB
ORG 3000H
ARR2
DATA ENDS
CODE SEGMENT
START: MOV AX, DATA
MOV DS, AX
MOV SI, 2000H
MOV DI, 3000H
MOV CX, COUNT
ADD DI, COUNT-1
BACK: MOV AH, [SI]
MOV [DI], AH
INC SI
DEC DI
LOOP BACK
DB
0H,1H,2H,3H,4H,5H,6H,7H,8H,9H
COUNT
EQU $-ARR1
OVERLAP
EQU
06D
ORG 3000H
ARR2 DB
10D
DUP (0H)
DATA ENDS
CODE SEGMENT
ORG 1000H
START: MOV AX, DATA
MOV DS, AX
MOV SI, 2000H
MOV DI, 3000H
MOV CX, COUNT-OVERLAP
NXTP: MOV AH, [SI]
MOV [DI], AH
INC SI
INC DI
LOOP NXTP
AGAIN: LEA SI, ARR1
Result: Data stored in consecutive memory locations is transferred from 2000h memory
location to 3000h memory location (a) in the forward direction (i.e. in the same order), (b) in
the reverse direction and (c) with overlapping in the forward direction.
Ex.No.2
ARITHMETIC OPERATIONS
Date:
Aim:
PROGRAM:
A. Addition
ASSUME CS: CODE, DS: DATA
DATA SEGMENT
ORG 2000H
ADDEND
DW
8765H
ADDER
DW
9876H
SUM DW
0H
CARRY
DB
0H
DATA ENDS
CODE
SEGMENT
ORG 1000H
START: MOV AX, DATA
MOV DS, AX
MOV AX, ADDEND
ADD AX, ADDER
JNC SKIP
INC CARRY
SKIP: MOV SUM, AX
MOV AH, 4CH
INT 21H
CODE
END START
ENDS
B. Subtraction
ASSUME CS: CODE, DS: DATA
DATA SEGMENT
ORG 2000H
SUBTRAHEND
DW
8765H
SUBTRACTOR
DW
9876H
DIFFERENCE
DW
0H
BARROW
DB
0H
DATA ENDS
CODE
SEGMENT
ORG 1000H
START: MOV AX, DATA
MOV DS, AX
MOV AX,SUBTRAHEND
SUB AX, SUBTRACTOR
JNC SKIP
INC BARROW
SKIP: MOV DIFFERENCE, AX
MOV AH, 4CH
INT 21H
CODE
ENDS
END START
C.Multiplication
ASSUME CS: CODE, DS: DATA
DATA SEGMENT
ORG 2000H
MULTIPLICANT
DW
0FFFFH
MULTIPLIER
DW
123AH
RES
DD
0H
DATA ENDS
CODE SEGMENT
ORG 1000H
START: MOV AX, DATA
MOV DS, AX
MOV AX, MULTIPLICANT
MOV BX, MULTIPLIER
MUL BX
MOV WORD PTR [RES], AX
MOV WORD PTR [RES+2], DX
MOV AH, 4CH
INT21H
CODE ENDS
END START
D.Division
ASSUME CS: CODE, DS: DATA
DATA SEGMENT
ORG 2000H
DIVIDEND
DW
8765H
DIVISOR
DW
1234H
QUOTIENT
DW
0H
REMAINDER
DW
0H
DATA ENDS
CODE
SEGMENT
INT 21H
CODE
ENDS
END STAR T
Result:- An ALP is written to perform a) addition, (b) subtraction, (c) multiplication and (d)
division operations using arithmetic instructions and the same is verified.
Ex.No.3
LOGICAL OPERATIONS
Date:
Aim:
A. Write an ALP to find number of 1s in a given word.
B. Write an ALP to find the number of even and odd numbers in the given array.
C. Write an ALP to find the number of elements in the array having 1 in their 5th bit position.
Software Used:
Computer system with TASM.
PROGRAM:
A. Number of 1s in a word
ASSUME CS: CODE, DS: DATA
DATA SEGMENT
ORG 2000H
NUM
DW
COUNT
EQU 16D
BITCOUNT DB
5464
0H
DATA ENDS
CODE SEGMENT
ORG 1000H
START: MOV AX, DATA
MOV DS, AX
MOV CL, COUNT
MOV AX, NUM
NXTP: ROR AX, 01H
JNC GO
INC BITCOUNT
GO: DEC CL
JNZ NXTP
MOV AH, 4CH
INT 21H
CODE ENDS
END START
B.Number of even and odd numbers
ASSUME CS: CODE, DS: DATA
DATA SEGMENT
ORG 2000H
SERIES
DW
3456H,4533H,1234H,1567H,0FFFFH,145AH,56D7,4E34H,3421H,
89C5H
COUNT
EQU 0AH
ODDCOUNT
DB
00H
EVENCOUNT
DB
00H
DATA ENDS
CODE SEGMENT
ORG 1000H
START: MOV AX, DATA
MOV DS, AX
LEA SI, SERIES
MOV CL, COUNT
NXTP: MOV AX, [SI]
ROR AX, 01H
JC ODD
INC EVENCOUNT
JMP OTHER
ODD: INC ODDCOUNT
OTHER: INC SI
DEC CL
JNZ NXTP
MOV AH, 4CH
INT 21H
CODE ENDS
END START
C.Number of elements having 1s in their 5th bit position
ASSUME CS: CODE, DS: DATA
DATA SEGMENT
ORG 2000H
SERIES
DB
COUNT
EQU 0AH
BITCOUNT DB
21H,54H,05H,34H,32H,14H,18H,17H,53H,58H
00H
DATA ENDA
CODE SEGMENT
ORG 1000H
START: MOV AX, DATA
MOV DS, AX
LEA SI, SERIES
MOV CL, COUNT
NXTP: MOV AX, [SI]
TEST AX, 10H
JZ GO
INC BITCOUNT
GO: INC SI
DEC CL
JNZ NXTP
MOV AH, 4CH
INT 21H
CODE ENDS
END START, Result: Logical operations such as Shift, rotate and test are used to find the a) no. of
1s in the given byte, b) no. of even and add numbers, c)no. of positive and negative numbers and d)
no. of elements having 1s in their 5th bit position.
Ex.No.4
STRING MANIPULATIONS
Date:
Aim:
A. Write an ALP to transfer the data in forward direction using string instructions.
B. Write an ALP to transfer the data in reverse direction using string instructions.
Software Used:
Computer system with TASM.
PROGRAM:
A. Forward Direction using String Instructions
DB
'MICROPROCESSOR'
COUNT
EQU $-STRING1
DATA ENDS
EXTRA SEGMENT
ORG 3000H
STRING2
DB
EXTRA ENDS
CODE SEGMENT
ORG 1000H
START: MOV AX, DATA
MOV DS, AX
MOV AX, EXTRA
MOV ES, AX
MOV CX, COUNT
LEA SI, STRING1
LEA DI, STRING2
CLD
REP MOVSB
MOV AH, 4CH
INT 21H
CODE ENDS
END START
B.Reverse Direction using String Instructions
DB
'MICROPROCESSOR'
LENGTH_STRING
DW
$-STRING1
DB
DATA ENDS
EXTRA SEGMENT
ORG 3000H
STRING2
EXTRA ENDS
CODE SEGMENT
ORG 1000H
START: MOV AX, DATA
MOV DS, AX
MOV AX, EXTRA
MOV ES, AX
LEA SI, STRING1
LEA DI, STRING2
MOV CX, LENGTH_STRING
ADD DI, CX
DEC DI
BACK: MOVSB
a) forward string,
b) reverse string.
Ex.No.5
SORTING
Date:
Aim:
A. Write an ALP to sort the given array in signed ascending order.
B. Write an ALP to sort the given array in unsigned descending order.
C. Write an ALP to find the maximum and the minimum element in the given array.
Software Used:
Computer system with TASM.
PROGRAM:
A. Signed ascending order
ASSUME DS: DATA, CS: CODE
DATA SEGMENT
ORG 3000H
ARRAY
DB
03H,07H,05H,01H,09H,04H,06H,02H,08H
COUNT
EQU 09H
DATA ENDS
CODE SEGMENT
ORG 1000H
START: MOV AX, DATA
MOV DS, AX
MOV DX, COUNT
DEC DX
BEGIN: MOV CX, DX
LEA SI, ARRAY
BACK: MOV AL, [SI]
CMP AL,[SI+01]
JNZ SKIP
XCHG AL, [SI+01]
DB
03H,07H,05H,01H,09H,04H,06H,02H,08H
COUNT
EQU 09H
DATA ENDS
CODE SEGMENT
ORG 1000H
START: MOV AX, DATA
MOV DS, AX
MOV DX, COUNT
DEC DX
BEGIN: MOV CX, DX
LEA SI, ARRAY
BACK: MOV AL, [SI]
CMP AL,[SI+01]
JNB SKIP
XCHG AL, [SI+01]
DW
A_LENTH
EQU
($-ARRAY)/2
MAX_NO
DW
0H
MIN_NO
DW
0H
DATA
ENDS
CODE
SEGMENT
ORG 1000H
START: MOV AX, DATA
MOV DS, AX
MOV CX, A_LENTH-1
LEA SI, ARRAY
MOV AX, [SI]
MOV BX, AX
BACK: INC SI
INC SI
CMP AX, [SI]
JNC SKIP
MOV AX, [SI]
JMP NEXT
SKIP: CMP BX, [SI]
JC NEXT
MOV BX, [SI]
NEXT: LOOP BACK
MOV MAX_NO,AX
MOV MIN_NO, BX
MOV AH, 4CH
INT 21H
CODE
ENDS
END START
Result: Sorting the array in a) signed ascending order, b) unsigned descending order and c)
searching for the maximum and minimum elements in the unsigned array, are implemented.
Ex.No.6
Aim:
A. Write an ALP to convert Hexadecimal numbers to BCD numbers.
B. Write an ALP to find the factorial of given number.
Software Used:
Computer system with TASM.
Flow Chart:
PROGRAM
A. Hexadecimal to BCD conversion
ASSUME DS: DATA, CS: CODE
DATA SEGMENT
ORG 2000H
HEXA
DB
COUNT
EQU 04
DECI
DB
12 DUP (00H)
BCD
DW
04 DUP (00H)
DATA ENDS
CODE SEGMENT
ORG 1000H
START: MOV AX, DATA
MOV DS, AX
MOV SI, OFFSET HEXA
MOV DI, OFFSET DECI
MOV CX, COUNT
BACK: XOR AX, AX
MOV AL, [SI]
MOV BL, 64H
Date:
DIV BL
MOV [DI], AL
INC DI
MOV AL, AH
XOR AH, AH
MOV BH, 0AH
DIV BH
MOV [DI], AL
INC DI
MOV [DI], AH
INC SI
INC DI
LOOP BACK
CALL UP2P
MOV AH, 4CH
INT 21H
UP2P PROC NEAR
MOV CH,COUNT
MOV DI,OFFSET DECI
MOV BP,OFFSET BCD
CONTINUE: XOR AX,AX
MOV AH,[DI]
INC DI
MOV AL,[DI]
MOV CL,4
SHL AL,CL
INC DI
ADD AL,[DI]
MOV DS:BP,AX
INC DI
INC BP
INC BP
DEC CH
JNZ CONTINUE
RET
UP2P ENDP
CODE ENDS
END START
B.Factorial of a given number
FACTORIAL MACRO
XOR CX, CX
XOR AX, AX
INC AX
MOV CL, NUMBER
CMP CL, 0
JE GO
REPEAT: MUL CX
LOOP REPEAT
GO: MOV FACT, AX
ENDM
ASSUME CS: CODE, DS: DATA
DATA SEGMENT
ORG 2000H
NUMBER
DB
08H
FACT
DW
DATA ENDS
CODE SEGMENT
START: MOV AX, DATA
MOV DS, AX
FACTORIAL
MOV AH, 4CH
INT 21H
CODE ENDS
END START
Result: Programs on a) Procedure for converting Hexadecimal numbers to packed BCD and b)
Macro for finding the factorial of a given number are implemented.
Ex.No.7
INTERRUP TS
Aim:
A. Write an ALP to find whether the given string is a palindrome or not.
B. Write an ALP to enter the string through keyboard and display it.
Software Used:
Computer system with TASM.
PROGRAM:
A. String is palindrome or not
DB
'RADAR'
COUNT
EQU
$-STRING-1
MSG1
DB
MSG2
DB
DATA ENDS
CODE SEGMENT
ORG 1000H
START: MOV AX, DATA
MOV DS, AX
LEA SI, STRING
LEA DX, MSG2
MOV CX, COUNT
MOV DI, SI
ADD DI, COUNT-1
SHR CX, 1
Date:
DB
OUTPUT
DB
S_LENTH
DB
BUFFER
DB
0
80 DUP (0)
DATA ENDS
CODE SEGMENT
START: MOV AX, DATA
MOV DS, AX
XOR CL, CL
LEA DX, INPUT
MOV AH, 09H
INT 21H
LEA BX, BUFFER
REPEAT: MOV AH, 01H
INT 21H
CMP AL, 0DH
JZ EXIT
INC CL
MOV [BX], AL
INC BX
JMP REPEAT
EXIT: MOV S_LENTH, CL
LEA BX, BUFFER
ADD BL, CL
MOV AL,$
MOV [BX], AL
LEA DX, OUTPUT
MOV AH, 09H
INT 21H
LEA DX, BUFFER
MOV AH, 09H
INT 21H
CODE ENDS
ENDF START
Result: Interrupts on a) whether the given string is a palindrome or not and b) entering the string through
keyboard and displaying the same, are verified.
Ex.No.8
Date:
Software Used:
Computer system with TOPVIEW SIMULATOR.
PROCEDURE:
MOVX A, @DPTR
MUL A B
INC DPTR
INC DPTR
MOVX @DPTR, A
MOV A, B
INC DPTR
MOVX @DPTR, A
STOP: SJMP STOP
END
D.DIVISION
$MOD51
ORG 0000H
MOV DPTR, # 0101H
MOV X A,@DPTR
MOV B, A
DEC DPL
MOVX A, @DPTR
DIV AB
INC DPTR
INC DPTR
MOVX @DPTR, A
MOV A, B
INC DPTR
MOVX @DPTR, A
STOP: SJMP STOP
END
D.SWAP
$MOD51
ORG 0000H
MOV DPTR, # 0101H
MOVX A, @ DPTR
SWAP A
INC DPTR
MOVX @ DPTR, A
STOP: SJMP STOP
END
E.RESET
$MOD51
ORG 0000H
MOV DPTR, # 0101H
CLR C
MOV A, ODOH
MOV DPTR, # 0101H
MOVX @ DPTR, A
STOP: SJMP STOP
END
F.SET
$MOD51
ORG 0000H
MOV DPTR, # 0101H
SETB C
MOV A,0D0H
MOV DPTR, # 0101H
MOVX @ DPTR, A
STOP: SJMP STOP
END
G.BIT
$MOD51
ORG 0000H
MOV DPTR, # 0101H
MOV A, ODOH
MOVX @ DPTR, A
CPL C
MOV A, ODOH
INC DPTR
MOVX @DPTR, A
STOP: SJMP STOP
END
H.BYTE
$MOD51
ORG 0000H
MOV DPTR, # 0101H
MOVX A @ DPTR
CPL A
INC DPTR
MOVX @ DPTR, A
STOP: SJMP STOP
END
I.COMPLIMENT
$MOD51
ORG 0000H
MOV DPTR,#0101H
MOVX A,@DPTR
CPL A
INC DPTR
MOVX @DPTR,A
STOP: SJMP STOP
END
Result: All the Arithmetic and special instruction operations are performed by using 8051.
Ex. No 9
Date:
Problem statement:
Interface 7-segment displays (using BCD to 7-seg decoder) to the 8051
microcontroller.
Aim: To display two Digit Decimal counter on 7- segment displays.
Software Used:
Computer system with TOPVIEW SIMULATOR.
PROCEDURE:
PIN on 8051
Digit2 A
P1.0
Digit2 B
P1.1
Digit2 C
P1.2
Digit2 D
P1.3
Digit2 Dp
GND
Digit1 A
P1.4
Digit1 B
P1.5
Digit1 C
P1.6
Digit1 D
P1.7
Digit1 Dp
GND
Circuit:
Digit2
8051
P1.0
P1.1
P1.2
P1.3
7
BCD to 7
SEG
SEG
|_|
Digit1
P1.4 A A
P1.5
BB
P1.6 C C
P1.7
BCD to 7
SEG
7
SEG
PROGRAM
$MOD51
ORG 0000H
SJMP MAIN
ORG 0030H
MAIN:MOV A,#00H
AG AIN:MOV P1,A
LCALL DELAY
ADD A,#01
DA A
SJMP AGAIN
ORG 0040H
DELAY:MOV R2,0FFH
UP1:MOV R1,0FFH
UP2:NOP
NOP
NOP
DJNZ R1,UP2
DJNZ R2,UP1
RET
END
Simulated output:
Ex.No.10
Date:
Problem statement:
Interface LCD controller to the 8051 microcontroller.
Aim: To display strings in two lines on a LCD module.
Software Used:
Computer system with TOPVIEW SIMULATOR.
Procedure:
In Top view simulator
Select device 89C51 with 12000000Hz frequency.
Open the hex file ( Ctrl + O or file->Load program).
Open LCD module settings to configure the LCD connections.( File-> External
modules settings-> LCD) Check with the summary window for correct
connections.
Select LCD as 2lines 16 characters and Data bus width as 8 bit.
In port line selection configure the port lines as per requirement. ( see the table for
port selection).
Open the LCD module. (View->External modules->LCD).
Run the program at full speed. ( Run->go)
The strings are displayed on the LCD.
To stop the execution Run->stop execution.
PIN on LCD
P1.0 P1.7
D0D7(Data lines)
P2.0
RS
P2.1
RW
P2.2
Circuit:
P1.0
P1.7
P2.0
P2.1
P2.2
PROGRAM
$MOD51
RS EQU P3.1
EN EQU P3.2
RW EQU P3.3
ORG 0000H
MOV A,#38H
LCALL LCD_COMD
MOV A,#0EH
LCALL LCD_COMD
MOV A,#06H
LCALL LCD_COMD
MOV A,#01H
LCALL LCD_COMD
MOV A,#'E'
LCALL LCD_TEXT
MOV A,#'C'
D7
RS
8051
Flow Chart:
D0
LCD
controller
RW
LCALL LCD_TEXT
MOV A,#'E'
LCALL LCD_TEXT
LOOP:SJMP LOOP
LCD_COMD:CLR C
LCALL WRITE
RET
LCD_TEXT:SETB C
LCALL WRITE
RET
WRITE:SETB EN
CLR RW
MOV RS,C
MOV P1,A
CLR EN
LCALL DELAY
RET
DELAY:MOV R0,#60
LOOP2:MOV R1,#255
LOOP1:DJNZ R1,LOOP1
DJNZ R0,LOOP2
RET
END
Simulator Output:
Result:
The strings in two lines are displayed on LCD module.
Ex.No.11
Date:
Problem statement:
Interface LED controller to the 8051 microcontroller.
Aim:
Write an ALP for LED using 8051.
Software Used:
Computer system with TOPVIEW SIMULATOR.
PROCEDURE:
PROGRAM
$MOD51
CLR A
REPEAT:MOV P1,A
LCALL DELAY
INC A
SJMP REPEAT
DELAY:MOV R2,#0FFH
BACK:MOV R1,#0FFH
UP1:NOP
NOP
DJNZ R1,UP1
DJNZ R2,BACK
RET
END
Simulator Output:
Exp.12
Date:
Aim: Interface the stepper motor to 8051 target system and write program to operate in
different speeds both clock wise and anti clock wise directions.
STEPPER MOTOR CONTROLLER INTERFACING MODULE
CIRCUIT DESCRIPTION
The four winding of the motor is connected with PA0 to PA3 through buffer and driving
circuit. So, the Port A of 8255 will have to initializes in output mode.
HARDWARE INSTALLATION
1. Connect Stepper Motor interfacing module to 8255 I of 8051 / 8085 Trainer Kit
through 26 pin FRC Cable.
2. Be sure about the direction of the cable i.e. Pin No.1 of module should be
connected to Pin No.1 of 8255 connector.
3. Connect +5V, GND from the trainer kit (+5V & GND signals are available in the
25 & 26 pin of FRC 8255 I Connector).
4. Connect Motor Supply to +12V from the Trainer Kit.
8255 Port Address:
Port A
FF00H
Port B
FF01H
Port C
FF02H
Control Word
FF03H
Procedure:
1. Create a source file in Assembly language.
2. Assemble the source file using ASM51 cross Assembler and create LST & HEX files.
3.Configure the windows hyper terminal with a baud rate 9600 , 8 data bits, no parity, 1
stop bit and flow control XON / XOFF.
4. Establish a serial communication link between Host and Target system using hyper
terminal.
5. Down load the HEX file from the host to the target system.
6. Connect stepper motor interface module to the target system and run the program.
Program:
This program will move the motor in Clock wise direction. For Anti Clock wise
direction change F9, F5, F6, FA in place of FA, F6, F5, F9.
Address Code
Label
Mnemonic
Operand
2000
90 FF 03
MOV
DPTR, #0FF03H
2003
74 80
MOV
A,#80H
2005
F0
MOVX
@DPTR,A
Comments
2006
90 FF 00
2009
74 FA
START:
MOV
DPTR,#0FF00H
output ports
MOV
A,#0FAH
200B
F0
MOVX
200C
11 1F
ACALL
DELAY
steps
200E
74 F6
MOV
@DPTR,A
A,#0F6H
2010
F0
MOVX
2011
11 1F
ACALL
@DPTR,A
DELAY
2013
74 F5
MOV
A,#0F5H
2015
F0
MOVX
@DPTR,A
2016
11 1F
ACALL
DELAY
2018
74 F9
MOV
A,#0F9H
201A
F0
MOVX
201B
11 1F
ACALL
DELAY
steps
201D
80 E7
SJMP
@DPTR,A
START
repeat
for
next
count
for
cycle
201F
7F 3F
DELAY:
MOV
R7,#03FH
delay
controlling speed
2021
7E 3F
DELA:
MOV
R6,#03FH
2023
00
DELA1:
NOP
2024
00
NOP
2025
00
NOP
2026
DE FB
DJNZ
R6,DELA1
2028
DF F7
DJNZ
R7,DELA
202A
22
RET
Result:
The Stepper Motor is interfaced to 8051 and operated with different speeds and
directions.
THEORY:
Before starting with counters there is some vital information that needs to be understood. The most
important is the fact that since the outputs of a digital chip can only be in one of two states, it must use a
different counting system than you are accustomed to. Normally we use a decimal counting system; meaning
each digit in a number is represented by one of 10 characters (0-9). In a binary system, there can only be two
characters, 0 and 1.
A computer does not recognize 0 or 1. It only works o n voltage changes. What we call logic 0 to a
computer is zero volts. What we call logic 1 is +5 volts. When a logic state changes from a zero to a one the
voltage at the pin in question goes from zero volts to +5 volts. Likewise, when a logic state changes from a
one to a zero the voltage is changing from +5 volts to zero volts.
When counting up in a decimal system, we start with the first digit. When that digit overflows, i.e. gets
above 9, we set it to 0 and add one to the next digit over. The same goes for a binary system. When the
count goes above 1 we add one to the next digit over and set the first digit to 0. Here is an example
DECIMAL TO BINARY CONVERSION
Decimal Number (base 10)
10
11
100
101
110
111
1000
1001
BINARY COUNTING
To convert a binary number to a decimal, we use a simple system. Each digit or bit of the binary
number represents a power of two. All you need to do to convert from binary to decimal is add up the
applicable powers of 2. In the example below, we find that the binary number 10110111 is equal to 183. The
diagram also shows that eight bits make up what is called a byte. Nibbles are the upper or lower four bits of
that byte. Referring to nibbles and bytes are useful when dealing with other number systems such as
hexadecimal, which is base 16.
fig1. Interfacing
PROGRAM:
INTRODUCTION
For the seven segment display you can use the LT-541 or LSD5061-11 chip. Each of the segments of the
display is connected to a pin on the 8051 (the schematic shows how to do this). In order to light up a
segment on the the pin must be set to 0V. To turn a segment off the corresponding pin must be set to 5V.
This is simply done by setting the pins on the 8051 to '1' or '0'.
For displaying Digit say 7 we need to light segments -a ,b, c. Since we are using Common anode display , to
do so we have to to provide Logic -0 (0 v) at anode of these segments.so need to clear pins- P1.0
,P1.1,P1.2. that is 1 1 1 1 1 0 0 0 -->F8h .
Connection
Hex Code
Segment
number
Seg. d Seg. c
Seg.
Seg. a HEX
b
P1.0
C0
P1.1
06
P1.2
A4
P1.3
B0
P1.4
99
P1.5
p1.6
h(dp)
P1.7
Segment
number
a
b
c
d
e
f
g
h(dp)
COMMON ANODE
Seg. d Seg. c
P1.0
P1.1
P1.2
P1.3
P1.4
P1.5
p1.6
P1.7
0
1
2
3
4
1
0
1
1
0
0
0
0
0
0
0
0
1
1
1
1
0
0
0
1
1
0
1
0
0
COMMON CATHODE
1
1
0
1
1
Seg.
b
1
1
1
1
1
Seg. a HEX
1
0
1
1
0
3f
06
5b
4f
66
You can also do this for some characters like A, E. But not for D or B because it will be same
as that of 0 & 8 . So this is one of limitation of 7-seg display.
Since we can enable only one 7-seg display at a time, we need to scan these display at fast rate .The
scanning frequency should be high enough to be flicker- free. At least 30HZ .Therefore time one digit is
ON is 1/30 seconds
INTERFACING
Note that I am using Common Anode display. So the common Anode pin is tied to 5v .The cathode pins are
connected to port 1 through 330 Ohm resistance (current limiting).
SOURCE CODE:
RESULT: To generate digits from 0 to 9 using common anode and common cathode technique.
OUTPUT VOLTAGE(V)
00
01
02
-5.00
-4.96
-4.92
7F
00
FD
4.92
FE
4.96
FF
5.00
Table 1.
Referring to Table1, with 00 H as input to DAC, the a nalog output is 5V. Similarly, With FF H as input,
the output is +5V. Outputting digital data 00 and FF at regular intervals, to DAC, results in different wave
forms namely square, triangular, etc,
Two methods of creating a DAC : binary weighted and R/2R ladder. The vast majority of integrated
circuit DACs, including the MC1408 (DAC 0809) used in this section use the R/2R method since it can
achieve a much higher degree of precision. The first criterion for judging a DAC is its resolution, which is a
function of the number of binary inputs. The common ones are 8, 10, and 12 bits. The number of data bit
inputs decides the resolution of the DAC since the number of analog output levels is equal to 2 n , where n is
the number of data bit inputs. Therefore, an 8-input DAC.
Such as the DAC 0809 provides 256 discrete voltage (or current)
Similarly, the 12-bit DAC provides 4096 discrete voltage levels.
16-bit DACs, but they are more expensive.
levels of output.
There are also
ALGORITHM:
(a) Square Wave Generation
1. Move the port address of DAC to DPTR.
2. Load the initial value (00) to Accumulator and move it to DAC.
3. Call the delay program.
4. Load the final value (FF) to accumulator and move it to DAC.
5. Call the delay program.
6. Repeat the steps 2 to 5.
(b) Saw tooth Wave Generation
1. Move the port address of DAC to DPTR.
2. Load the initial value (00) to Accumulator.
3. Move the accumulator content to DAC.
4. Increment the accumulator content by 1.
5. Repeat Steps 3 and 4.
(c) Triangular Wave Generation
1. Move the port address of DAC to DPTR.
2. Load the initial value (00) to Accumulator.
3. Move the accumulator content to DAC
PROGRAM:
(b)
MOVX @DPTR,
START: MOV A, #00H
MOV DPTR, # 2021 (port B address of DAC start)
GO: MOVX @DPTR, A
INC A
CJNE A, #FFH, GO
SJMP START
PROGRAM:
Result : Thus the square, triangular and saw tooth wave form were generated by interfacing DAC with
8051 trainer kit.
Address Latch Enable ALE: The address is latched on the Low High transition of ALE.
START: The ADCs Successive Approximation Register (SAR) is reset on the positive edge i.e. Low- High
of the Start Conversion pulse. Whereas the conversion is begun on the falling edge i.e. high Low of the
pulse.
Output Enable: Whenever data has to be read from the ADC, Output Enable pin has to be pulled high thus
enabling the TRI-STATE outputs, allowing data to be read from the data pins D0-D7.
End of Conversion (EOC): This Pin becomes high when the conversion has ended, so the controller comes
to know that the data can now be read from the data pins.
Clock: External clock pulses are to be given to the ADC; this can be given either from LM 555 in Astable
mode or the controller can also be used to give the pulses.
ALGORITHM:
1. Start. 2. Select the channel. 3. A Low High transition on ALE to latch in the address. 4. A Low
High transition on Start to reset the ADCs SAR. 5. A High Low transition on ALE. 6. A High Low
transition on start to start the conversion. 7. Wait for End of cycle (EOC) pin to become high. 8. Make
Take Data from the ADCs output 10. Make Output Enable pin Low. 11.
PROGRAM:
Winding A
Winding B
Winding C
Winding D
Going from step 1 to 4 we rotate motor clockwise, going from step 4 to 1 we rotate motor counter clockwise. The
stepper motor discussed here has total 6 leads. 4 leads representing 4 windings and 2 commons for centre tapped leads.
Here we have used 2 phase 4 step sequence. It must also be noted we can start from any step. Be it step 1, 2, 3 or 4.
But we must continue in proper order for proper rotation.
In programs on blog I have mostly begun from step 3. Other step sequences are as below
Winding A
Winding B
Winding C
Winding D
Winding A
Winding B
Winding C
Winding D
.72
500
1.8
200
180
2.5
144
72
7.5
48
15
24
4 Pins Of Stepper Motor Controlled By 4 Bits Of 8051 P1.0 - P1.3; It Is Interfaced Using Darlington
Arrays Such As Uln2003 As; 8051 Lacks Current To Run The Motor. So Uln2003 Is Used For
Energizing Stator.; Program Below Shows Just Rotating The Motor Step Wise; But Step Width Is
Unknown
MOV A, #66H
BACK :MOV P1, A
RR A
so 45.So this way we can calculate step angle for any stepper motor. Usually step angle is given in the spec sheet
of the stepper motor you are using.
Knowing stepper motor's step angle helps you calibrate the rotation of motor also to helps you move the motor
to correct angular position.
; This Other Program Code How In Same Interfacing To Rotate A Stepper Motor
; 64 Degrees In Clockwise Direction Using 4 Step Sequence
; It Takes Some Calculations
; Consider A Motor With Step Angle 2 Degree
; So Steps Per Revolution = 180
; No Of Rotor Teeth = 45
; Movement Per 4 Step Sequence is 8 Degrees
; For 64 Degree Movement We Need To Send 8 Consecutive 4 Step Sequence
; That Is It Will Cover 32 Steps
ORG 0000H
MOV A, #66H
MOV R1, #32H
; 32 Steps To Be Taken
BACK :RR A
; Rotate Clockwise
MOV P1, A ;
ACALL DELAY
END
DELAY: MOV R2, #100
H1: MOV R3, #255
H2: DJNZ R3, H2
DJNZ R2, H1
RET
Result: By applying step sequence in program rotate the motor in clock wise and anti clock wise direction.