0% found this document useful (0 votes)
299 views135 pages

R19 MPMC Lab Manual SVEC-Revanth-III-II

This document discusses various software tools used in microprocessor development systems, including editors, assemblers, library builders, linkers, debuggers, and simulators. It provides details on specific assemblers like TASM and MASM, explaining how they are used to assemble source code into machine code. Variables and constraints in assembly language programming are also covered.

Uploaded by

Darshan Bysani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
299 views135 pages

R19 MPMC Lab Manual SVEC-Revanth-III-II

This document discusses various software tools used in microprocessor development systems, including editors, assemblers, library builders, linkers, debuggers, and simulators. It provides details on specific assemblers like TASM and MASM, explaining how they are used to assemble source code into machine code. Variables and constraints in assembly language programming are also covered.

Uploaded by

Darshan Bysani
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 135

INTEL 8086-16 BIT

MICROPROCESSOR
(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

INTRODUCTION TO MASM/TASM PROGRAMMING

The microprocessor development system consists of a set of hardware and software tools.
The hardware of development systems usually contains a standard PC (Personal Computer),
printer and an emulator. The software tools are also called program development tools and they
are Editor, Assembler, and Library builder, Linker, Debugger and Simulator. These software
tools can be run on the PC in order to write, assemble, debug, modify and test the assembly
language programs.
EDITOR (TEXT EDITOR):
The Editor is software tool which, when run on a PC, allow the user to type/enter and
modify the assembly language program. The editor provides a set of commands for insertion,
deletion, modifications of letters, characters, statements, etc., The main faction of an editor is to
help the user to constrict the assembly language program in the right format. The program
created using editor is known as source program and usually it is saved with file extension
“ASM”.
ASSEMBLER:
The assembler is a software tool which run on a PC, converts the assembly language
program to machine language program. Several types of assemblers are available and they are
one pass assembler, two pass assembler, macro assembler, cross assembler, resident assembler
and Meta assembler.
One Pass Assembler: In the one pass assembler source code is processed only once, and we can
use only backward reference.
Two Pass Assembler: Most of the popularly used assemblers are two pass assembler. In two
pass assembler, the first pass is made through source code for the purpose of assigning an
address to all the labels and to store this information in a symbol table. The second pass is made
to actually translate the source code into machine code.
Some examples of assemblers are TASM (Borland’s Turbo Assembler), MASM
(Microsoft Macro Assembler), ASM86 (INTEL’S 8086 Assembler), etc,.

Sri Venkateswara Engineering College, Dept of E C E. Page 2


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

TASM:
The Turbo Assembler (TASM) mainly PC-targeted assembler package was Borland’s
offering in the X86 assembler programming tool market. As one would expect, TASM worked
well with Borland’s high-level language compilers for the PC, such as Turbo Pascal, Turbo Basic
and Turbo C. Along with the rest of the Turbo suite, Turbo Assembler is no longer maintained.
The Turbo Assembler package came bundled with the linker Turbo Linker, and was
interoperable with the Turbo Debugger. For compatibility with the common Microsoft Macro
Assembler (MASM), TASM was able to assemble such source code files via its MASM mode. It
also had an ideal mode that enabled a few enhancements.
The effective execution of a program in assembly language we need the following
1. MASM assembler
2. NE (Norton’s Editor) editor (or) Edlin editor
3. Linker
4. Debug utility of DOS
How to use TASM:
Install the specified TASM software on PC with DOS operating system. The program
implementation and its execution are illustrated in four stages, there are
1. Editing of program
2. Assembling the program
3. Linking the program
4. Debugging and execution of the program
C:\ tasm>edit (file name).asm
>tasm (file name).asm
Assembling
Turbo assembler version 3.2 copy right (C) 1988, 1992 Borland International
Assembling file : (file name)
Error messages : None
Warning messages : None
Passes :1

Sri Venkateswara Engineering College, Dept of E C E. Page 3


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

PROGRAM:

Remaining memory : 392K

C:\ tasm>tlink (file name).obj Turbo Linking


Turbo link version 5.1 copy right (C) 1992 Borland International the Program

C:\ tasm>debug (file name).exe Debugging & Operation


-r of the
-p Program
-q
DEBUG COMMANDS:

Command Command Character Description


& Syntax
Assembler - A [address] Assembles the instructions at a particular address.
Quit -q Quits from debug
Compare - C range address Compares two memory ranges
Display - D range Displays the contents of memory
Enter - E address [List] Enters new or modifies old memory contents
Fill - F range list Fills in a range of memory
Go - G – address Executes a program in memory
Hex - H V1V2 Adds & Subtracts two hex values (V1 & V2)
Load - L [address] [drive] Load disk data into memory
Trace -T Traces disk data into memory
Un assemble -U Un assembles hex bytes into assembler instructions

MASM:
The Microsoft Macro Assembler (abbreviated MASM) is an x86 high-level assembler for
DOS and Microsoft Windows. Currently it is the most popular x86 assembler. It supports a wide
variety of macro facilities and structured programming idioms, including high-level functions for
looping and procedures. Later versions added the capability of producing programs for
Windows. MASM is one of the few Microsoft development tools that target 16-bit, 32-bit and

Sri Venkateswara Engineering College, Dept of E C E. Page 4


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

64-bit platforms. Earlier versions were MS-DOS applications. Versions 5.1 and 6.0 were OS/2
applications and later versions were Win32 console applications. Versions 6.1 and 6.11 included
Phar Lap’s TNT DOS extender so that MASM could run in MS-DOS.
MASM can be used along with a link program to structure the codes generated by
MASM in the form of an executable file. This assembler reads the source program as its inputs
and provides an object file. The link accepts the object file produced by this MASM assembler as
input and produces an EXE file.
The effective execution of a program in assembly language we need the following
1. MASM assembler
2. NE (Norton’s Editor) editor (or) Edlin editor
3. Linker
4. Debug utility of DOS
LIBRARY BUILDER:
The library builder is used to create library files which are collection of procedures of
frequently used functions.
The input to library builder is a set of assembled object of program modules/procedures.
The library builder combines the program modules/procedures into a single file known as
library file and it is saved with file extension “.LIB”. Some examples of library builder are
Microsoft’s LIB Borland’s TLIB, etc,.
LINKER:
The linker is a software tool which is used to combine releasable object files of program
modules and library functions into a single executable file.
The linker also generates a link map file which contains the address information about the
linked files. Some examples of linkers Microsoft’s linker LINK, Borland’s Turbo linker TLINK,
etc,.
DEBUGGER:
The debugger is a software tool that allows the execution of a grogram in single step or
break-point mode under the control of user. The process of locating and correcting the errors in a
program using a debugger is known as debugging.

Sri Venkateswara Engineering College, Dept of E C E. Page 5


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

The debugger tools can help the user to isolate a problem in the program. Once the
problem/errors are identified, the algorithm can be modified. Then the user can the editor to
correct the source program, reassemble the corrected source program, relink and run the program
again.
SIMULATOR:
The simulator is a program which can be run on the development system (Personal
computer) to simulate the operations of the newly designed system. Some of the operations that
can be simulated are given below.
 Execute a program and display result.
 Single step execution of a person.
 Break – point execution of a program.
 Display the contents of register/memory.
EMULATOR:
An emulator is a combination of hardware and software. It is usually used to test and
debug the hardware and software of a newly designed microprocessor based system. The
emulator has a multi core cable which connects the PC of development system and the newly
designed hardware of microprocessor system.
VARIABLES AND CONSTRAINTS USED IN ASSEMBLERS:
Variables: The variables are symbols (or terms) used in assembly language program statements
in order to represent variable data and address. While running a program, a value has to be
attached to each variable in the program. The advantage of using variables is that the value of the
variable can be dynamically varied while running program.
Rules of Framing Variable names:
1. The variable name can have any of the following characters. A to Z a to z, 0 to 9
@ , _ (underscore).
2. The first character in the variable name should be an alphabet (A to Z or a to z) or an
underscore.
3. The length of variable name depends on assembler and normally the maximum length
of variable name is 32 characters.

Sri Venkateswara Engineering College, Dept of E C E. Page 6


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

4. The variable name are case insensitive. Therefore the assembler do not distinguish
between the upper and lower case letters/alphabets.

Constraints: The decimal, binary or hexadecimal number used to represent the data address in
assembly language program statement is called constants or numerical constants. When constants
are used to represent the address the address the address/data then their values are fixed and
cannot be changed while running a program. The binary, hexadecimal and decimal constants can
be differentiated by placing a specific alphabet at the end of the constant.
Example of Valid Constant:
1011 --------- Decimal (BCD) constant
1060 D ------ Decimal constant
Examples of invalid Constant:
1131 B ------ The character 3 should not be used in binary constant.
0E2 ---------- The character H at the end of hexadecimal number in missing.

PIN DIAGRAM:

Sri Venkateswara Engineering College, Dept of E C E. Page 7


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

A. 16 BIT ADDITION:

MEMORY
LOCATION OPCODE LABEL INSTRUCTION

Sri Venkateswara Engineering College, Dept of E C E. Page 8


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

FLOWCHART:

EXP. NO: 01 DATE:

PROGRAMS FOR ARITHMETIC OPERATIONS

AIM: To write an assembly language Program for 16 bit arithmetic operations


of 8086(using different Addressing modes) .

APPARATUS REQUIRED:

i) 8086microprocessor kit -1/ TASM software


ii) FPS (+5V) -1
ALGORITHM:

Sri Venkateswara Engineering College, Dept of E C E. Page 9


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

B .16 BIT SUBTRACTION:

MEMORY
LOCATION OPCODE LABEL INSTRUCTION

Sri Venkateswara Engineering College, Dept of E C E. Page 10


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

FLOWCHART:

PROGRAMS: (using register addressing mode):


A. 16 BIT ADDITION:

.MODEL SMALL
.STACK 100
.DATA
OPR1 DW 8888H
OPR2 DW 6666H
RES DW 3 DUP(?),’$’
.CODE
MOV AX,@DATA
MOV DS,AX
MOV AX,OPR1
MOV BX,OPR2
ADD AX,BX
MOV RES,AX
MOV AX,0000H
RCL AX,0001H
Sri Venkateswara Engineering College, Dept of E C E. Page 11
(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

MOV [RES+2],AX
MOV AH,09H
MOV DX,OFFSET RES
INT 21H
MOV AH,4CH
INT 21H
END

OBERVATION TABLE:
A. 16 BIT ADDITION

INPUT OUTPUT
MEMORY MEMORY
LOCATION DATA LOCATION DATA

C.16 BIT MULTIPLICATION:

MEMORY
LOCATION OPCODE LABEL INSTRUCTION

FLOWCHART:
Sri Venkateswara Engineering College, Dept of E C E. Page 12
(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

A. 16 BIT SUBTRACTION:
.MODEL SMALL
.STACK 100
.DATA
OPR1 DW 8888H
OPR2 DW 6666H
RES DW 3 DUP(?),’$’
.CODE
MOV AX,@DATA
MOV DS,AX
MOV AX,OPR1
MOV BX,OPR2
SUB AX,BX
MOV RES,AX
MOV AX,0000H

Sri Venkateswara Engineering College, Dept of E C E. Page 13


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

RCL AX,0001H
MOV [RES+2],AX
MOV AH,09H
MOV DX,OFFSET RES
INT 21H
MOV AH,4CH
INT 21H
END
OBERVATION TABLE:
B.16 BIT SUBTRACTION
INPUT OUTPUT
MEMORY MEMORY
LOCATION DATA LOCATION DATA

D. 16 BIT DIVISION:

MEMORY
LOCATION OPCODE LABEL INSTRUCTION

Sri Venkateswara Engineering College, Dept of E C E. Page 14


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

FLOWCHART:

C.16 BIT MULTIPLICATION:


.MODEL SMALL
.STACK 100
.DATA
OPR1 DW 7777H
OPR2 DW 8888H
RES DW 2 DUP(?),’$’
.CODE
MOV AX,@DATA
MOV DS,AX
MOV AX,OPR1
MOV BX,OPR2
MUL BX
MOV RES,AX
MOV [RES+2],DX

Sri Venkateswara Engineering College, Dept of E C E. Page 15


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

MOV AH,09H
MOV DX,OFFSET RES
INT 21H
MOV AH,4CH
INT 21H
END
OBERVATION TABLE:
C.16 BIT MULTIPLICATION
INPUT OUTPUT
MEMORY MEMORY
LOCATION DATA LOCATION DATA

CALCULATION:

Sri Venkateswara Engineering College, Dept of E C E. Page 16


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

D.16BIT DIVISION:
.MODEL SMALL
.STACK 100
.DATA
OPR1 DW 5555H
OPR2 DW 0055H
RES DW 2 DUP(?),’$’
.CODE
MOV AX,@DATA
MOV DS,AX
XOR AX,AX
MOV AX,OPR1
MOV BX,OPR2
DIV BX
MOV RES,AX

Sri Venkateswara Engineering College, Dept of E C E. Page 17


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

MOV [RES+2],DX
MOV AH,09H
MOV DX,OFFSET RES
INT 21H
MOV AH,4CH
INT 21H
END

OBERVATION TABLE:
C.16 BIT DIVISION
INPUT OUTPUT
MEMORY MEMORY
LOCATION DATA LOCATION DATA

E.16 BIT ADDITION: (using direct addressing mode)

MEMORY
LOCATION OPCODE LABEL INSTRUCTION

Sri Venkateswara Engineering College, Dept of E C E. Page 18


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

FLOWCHART:

PROGRAMS (using direct addressing mode):


E.16 BIT ADDITION:
.MODEL SMALL
.STACK 100
.DATA
OPR1 DW 8888H
OPR2 DW 6666H
RES DW 3 DUP(?),’$’
.CODE
MOV AX,@DATA
MOV DS,AX
MOV AX,OPR1
ADD AX,OPR2
MOV RES,AX
MOV AX,0000H
RCL AX,0001H

Sri Venkateswara Engineering College, Dept of E C E. Page 19


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

MOV [RES+2],AX
MOV AH,09H
MOV DX,OFFSET RES
INT 21H
MOV AH,4CH
INT 21H
END
OBERVATION TABLE:
E.16 BIT ADDITION:

INPUT OUTPUT
MEMORY MEMORY
LOCATION DATA LOCATION DATA

F. 16 BIT SUBTRACTION:

MEMORY
LOCATION OPCODE LABEL INSTRUCTION

FLOWCHART:

Sri Venkateswara Engineering College, Dept of E C E. Page 20


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

A. 16 BIT SUBTRACTION:
.MODEL SMALL
.STACK 100
.DATA
OPR1 DW 8888H
OPR2 DW 6666H
RES DW 3 DUP(?),’$’
.CODE
MOV AX,@DATA
MOV DS,AX
MOV AX,OPR1
SUB AX,OPR2
MOV RES,AX
MOV AX,0000H
RCL AX,0001H
MOV [RES+2],AX

Sri Venkateswara Engineering College, Dept of E C E. Page 21


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

MOV AH,09H
MOV DX,OFFSET RES
INT 21H
MOV AH,4CH
INT 21H
END
OBERVATION TABLE:
F. 16 BIT SUBTRACTION:
INPUT OUTPUT
MEMORY MEMORY
LOCATION DATA LOCATION DATA

G.16 BIT ADDITION:

MEMORY
LOCATION OPCODE LABEL INSTRUCTION

Sri Venkateswara Engineering College, Dept of E C E. Page 22


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

FLOWCHATR:

PROGRAMS (using indirect register addressing mode):


G.16 BIT ADDITION:
.MODEL SMALL
.STACK 100
.DATA
OPR1 DW 8888H
OPR2 DW 6666H
RES DW 3 DUP(?),’$’
.CODE
MOV AX,@DATA
MOV DS,AX
LEA SI,OPR1
LEA DI,OPR2

Sri Venkateswara Engineering College, Dept of E C E. Page 23


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

MOV AX,[SI]
MOV BX,[DI]
ADD AX,BX
MOV RES,AX
MOV AX,0000H
RCL AX,0001H
MOV [RES+2],AX
MOV AH,09H
MOV DX,OFFSET RES
INT 21H
MOV AH,4CH
INT 21H
END

CALCULATION:

Sri Venkateswara Engineering College, Dept of E C E. Page 24


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

OBERVATION TABLE:
G. 1.6 BIT ADDITION:
INPUT OUTPUT
MEMORY MEMORY
LOCATION DATA LOCATION DATA

H. 16 BIT SUBTRACTION:

MEMORY
LOCATION OPCODE LABEL INSTRUCTION

Sri Venkateswara Engineering College, Dept of E C E. Page 25


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

FLOWCHART:

H. 16 BIT SUBTRACTION:
.MODEL SMALL
.STACK 100
.DATA
OPR1 DW 8888H
OPR2 DW 6666H
RES DW 3 DUP(?),’$’
.CODE
MOV AX,@DATA
MOV DS,AX
LEA SI,OPR1
LEA DI,OPR2

Sri Venkateswara Engineering College, Dept of E C E. Page 26


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

MOV AX,[SI]
MOV BX,[DI]
SUB AX,BX
MOV RES,AX
MOV AX,0000H
RCL AX,0001H
MOV [RES+2],AX
MOV AH,09H
MOV DX,OFFSET RES
INT 21H
MOV AH,4CH
INT 21H
END

OBERVATION TABLE:
H. 16 BIT SUBTRACTION:
INPUT OUTPUT
MEMORY MEMORY
LOCATION DATA LOCATION DATA

CALCULATION:

Sri Venkateswara Engineering College, Dept of E C E. Page 27


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

I.16 BIT ADDITION

MEMORY
LOCATION OPCODE LABEL INSTRUCTION

Sri Venkateswara Engineering College, Dept of E C E. Page 28


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

FLOWCHART:

PROGRAMS (using immediate addressing mode):


I.16 BIT ADDITION
.MODEL SMALL
.STACK 100
.DATA
RES DW 3 DUP(?),’$’
.CODE
MOV AX,@DATA
MOV DS,AX
MOV AX,6666h
ADD AX,7788h
MOV RES,AX
MOV AX, 0000H

Sri Venkateswara Engineering College, Dept of E C E. Page 29


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

RCL AX,0001H
MOV [RES+2],AX
MOV AH,09H
MOV DX,OFFSET RES
INT 21H
MOV AH,4CH
INT 21H
END

OBERVATION TABLE:
I. 16 BITADDITION:
INPUT OUTPUT
MEMORY MEMORY
LOCATION DATA LOCATION DATA

J. 16 BIT SUBTRACTION:

MEMORY
LOCATION OPCODE LABEL INSTRUCTION

Sri Venkateswara Engineering College, Dept of E C E. Page 30


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

FLOWCHART:

J. 16 BIT SUBTRACTION:
.MODEL SMALL
.STACK 100
.DATA
RES DW 3 DUP(?),’$’
.CODE
MOV AX,@DATA
MOV DS,AX
MOV AX,6666h
SUB AX,7788h
MOV RES,AX
MOV AX, 0000H
Sri Venkateswara Engineering College, Dept of E C E. Page 31
(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

RCL AX,0001H
MOV [RES+2],AX
MOV AH,09H
MOV DX,OFFSET RES
INT 21H
MOV AH,4CH
INT 21H
END
OBERVATION TABLE:
I. 16 BIT SUBTRACTION:

INPUT OUTPUT
MEMORY MEMORY
LOCATION DATA LOCATION DATA

Sri Venkateswara Engineering College, Dept of E C E. Page 32


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

RESULT:

CONCLUSION:

VIVA QUESTIONS:

1. What is need for initializing the data segment register?

Sri Venkateswara Engineering College, Dept of E C E. Page 33


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

2. What is an interrupt?

3. What are the data definition directives?

4. What are interrupt vectors?

5. Explain the organization of system memory?

ASCENDING ORDER:

MEMORY
LOCATION OPCODE LABEL INSTRUCTION

Sri Venkateswara Engineering College, Dept of E C E. Page 34


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

EXP. NO : 02 DATE:

PROGRAM FOR SORTING AN ARRAY FOR 8086


A.ASCENDING ORDER

AIM: To write an assembly language program to sorting of numbers in


an ascending in a given series by using MASM software.

Sri Venkateswara Engineering College, Dept of E C E. Page 35


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

APPARATUS REQUIRED:

i). 8086microprocessor kit -1/ MASM software


ii).FPS(+5V) -1

ALGORITHM:

FLOWCHART:

Sri Venkateswara Engineering College, Dept of E C E. Page 36


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

PROGRAM:

.MODEL SMALL
.STACK 100
.DATA

LIST DB 56H,12H,72H,32H,13H
COUNT EQU ($-LIST)
Sri Venkateswara Engineering College, Dept of E C E. Page 37
(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

.CODE

MOV AX,@DATA
MOV DS,AX
MOV CX,COUNT
MOV DX,CX

AGAIN: MOV SI,OFFSET LIST


MOV CX,DX

BACK : MOV AL,[SI]


INC SI
CMP AL,[SI]
JC NEXT
XCHG [SI],AL
DEC SI
MOV [SI],AL
INC SI

NEXT :LOOP BACK


DEC DX
JNZ AGAIN
MOV AH,09H
MOV DX,OFFSET LIST
INT 21H

MOV AH,4CH
INT 21H
END

B.DESCENDING ORDER

MEMORY
LOCATION OPCODE LABEL INSTRUCTION

Sri Venkateswara Engineering College, Dept of E C E. Page 38


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

B.DESCENDING ORDER

AIM: To write an assembly language program to sorting of numbers in


an descending in a given series by using MASM software.

APPARATUS REQUIRED:

i). 8086microprocessor kit -1/ MASM software

Sri Venkateswara Engineering College, Dept of E C E. Page 39


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

ii).FPS(+5V) -1

ALGORITHM:

FLOWCHART:

Sri Venkateswara Engineering College, Dept of E C E. Page 40


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

PROGRAM:
.MODEL SMALL
.STACK 100
.DATA

LIST DB 56H,12H,72H,32H,13H
COUNT EQU ($-LIST)
.CODE
Sri Venkateswara Engineering College, Dept of E C E. Page 41
(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

MOV AX,@DATA
MOV DS,AX
MOV CX,COUNT
MOV DX,CX

AGAIN: MOV SI,OFFSET LIST


MOV CX,DX

BACK : MOV AL,[SI]


INC SI
CMP AL,[SI]
JNC NEXT
XCHG [SI],AL
DEC SI
MOV [SI],AL
INC SI

NEXT :LOOP BACK


DEC DX
JNZ AGAIN
MOV AH,09H
MOV DX,OFFSET LIST
INT 21H

MOV AH,4CH
INT 21H
END

OBERVATION TABLE:
ASCENDING ORDER

INPUT OUTPUT
MEMORY MEMORY
LOCATION DATA LOCATION DATA

Sri Venkateswara Engineering College, Dept of E C E. Page 42


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

OBERVATION TABLE:
DECENDING ORDER

INPUT OUTPUT
MEMORY MEMORY
LOCATION DATA LOCATION DATA

Sri Venkateswara Engineering College, Dept of E C E. Page 43


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

RESULT:

CONCLUSION:
.

VIVA QUESTIONS:
1. Give the concept of Jump with return and jump with non return.

Sri Venkateswara Engineering College, Dept of E C E. Page 44


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

2. What are the flags that are effected by compare statement?

3. What is the Significance of inserting label in programming.

4. What is the Significance of int 03h.

5. What is the purpose of offset?

PACKED BCD TO ASCII

OPCODE
MEMORY LABEL INSTRUCTION
LOCATION

Sri Venkateswara Engineering College, Dept of E C E. Page 45


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

FLOWCHART:

EXP. NO: 03 DATE:

CODE CONVERSION
A.PACKED BCD TO ASCII

Sri Venkateswara Engineering College, Dept of E C E. Page 46


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

AIM: To write an assembly language program to convert BCD number to


ASCII number using MASM software.
.

APPARATUS REQUIRED:

i). 8086microprocessor kit -1/ MASM software


ii).FPS(+5V) -1

ALGORITHM:

CALCULATION:

Sri Venkateswara Engineering College, Dept of E C E. Page 47


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

PROGRAM:

.model small
.STACK 100
.DATA
BCD DB 17H

Sri Venkateswara Engineering College, Dept of E C E. Page 48


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

ASCII DW 1 DUP(?),'$'

.CODE

MOV AX,@DATA
MOV DS,AX
MOV AL,BCD
MOV CL,04H
MOV AH,AL
AND AL,0FH
AND AH,0F0H
ROR AH,CL
OR AL,30H
OR AH,30H
MOV ASCII,AX
MOV AH,09H
MOV DX, OFFSET ASCII
INT 21H
MOV AH, 4CH
INT 21H
END

OBERVATION TABLE:
PACKED BCD TO ASCII

INPUT OUTPUT
MEMORY MEMORY
LOCATION DATA LOCATION DATA

ASCII TO PACKED BCD

MEMORY
LOCATION OPCODE LABEL INSTRUCTION

Sri Venkateswara Engineering College, Dept of E C E. Page 49


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

FLOECHART

B. ASCII TO PACKED BCD

AIM: To write an assembly language program to convert ASCII to BCD


number using MASM software.
.
Sri Venkateswara Engineering College, Dept of E C E. Page 50
(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

APPARATUS REQUIRED:

i). 8086microprocessor kit -1/ MASM software


ii).FPS(+5V) -1

ALGORITHM:

CALCULATION:

Sri Venkateswara Engineering College, Dept of E C E. Page 51


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

PROGRAM:

.MODEL SMALL
.STACK 100
.DATA
ASCII1 DB ‘31’

Sri Venkateswara Engineering College, Dept of E C E. Page 52


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

ASCII2 DB ‘37’
BCD DB 01 DUP(?),’$’
.CODE
MOV AX,@DATA
MOV DS, AX
MOV CL, 04H
MOV AL, ASCII1
MOV BL, ASCII2
AND AL, 0FH
AND BL, 0FH
ROR AL, CL
OR AL, BL
MOV BCD, AL
MOV AH,09H
MOV DX,OFFSET BCD
INT 21H
MOV AH, 4CH
INT 21H
END

OBERVATION TABLE:
ASCII TO PACKED BCD

INPUT OUTPUT
MEMORY MEMORY
LOCATION DATA LOCATION DATA

Sri Venkateswara Engineering College, Dept of E C E. Page 53


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

RESULT:

CONCLUSION:

VIVA QUESTIONS:

1. What is meant by instruction AAA ?

Sri Venkateswara Engineering College, Dept of E C E. Page 54


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

2. Why data bus is bi-directional?

3. Specifies the function of address bus and the direction of address bus?

4.List various instructions that can be used to clear accumulator in 8086?

5. When the Ready signal of 8086 is sampled by the processor?

ADDITION OF AN ARRAY OF
BCD NUMBERS

OPCODE
MEMORY LABEL INSTRUCTION
LOCATION

Sri Venkateswara Engineering College, Dept of E C E. Page 55


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

FLOWCHART:

EXP. NO: 04 DATE:

ADDITION OF AN ARRAY OF
BCD NUMBERS

Sri Venkateswara Engineering College, Dept of E C E. Page 56


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

AIM: To write an assembly language program to addition of an array of


BCD number using MASM software.
.
APPARATUS REQUIRED:

i). 8086microprocessor kit -1/ MASM software


ii).FPS(+5V) -1

ALGORITHM:

PROGRAM:

.MODEL SMALL
.STACK 100
.DATA
Sri Venkateswara Engineering College, Dept of E C E. Page 57
(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

  ARRAY   DB 1,2,3,4,5,6,7,8,9,10


  SUM_LSB DB 0
  SUM_MSB DB 0
.CODE
    MOV AX ,@DATA
    MOV DS ,AX
 
    MOV CX ,10 ;
    MOV SI,OFFSET ARRAY 
        
 UP:
    MOV AL,[SI]     
    ADD SUM_LSB , AL 
    DAA
    JNC NEXT
     INC SUM_MSB
 NEXT:
     INC SI         
     LOOP UP         
                     
                     
    MOV DL,SUM_MSB
    MOV AH ,2
    INT 21H
 
    MOV DL , SUM_LSB
    MOV AH ,2
    INT 21H

 MOV DH,00H
    MOV AH ,4CH
    INT 21H
END
OBERVATION TABLE:
BCD NUMBERS:

INPUT OUTPUT
MEMORY MEMORY
LOCATION DATA LOCATION DATA

Sri Venkateswara Engineering College, Dept of E C E. Page 58


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

RESULT:

CONCLUSION:

VIVA QUESTIONS:

1.How does 8086 perform BCD?

Sri Venkateswara Engineering College, Dept of E C E. Page 59


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

2.Which instructions are used during BCD 8 bit addition?

3.Which instruction is used to get the BCD addition result?

4.What is BCD addition in microprocessor?

5. How do you do BCD addition?

MULTIPLYING TWO 3X3 MATRICES:

MEMORY
LOCATION OPCODE LABEL INSTRUCTION

Sri Venkateswara Engineering College, Dept of E C E. Page 60


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

FLOWCHART:

EXP. NO: 05 DATE:

MULTIPLYING TWO 3X3 MATRICES

AIM: To write an assembly language program to 3*3 matrix multiplication


MASM software.

Sri Venkateswara Engineering College, Dept of E C E. Page 61


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

APPARATUS REQUIRED:

i). 8086microprocessor kit -1/ MASM software


ii).FPS(+5V) -1

ALGORITHM:

OBERVATION TABLE:
3X3 MATRICES:

INPUT- MATRICES 1 INPUT- MATRICES 2


MEMORY DATA MEMORY DATA

Sri Venkateswara Engineering College, Dept of E C E. Page 62


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

LOCATION LOCATION

OUTPUT

MEMORY
LOCATION DATA

PROGRAMS:
.MODEL SMALL
.STACK 100
.DATA
.CODE
MOV SI,1000H

Sri Venkateswara Engineering College, Dept of E C E. Page 63


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

MOV BP,1020H
MOV DI,1050H
L2: MOV CX,0000H
L1: MOV AL,[SI]
MOV BL,[BP]
MUL BL
ADD CX,AX
ADD BP,03
INC SI
CMP BP,1029
JB L1
SUB SI,03
SUB BP,08
ADD DI,02
CMP BP,1023
JB L2
ADD SI,03
SUB BP,03
CMP DI,1051
JB L2
INT 21H, MOV AH.4CH, INT 21H, END

Sri Venkateswara Engineering College, Dept of E C E. Page 64


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

RESULT:

CONCLUSION:

VIVA QUESTIONS:

1. How do you do 3x3 matrix multiplication?

Sri Venkateswara Engineering College, Dept of E C E. Page 65


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

2. What is the logic of matrix multiplication?

3. Which array is used for matrix multiplication?

4. How do you do multiplication in 8086?

5. How do you do multiplication in emu8086?

EXP. NO: 06 DATE:

DOS &BIOS FUNCTIONS

AIM: To write an assembly language program to DOS and BIOS functions using
MASM software

Sri Venkateswara Engineering College, Dept of E C E. Page 66


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

APPARATUS REQUIRED:

i). 8086microprocessor kit -1/ MASM software


ii).FPS(+5V) -1

ALGORITHM:

DOS FUNCTIONS
PROGRAMS:

DISPLAY A CHARACTER

.MODEL SMALL
.STACK 100
.DATA

Sri Venkateswara Engineering College, Dept of E C E. Page 67


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

.CODE

MOV AH,02H
MOV DL,’A’
INT 21H
END

OUTPUT:

a=61h

DISPLAY A STRING PROGRAM:

.MODEL SMALL
.STACK 100
.DATA
STRING DB “ VEMU INSTITUTE OF TECHNOLOGY” ,$
.CODE
MOV AX,@DATA
MOV DS,AX
MOV AH,09H
LEA DX,STRING
INT 21H
END

OUTPUT:

VEMU INSTITUTE OF TECHNOLOGY

READING A KEYBOARD WITHOUT ECHO

.MODEL SMALL
.STACK 100
.DATA
.CODE

Sri Venkateswara Engineering College, Dept of E C E. Page 68


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

MOV AH,08H
INT 21H
INT 21H
END

OUTPUT:

AX= 0861

INPUT A CHARACTER

.MODEL SMALL
.STACK 100
.DATA
.CODE

MOV AH,01H
INT 21H
END

OUTPUT:

AX= 0164

BIOS FUNCTIONS

PROGRAMS:

SET VIDEO MODE

.MODEL SMALL

Sri Venkateswara Engineering College, Dept of E C E. Page 69


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

.STACK 100
.DATA
.CODE

MOV AH,00H
MOV AL,01H
INT 10H
END

OUTPUT:

CHANGED VIDEO SIZE

SET CURSOR SIZE

.MODEL SMALL
.STACK 100
.DATA
.CODE

MOV AH,01H –SETTING THE CURSOR SIZE


MOV CH,00H—TO POINT THE CURSOR TO TOP LEVEL
MOV CL,14H--- TO POINT THE CURSOR TO LOW LEVEL
INT 10H
END

OUTPUT:

CHANGED THE CURSOR SIZE

KEY BOARD SHIFT STATUS

.MODEL SMALL
.STACK 100
.DATA
.CODE

Sri Venkateswara Engineering College, Dept of E C E. Page 70


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

MOV AH,12H –SETTING THE CURSOR SIZE


INT 16H
END

OUTPUT:

S.NO INPUTS OUTPUT

D7 D6 D5 D4 D3 D2 D1 D0 DATA
(nl) (cl) (sl)
1 0 0 0 1 0 0 0 0 10
2 0 0 1 0 0 0 0 0 20
3 0 0 1 1 0 0 0 0 30
4 0 1 0 0 0 0 0 0 40
5 0 1 0 1 0 0 0 0 50
6 0 1 1 0 0 0 0 0 60
7 0 1 1 1 0 0 0 0 70

KEY BOARD INPUT WITH ECHO

.MODEL SMALL
.STACK 100
.DATA
.CODE
MOV AH,01H –SETTING THE CURSOR SIZE
INT 21H
END

INPUT:

a is entered as input

OUTPUT:

The character ‘a’ is displayed along withASCII value that is ax= 0161

Sri Venkateswara Engineering College, Dept of E C E. Page 71


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

RESULT:

CONCLUSION:

VIVA QUESTIONS

1. What are the functions of BIOS and DOS?

Sri Venkateswara Engineering College, Dept of E C E. Page 72


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

2. Is BIOS an operating system?

3. What are the different types of BIOS?

4. How BIOS works step by step?

5. Where are BIOS stored?

Sri Venkateswara Engineering College, Dept of E C E. Page 73


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

INTEL 8051- 8 BIT


MICROCONTROLLER

INTRODUCTION TO 8051 MICROCONTROLLER

8051 microcontroller is designed by Intel in 1981. It is an 8-bit microcontroller. It is built with

40 pins DIP (dual inline package), 4kb of ROM storage and 128 bytes of RAM storage, 2 16-bit

Sri Venkateswara Engineering College, Dept of E C E. Page 74


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

timers. It consists of are four parallel 8-bit ports, which are programmable as well as addressable

as per the requirement. An on-chip crystal oscillator is integrated in the microcontroller having

crystal frequency of 12 MHz.

The 8051 memory is organized in a Harvard Architecture. Both the

code memory space and data memory space begin at location 0x00 for internal or external

memory which is different from the Princeton Architecture where code and data share same

memory space. The advantage of the Harvard Architecture is not only doubling the memory

capacity of the microcontroller with same number of address lines but also increases the

reliability of the microcontroller, since there are no instructions to write to the code memory

which is read only.

1. Features of 8051 Microcontroller


An 8051 microcontroller comes bundled with the following features.
 64K bytes on-chip program memory (ROM)
 128 bytes on-chip data memory (RAM) Four register banks 128 user
defined software flags
 8-bit bidirectional data bus
 16-bit unidirectional address bus
 32 general purpose registers each of 8-bit
 16 bit Timers (usually 2, but may have more or less)
 Three internal and two external Interrupts
 Four 8-bit ports,(short model have two 8-bit ports)
 16-bit program counter and data pointer

2. Diagram Of 8051 microcontroller

Sri Venkateswara Engineering College, Dept of E C E. Page 75


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

3. Pin Description :

The EA' (External Access) pin is used to control the internal or external
memory access. The signal 0 is for external memory access and signal 1 for internal memory
access. The PSEN' (Program Store Enable) is for reading external code memory when it is low
(0) and EA EC 334:Microcontroller Lab 5 ICET,ECE Dept is also 0. The ALE (Address Latch
Enable) activates the port 0 joined with port 2 to provide 16 bit external address bus to access the
external memory. The ALE multiplexes the P0: 1 for latching address on P0 as A0-A7 in the 16
bit address buss, 0 for latching P0 as data I/O. P0.x is named ADx because P0 is multiplexed for
Address bus and Data bus at different clock time. WR' provides the signal to write external data
memory RD' provides the signal to read external data and code memory

Sri Venkateswara Engineering College, Dept of E C E. Page 76


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

PORT P1 (Pins 1 to 8): The port P1 is a port dedicated for general I/O purpose. The
other ports P0, P2 and P3 have dual roles in addition to their basic I/O function

• PORT P0 (pins 32 to 39): When the external memory access is required then Port P0 is
multiplexed for address bus and data bus that can be used to access external memory in
conjunction with port P2. P0 acts as A0-A7 in address bus and D0-D7 for port data. It can be
used for general purpose I/O if no external memory presents.

• PORT P2 (pins 21 to 28): Similar to P0, the port P2 can also play a role (A8-A15) in the
address bus in conjunction with PORT P0 to access external memory.

PORT P3 (Pins 10 to 17): In addition to acting as a normal I/O port,


 P3.0 can be used for serial receive input pin(RXD)
• P3.1 can be used for serial transmit output pin(TXD) in a serial port,
 P3.2 and P3.3 can be used as external interrupt pins(INT0’ and INT1’),
 P3.4 and P3.5 are used for external counter input pins(T0 and T1),
 P3.6 and P3.7 can be used as external data memory write and read control signal pins
 (WR’ and RD’)read and write pins for memory access.

EXP. NO: 01 DATE:

8279 KEYBOARD INTERFACING WITH 8051

Sri Venkateswara Engineering College, Dept of E C E. Page 77


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

AIM: To write an Assembly Language Program to display string ESA in the


display field of the study card using 8279 keyboard and display controller decode
method with 8051 microcontroller.
.APPARATUS REQUIRED:
1. 8051 Trainer kit
2. FPS(+5V)
3. 8279 interfacing Keyboard
4. RS 26 core cable

ALGORITHM:

PROGRAM:

ADDRESS OPCODE LABEL INSTRUCTION COMMENT

8000 ORG 8000H


8000 90F181 MOV
Sri Venkateswara Engineering College, Dept of E C E. Page 78
(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

8003 74 FF DPTR,#F181
8005 F0 MOV A,#FF
8006 7A 90 MOVX
8008 7B 00 @DPTR,A
800A 90F181 MOV R2,#90
800D 74 90 MOV R3,#00
800F F0 MOV
8010 74 11 DPTR,#F181
8012 F0 MOV A,#90
8013 78 08 MOVX
8015 74 00 @DPTR,A
8017 90F180 START: MOV A,#11H
801A F0 MOVX
801B 18 @DPTR,A
801C B800F6 MOV R0,#08H
801F 79 00 MOV A,#00H
8021 909000 MOV
8024 E4 DPTR,#F180
8025 93 MOVX @DPTR,A
8026 90F180 DEC R0
8029 F0 CJNE R0,#0,8015
802A 09 MOV R1,#00
802B 909090 MOV
802E E9 START1: DPTR,#9000
802F B904F3 CLR A
8032 80FE MOVC
A,@A+DPTR
9000 MOV DPTR,#F180
9000 0497D6 MOVX @DPTR,A
9003 770404 INC R1
9006 00 MOV DPTR,#9000
MOV A,R1
JNE R1,#04,8025
SJMP 8032
TABLE:
ORG 9000H
DB 04H,97H,D6H
DB 77H,04H,04H
DB 00H

DISPLAY CODES:

Sri Venkateswara Engineering College, Dept of E C E. Page 79


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

SEVEN
HEX SEVEN SEGMENT CONVERSION SEGMENT
NUMBE DISPLAY
R D C B A DP. G F E

Sri Venkateswara Engineering College, Dept of E C E. Page 80


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

RESULT:

CONCLUSION:

VIVA QUESTIONS:

Sri Venkateswara Engineering College, Dept of E C E. Page 81


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

1.What is the function performed by 8279?

2.What are the two most important functions performed by 8279?

3.Which pin is used to blank the display of 8279?

4.When 8279 is used for keyboard and display interfacing it take care of?

5.How many types of interfacing are there?

EXP. NO: 02 DATE:


Sri Venkateswara Engineering College, Dept of E C E. Page 82
(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

DELAY GENERATION
BLINKING LED (using NESTED Loop)
AIM: To write an Assembly Language Program to make the LED connector
P1.0 blinking a specific rate.

APPARATUS REQUIRED:
1.8051 Trainer kit
2. Power supply
3. Keyboard
4. RS 26 core cable
5. LED

ALGORITHM:

PROGRAM:

Sri Venkateswara Engineering College, Dept of E C E. Page 83


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

START :
CPL P1.5
ACALL DELAY
SJMP START

DELAY: : DJNZ R3,#0FFH


L3: MOV R4,#0FFH
L2: MOV R5,#0FFH
L1: DJNZ R5,L1
DJNZ R4,L2
DJNZ R3,L3
RET

B . GENERATION OF SQUAREWAVE (using TIMER)

Sri Venkateswara Engineering College, Dept of E C E. Page 84


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

AIM: To write an Assembly Language Program to generate square waveform


using 8051µc.

APPARATUS REQUIRED:
1. 8051 Trainer kit
2. Power supply
3. Keyboard
4. RS 26 core cable
5. Cro
6. Probes

ALGORITHM:

PROGRAMS:

Sri Venkateswara Engineering College, Dept of E C E. Page 85


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

MOV TMOD,#01
HERE : MOV TL0,#0F2H
MOV TH0,#0FFH
CPL P1.5
ACALL DELAY
SJMP HERE

DELAY:SET B TR0
JNB TF0,AGAIN

AGAIN:
CLR TR0
CLR TE0
RET

Sri Venkateswara Engineering College, Dept of E C E. Page 86


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

RESULT:

CONCLUSION:

VIVA QUESTIONS:

1. What are the addresses of the two timers

Sri Venkateswara Engineering College, Dept of E C E. Page 87


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

2. What is the purpose of timers

3. What are the modes in which they work

4. What are the SFRs used to define modes for counters

5. What is the purpose of counters

EXP. NO: 03 DATE:

Sri Venkateswara Engineering College, Dept of E C E. Page 88


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

COUNTING OF EXTERNAL EVENT

AIM: TO write an Assembly Language Program to count external


events connected to port line using counters of 8051.

APPARATUS REQUIRED:
1. 8051 Trainer kit
2. Power supply
3. Keyboard
4. RS 26 core cable
5. LEDs
6. Pushbutton switch
ALGORITHM:

Sri Venkateswara Engineering College, Dept of E C E. Page 89


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

PROGRAM:

MOV TMOD,#0110000B ; counter 1, mode 2, C/T=1


; External pulses
MOV TH1,#0 ;clear TH1
SETB P3.5 ; make T1 input
AGAIN SETB TR1 ; start the counter
:
BACK : MOV A,TL1 ; get copy of count TL1
MOV P2,A ; display it on port2
JNB TF1, BACK ; keep doing it if TF=0
CLR TR1 ; stop the counter 1
CLR TF1 ; make TF=0
SJMP AGAIN ; keep doing it

Sri Venkateswara Engineering College, Dept of E C E. Page 90


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

RESULT:

CONCLUSION:

VIVA QUESTIONS:
Sri Venkateswara Engineering College, Dept of E C E. Page 91
(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

1. How many parallel input and output ports available in 8051 micro
controller?

2. What is timer in 8051?

3. What are different modes of timer?

4. How do you use a counter timer?

5. How many ways are there to generate delay in 8051? What are they ?

Sri Venkateswara Engineering College, Dept of E C E. Page 92


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

ARM Cortex M0-


NXP LPC Xpress/1115

Sri Venkateswara Engineering College, Dept of E C E. Page 93


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

EXP. NO: 01 DATE:

INTRODUCTION TO ARM CORTEX M0

The ARM Cortex-M3 is a general purpose 32-bit microprocessor, which

offers high performance and very low power consumption. The Cortex-M3 offers many

new features, including a Thumb2 instruction set, low interrupt latency, hardware divide,

interruptible /continuable multiple load and store instructions, automatic state save and

restore for interrupts, tightly integrated interrupt controller with Wake-up Interrupt

Controller and multiple core buses capable of simultaneous accesses.

Pipeline techniques are employed so that all parts of the processing and

memory systems can operate continuously. Typically, while one instruction is being

executed, its successor is being decoded, and a third instruction is being fetched from

memory.

The processor has a Harvard architecture, which means that it has a

separate instruction bus and data bus. This allows instructions and data accesses to take

place at the same time, and as a result of this, the performance of the processor increases

because data accesses do not affect the instruction pipeline. This feature results in

multiple bus interfaces on Cortex-M0, each with optimized usage and the ability to be

used simultaneously. However, the instruction and data buses share the same memory

space (a unified memory system). In other words, you cannot get 8 GB of memory space

just because you have separate bus interfaces.

Sri Venkateswara Engineering College, Dept of E C E. Page 94


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

A simplified block diagram of the Cortex-M3 architecture is shown below

MDK Introduction

MDK helps you to create embedded applications for ARM Cortex-M processorbased
devices. MDK is a powerful, yet easy to learn and use development system. It consists of MDK-
Core and software packs, which can be downloaded and installed based on the requirements
of your application.

MDK-basic
mdk-basic is not available for purchase anymore.
we recommend mdk-cortex-m for projects with cortex-m microcontrollers and mdk-standard for
legacy projects with arm7 and arm9 mcus. for more information, please visit the mdk-arm
product selector.

Sri Venkateswara Engineering College, Dept of E C E. Page 95


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

MDK Tools

The MDK Tools include all the components that you need to create,
build, and debug an embedded application for ARM based microcontroller devices.
MDK-Core consists of the genuine Keil µVision IDE and debugger with leading
support for Cortex-M processor-based microcontroller devices including the new
ARMv8-M architecture.
DS-MDK contains the Eclipse-based DS-5 IDE and debugger
and offers multi-processor support for devices based on 32-bit Cortex-A processors
or hybrid systems with32-bit Cortex-A and Cortex-M processors. MDK includes
two ARM C/C++ Compilers
with assembler, linker, and highly optimize run-time libraries tailored for optimum
code size and performance
1.ARM Compiler version 5 is the reference C/C++ compiler available with a
TÜV certified qualification kit for safety applications, as well as long-term
support and maintenance
2. ARM Compiler version 6 is based on the innovative LLVM technology and
supports the latest C language standards including C++11 and C++14. It offers
the smallest size and highest performance for Cortex-M targets.
Software Packs
Software packs contain device support, CMSIS libraries, middleware, board
support, code templates, and example projects. They may be added any time to
MDK-Core or DS-MDK,making new device support and middleware updates
independent from the toolchain.The IDE manages the provided software
components that are available for the application as
building blocks.

Sri Venkateswara Engineering College, Dept of E C E. Page 96


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

Features:

 Complete support for cortex-m, cortex-r, arm7, and arm9 devices

 µvision4 ide, debugger, and simulation environment

 C/C++ compiler from arm

 Data and event trace tools for cortex-m processor-based devices

 Complete code coverage information about your program's execution

 Execution profiler and performance analyzer enable program optimization

 Detailed start-up code using the device database

 Flash programming algorithms for ulink debug adapters

 Cmsis cortex microcontroller software interface standard compliant,

NXP (founded by Philips) LPC2148:

The NXP (founded by Philips) LPC2148 is an ARM7TDMI-S

based high-performance 32-bit RISC Microcontroller with Thumb extensions

512KB on-chip Flash ROM with In-System Programming (ISP) and In-

Sri Venkateswara Engineering College, Dept of E C E. Page 97


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

Application Programming (IAP), 32KB RAM, Vectored Interrupt Controller, Two

10bit ADCs with 14 channels, USB 2.0 Full Speed Device Controller, Two

UARTs, one with full modem interface. Two I2C serial interfaces, Two SPI serial

interfaces Two 32-bit timers, Watchdog Timer, PWM unit, Real Time Clock with

optional battery backup, Brown out detect circuit General purpose I/O pins. CPU

clock up to 60 MHz, On-chip crystal oscillator and On-chip PLL.

PROCEDURE FOR PROGRAMS ON ARM KEIL


Creating an Assembly project in Keil

1. Open the Keil IDE by clicking on its icon on the desktop.


2. From the Project menu Choose New μ Vision Project
3. Select a drive where you would like to create your project .Create a new folder
and Name it First Project. Type the name First Project for the project and click
Save. Open that project folder and give a name of your project executable file and
save it.
4. In the Data base tree, choose the vendor and then the chip you want to use and
then click OK. For example, if you want to use the LPC2148, click on the
ARM/NXP and then on the LPC2148 and then press OK.
5. After selecting chip click on OK then it will display some window asking to add
STARTUP file. Click the No button when add the startup file to the project pop up
window is displayed

A target is created.

Sri Venkateswara Engineering College, Dept of E C E. Page 98


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

6. To write your project code select a new file from FILE menu bar or Make a new
file by clicking on the New Icon. Press Ctrl+S to save the new file. (You can also
save the file by choosing Save from the File menu.).Name the file as
program1.asm and save it in the FirstProject directory.
7. Type the program in the file
8. Add the program1.asm file to the project. To do so: a. Right click on Source
Group 1 and choose Add Existing Files to Group. Then go to the FirstProject
directory and choose Program1.asm, press Add and then Close. The file will be
added to target and it shows in the project window.

Building
1. Now give a right click on target in the project window and select“Options for
Target”.
2. It will show a window, in that go to output option and choose Create Hex file
option by selecting that box.In the same window go to Linker option and choose
Use Memory Layout from Target Dialog by selecting the box, and click OK.
3. To compile your project go to Project select Build Target option or press F7.
4. In the build OUT PUT window you can see the errors and warnings in your
code. And here Your project Hex file will be created.

Debugging and Tracing


1. To start debugging click on Start/Stop Debug Session icon or choose Start/Stop
Debug Session from the Debug menu. (or simply press Ctrl+F5)
2. If it starts tracing successfully, a cursor appears in front of the next instruction to
be executed.

Sri Venkateswara Engineering College, Dept of E C E. Page 99


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

3. To trace the program use the Step Over button or click on Step Over from the
Debug menu. It executes the instructions of the program one after another.
4. To trace the program you can use the Step button, as well. The difference
between the Step Over and Step is in executing functions. While Step goes into the
function and executes its instructions one by one, Step Over executes the function
completely and goes to the instruction next to the function.
5. To exit from the debugging mode press Start/Stop Debug Session.
The Memory Window displays the memory area content. Several separate
windows can be used at a time. Open the windows from the toolbar or using the
menu View – Memory Windows.
where
Address enter an expression that evalutes to a memory address.The register
window shows and allows modifying the content of register. The window also lists
all microcontroller operation modes. The currently active mode is highlighted in
black. Currently used registers are highlighted in blue.

Registers Window- Open this window through the toolbar button or the menu
View - Registers Window.
Where
Register Lists the operation modes and register names.
Value Shows the register value.
To modify a register value, double-click the value, or click on the value and press
F2.
To refresh the values, halt program execution or click the button Update Windows
of the Toolbox

Sri Venkateswara Engineering College, Dept of E C E. Page 100


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

ASM PROGRAM Coding in ARM Keil :


DATA TRANSFER INSTRUCTIONS
1. Bit Block Transfer from Location A to Location B

AREA Program, CODE, READONLY


MOV R0, #0x40000000
MOV R1, #0X4000003F
MOV R4, #0X05
loop LDR R2, [R0] ; load the value to be moved
STR R2, [R1] ; store it back in a different location
ADD R0, R0, #+4
ADD R1, R1, #+4
SUBS R4, R4, #0X01
BNE loop
SAME B SAME
END
OUTPUT:
Before execution
40000000: 11 22 33 44 55 66 77 88 AA BB CC DD EE FF 10 20 30 40 50 60
After execution
4000003C:11 22 33 44 55 66 77 88 AA BB CC DD EE FF 10 20 30 40 50 60
DATA TRANSFER INSTRUCTIONS

ARITHMETIC INSTRUCTIONS
Addition of two 32 bit numbers

AREA Program, CODE, READONLY


MOV R0, #0x40000000
LDR R1, [R0]
ADD R0, R0, #04
LDR R2, [R0]
ADDS R1, R1, R2
ADD R0, R0, #04
STR R1, [R0]
SAME B SAME
END

Sri Venkateswara Engineering College, Dept of E C E. Page 101


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

Creating a C project in ARM Keil :

1. Open the Keil IDE by clicking on its icon on the desktop.


2. From the Project menu Choose New μVision Project
3. Select a drive where you would like to create your project .Create a new folder
and Name it FirstProject. Type the name FirstProject for the project and click Save.
Open that project folder and give a name of your project executable file and save
it.
4. In the Data base tree, choose the vendor and then the chip you want to use and
then click OK. For example, if you want to use the LPC2148, click on the
ARM/NXP and then on the LPC2148 and then press OK.
5. After selecting chip click on OK then it will display some window asking to add
STARTUP file. Click the Yes button when add the startup file to the project pop
up window is displayed. A target is created.
6. To write your project code select a new file from FILE menu bar or Make a new
file by clicking on the New Icon. Press Ctrl+S to save the new file. (You can also
save the file by choosing Save from the File menu.).Name the file as program1.C
and save it in the FirstProject directory.
7. Type the program in the file
8. Add the program1.C file to the project. To do so: a. Right click on Source
Group 1 and choose Add Files to Group. Then go to the FirstProject directory and
choose Program1.asm, press Add and then Close. The file will be added to target
and it shows in the project window.

Building
5. Now give a right click on target in the project window and select “Options for
Target”.
6. It will show a window, in that go to output option and choose Create Hex file
option by selecting that box. In the same window go to Linker option and choose
Use Memory Layout from Target Dialog by selecting the box, and click OK.
7. To compile your project go to Project select Build Target option or press F7.
8. In the build Output window you can see the errors and warnings in your code.
And here

Sri Venkateswara Engineering College, Dept of E C E. Page 102


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

Your project Hex file will be created.


Debugging and Tracing
1. To start debugging click on Start/Stop Debug Session icon or choose Start/Stop
Debug Session from the Debug menu. (or simply press Ctrl+F5)
2. To exit from the debugging mode press Start/Stop Debug Session.

Peripherals Menu
The menu Peripherals includes dialogs to view and change on-chip peripheral
settings. The content of this menu is tailored to show specific peripherals of the
CPU selected for the application. This menu is active only in Debug Mode

LPC2148 C Programming

LPC2148 has 2 ports viz. Port 0 and Port 1. Each port can be
used as I/P or O/P. Port 0 has 0-31 pins and Port1 has 16-31 pins.
Port 0 is a 32 bit wide I/O port (i.e. it can be used for max 32 pins where each pin
refers to a corresponding bit) and has dedicated direction bits for each of the pins
present in the port. 28 out of the 32 pins can be used as bi-directional I/O (digital)
pins. Pins P0.24, P0.26 & P0.27 are unavailable for use and Pin P0.30 can be used
as output pin only. In port0, P0.24, P0.26, P0.27 are not physically available means
you can‟t find them on chip but still you can write values to them. & P0.31 is
available for digital output only.

Port 1 is also a 32 bit wide I/0 port but Pins 0 to 15 i.e P1.0 – P1.15
are unavailable for use and this port too has a dedicated direction bit for each of the
usable pins. In port1, P1.0 to P1.15 is not available physically. Only P1.16 to P1.31
is available. So out of 64 pins 45 pins are covered by port0 & port1.
Each Port can be used as GPIO (general purpose I/p and O/p) or As SFR (Special
Function).

Registers used for GPIO C programming.


1. IOxPIN (x=port number): GPIO Port Pin value register. This register can be
used to Read or Write values directly to the pins. Regardless of the direction set for
the particular pins it gives the current start of the GPIO pin when read. The current

Sri Venkateswara Engineering College, Dept of E C E. Page 103


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

state of the GPIO configured port pins can always be read from this register,
regardless of pin direction.

2. IOxDIR: This is the GPIO direction control register. Setting a bit to 0 in this
register will configure the corresponding pin to be used as an Input while setting it
to 1 will configure it as Output. To set the direction of any Port as I/P or O/P we
have to SET and CLR a Register named as IODIR. This register individually
controls the direction of each port pin.
1---set as o/p
0---set as i/p

Example:

IO0DIR=0x00000000; // it means port 0 will act as i/p


IO1DIR=0x000000ff; // it means lower 8 bit of port 1 will act as o/p
3. IOxSET: GPIO Port Output Set registers. This register can be used to drive an
„output‟ configured pin to Logic 1 i.e HIGH. Writing Zero does NOT have any
effect and hence it cannot be used to drive a pin to Logic 0 i.e LOW. This register
controls the state of output pins in conjunction with the IOCLR register. Writing
ones produces highs at the corresponding port pins. Writing zeroes has no effect.

Example:
IO0SET=0x00000001; //it means 0th bit of Port 0 will be set

4. IOxCLR: This register can be used to drive an „output‟ configured pin to Logic
0 i.e LOW. Writing Zero does NOT have any effect and hence it cannot be used to
drive a pin to Logic 1. GPIO Port Output Clear registers. This Register controls the
state of output pins. Writing ones produces lows at the corresponding port pins and
clears the corresponding bits in the IOSET register.

Example:

IO0CLR=0x00000001; //it means 0th bit of Port 0 will be cleared


IOPIN Register is used to get the status of the pins.

Sri Venkateswara Engineering College, Dept of E C E. Page 104


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

IODIR Register is used to set the direction of the pins, when set to 1 means output
and when 0 means input. IOSET Register is used to set the GPIO pins. IOCLR
Register is used to clear the GPIO pins.
Note:- When IOSET = 1 it will set the particular pin, but it doesn't means that to
clear the pin you will use IOSET = 0 or IOCLR = 0, this is different in case of
ARM, to set the pin we have to
use IOSET=1 and to clear we have to use IOCLR=1.

Sri Venkateswara Engineering College, Dept of E C E. Page 105


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

‘C’ PROGRAM Coding in Keil ARM :

1.PROGRAM 1-To calculate addition of two numbers

#include <lpc214x.h>
void main (void)
{
unsigned char x, y, z ;
x=0x34;
y=0xA9;
IO0PIN=0xffffffff;
z=x+y;
IO0PIN=z;
}

2. PROGRAM 2-To turn on and off bit 10 of PORT 0

#include <lpc214x.h>
unsigned int delay;
int main (void)
{
IO0DIR = (1<<10) ; // Configure P0.10 as Output
While (1)
{
for (delay=0; delay<5000 ; delay++) ; // delay
IO0SET = (1<<10) ; // SET (1) P0.10 to turn LED ON
for (delay=0; delay<500000; delay++) ; // delay
IO0CLR = (1<<10) ; // CLEAR (0) P0.10 to turn LEDs OFF
}
}

Sri Venkateswara Engineering College, Dept of E C E. Page 106


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

RESULT:

CONCLUSION:

Sri Venkateswara Engineering College, Dept of E C E. Page 107


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

VIVA QUESTIONS:

1. What is Keil used for?

2. What are features of Keil IDE?

3. How do you use Keil MDK ARM?

4. What language is Keil?

5. What is Keil MDK ARM?

Sri Venkateswara Engineering College, Dept of E C E. Page 108


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

EXP. NO:02 DATE:

BILNKING LEDS WITH GPIO

AIM: To Write an Assembly Language Program blinking LEDs with


GPIO using ARM Keil Software.

APPARATUS REQUIRED:
1. Keil ARM software
2. PC
ALGORITHM:

Sri Venkateswara Engineering College, Dept of E C E. Page 109


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

PROGRAM:

#include<lpc214x.h>
void delay();
void main()
{
roodir |=0xffffffff;// port 0 is now acting as a output pin
while(1)
{
ioseto |=0xffffffff;// port 0’s all pins are high now (led is glowing)
delay();
ioclro |=0xffffffff;// port 0’s all pins are low now (led is off)
delay();
}
void delay()
{
unsigned int i;
for(i=0;i<30000;i++);
}

The signal output can be viewed with the Logic Analyzer.

RESULT:

Sri Venkateswara Engineering College, Dept of E C E. Page 110


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

CONCLUSION:

VIVA QUESTIONS

1. What are GPIO Ports?

2. what does the GPIO controller do?

3. Does GPIO need driver?

4. What is GPIO host controller?

5. How do i get a GPIO controller?

Sri Venkateswara Engineering College, Dept of E C E. Page 111


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

EXP. NO: 03 DATE:

MIXED ASSEMBLY AND C PROGRAMMING

AIM: To study of mixed assembly and C Programming for calling C


function from assembly and calling a assembly function from C.

Mixing Assembly and C:

C programs and assembly programs can be mixed to form a


complete program. For example, consider the following C program

// file in main.c
#include <Stdio.h>
int main(){
int i = foo(5);
printf(“The value is %d \n”, i);
return 0;
}

Now consider the function foo written in assembly

# file in foo.s
.global foo
foo:
movl 4(%esp), %eax # (esp+4) contains the value 5
imull %eax, %eax # multiply the register eax by itself
ret # return values are given back thru eax

Both programs can be compiled, linked and run using


gcc main.c foo.s
./a.out
int x = 10;
int main( ) {

Sri Venkateswara Engineering College, Dept of E C E. Page 112


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

int y = x;
}

The assembly output produced by C compiler includes a global identification of


the variable x.

.globl x
.data
.align 4
.type x, @object
.size x, 4
x:
.long 10
.text
.globl main
.type main, @function

We have provided only a part of the output. The full assembly code can be
generated by compiling the file global.c
> gcc –S global.c

Introduction of C and Assembly:

This is a quick introduction to working with x86 assembly. Some


of the instructions and register names must be check for latest commands and
register names. Programming in assembly language requires one to understand the
instruction set architecture of the processor. Writing a program in machine
language or assembly language is like programming a microprocessor kit. It
requires the understanding of low level details of how a machine may execute a set
of instructions, fetch-execute cycle among other things. Today most programmers
don’t deal directly with assembly language, unless the task requires direct
interfacing with hardware. For example, a programmer may consider using an
assembly language to write a device driver or optimize part of a game program.

To understand the assembly code, Let us consider the simple code below.

Sri Venkateswara Engineering College, Dept of E C E. Page 113


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

#this is in a file first.s


.globl main
main:
movl $20, %eax
movl $10, %ebx
ret

The first line of the program is a comment. The .globl assembler directive
makes the symbol main visible to the linker. This line makes the program linked up
with the C start up library. If we try to remove this line, then we get the following
message

% gcc first.s
/usr/lib/crt1.o: In function `_start’:
: undefined reference to `main’
collect2: ld returned 1 exit status

The commands like movl $20, %eax means that the bit pattern of 20 is moved to
register %eax.

Using the GNU C compiler –S option, we can generate the assembly code for a
source code. For example, consider the program simple.c

int main(){
int x=10,y=15;
return 0;
}

When the program is compiled with –S option

gcc – S simple.c

it produces the assembly code file simple.s as shown below.

Sri Venkateswara Engineering College, Dept of E C E. Page 114


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

.globl main
.type main, @function
main:
pushq %rbp
movq %rsp, %rbp
movl $10, -8(%rbp)
movl $15, -4(%rbp)
movl $0, %eax
leave
ret

The intent here is to give some level of understanding of how assembly code
works. There are traces of the initialization of x and y in the code as well as many
uses of esp (stack pointer) and ebp (base pointer) references. The l at the end of
each instruction indicates that we are using opcode that works with 32-bit
operands. The registers are indicated by % in front and -4(%ebp) for example,
indicates a reference to ebp-4 location. For example
movl $10, -4(%ebp)
indicates moving the value 10 to ebp-4.

Let us look at another example of a C program converted into assembly code.

#include <stdio.h>
int main(){
printf("hello world\n");
return 0;
}

// Assembly code
.LC0:
.string "hello world"
.text
.globl main
.type main, @function

Sri Venkateswara Engineering College, Dept of E C E. Page 115


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

main:
pushq %rbp
movq %rsp, %rbp
movl $.LC0, %edi
call printf
movl $0, %eax
leave
ret

In 15-213 you will be required to program in x86 assembly. In this short


introduction we only expect to understand how to interpret simple assembly
programs, how to write simple assembly programs, assemble programs into object
code and how to link them up with a C program.

Looping with Assembly


Unlike high level languages, assembly language does not have any direct
loop constructs. Instead a programmer makes use of command like je (jump equal)
to test for loop exit condition. Here is a program to find the factorial 4 and we can
assemble and run this program

# factorial of 4
# in file factorial.s

.LC0:
.string "%d \n"
.text
.global main
main:
movl $4, %eax
movl $1, %ebx
L1: cmpl $0, %eax
je L2
imul %eax, %ebx
decl %eax
jmp L1
Sri Venkateswara Engineering College, Dept of E C E. Page 116
(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

L2: movl %ebx, 4(%esp)


movl $.LC0, (%esp)
call printf
movl $0, %eax
leave
ret

The program correctly prints out the factorial of 4.


Caution: This program may not contain all assembly directives needed to compile
and run. If you type this into a file and run, it may segfault.

Functions
A function is a piece of code that is designed to perform a subtask in the
program. Functions can have local variables, receive arguments, and pass a result
back to the calling program. Consider the following subroutine foo that return the
value 4 to main.

# in file subroutine.c and subroutine.s


.globl foo
.type foo, @function
foo:
pushl %ebp
movl %esp, %ebp
movl $4, %eax
popl %ebp
ret
.LC0:
.string "The value is %d \n"
.text
.globl main
.type main, @function
main:
pushl %ebp
movl %esp, %ebp
movl $0, %eax

Sri Venkateswara Engineering College, Dept of E C E. Page 117


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

subl %eax, %esp


call foo
movl %eax, -4(%ebp)
movl -4(%ebp), %eax
movl %eax, 4(%esp)
movl $.LC0, (%esp)
call printf
movl $0, %eax
leave
ret

A function is called with the instruction “call foo”. This instruction


transfers the control of the program to foo function. The two special registers ebp
(base pointer) and esp (stack pointer) handles call and return mechanisms of
function calls. The values are returned to the calling program via register eax.

Stack
A stack data structure allows two operations, push and pop. Both
operations are handled from the top of the stack. Imagine a stack of books, where
you can add a book to the top (push) and remove a book from the top (pop). Stacks
are useful data structures for saving the status of a program before branching out.
For example, when a subroutine is called from main, the status of the environment
is pushed into the stack. Upon return from the subroutine, the status variables are
pop from the stack to restore the calling program status. The key operations of a
stack are the push and pop. For example,

popl %eax

Places the top element of the stack on the register eax and change the
stack pointer esp. The stack pointer (esp) points to the top of the stack. To
“decrement” the stack pointer esp we can simply add 4 as follows. Stacks may
grow upward or downward.

Sri Venkateswara Engineering College, Dept of E C E. Page 118


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

addl $4, %esp

The instruction causes the stack pointer to point to the next 4 bytes of memory.
Note that if the stack grows downward, then a push operation subtracts 4 from esp
and pop operation adds 4 to esp.

Local Variables

C programs generally define local variables scope as the module where they
are defined. The registers are used to manipulate the variables, but local variables
are generally stored in the stack. Some variables, perhaps declared as register
variables may hold space in a register, but most variables do not get register space
but instead allocated space in the stack. Consider the following program that
defines a local variable of value 10 and push that into the stack. Upon exit from foo
all local variables are removed from the stack. the above code, call foo causes the
address of the instruction after call foo is to be saved in the stack.

# in file local.s
.global main
main: movl $3, %eax
call foo # save the address of the next instruction on stack
subl $4, %eax
ret
foo:
pushl %ebp # save the address of base pointer
movl %esp, %ebp # move the base pointer to where stack pointer
movl $10, %ebx # push the local variable value to a register
pushl %ebx # push the value of register to stack
movl %ebp, %esp # restore the esp upon return
popl %ebp # restore the base pointer
ret # pop the stack to see where to return

Sri Venkateswara Engineering College, Dept of E C E. Page 119


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

RESULT:

CONCLUSION:

VIVA QUESTIONS

Sri Venkateswara Engineering College, Dept of E C E. Page 120


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

1. What is the full form of ARM?

2. What is ARM register?

3. What are ARM microcontrollers?

4. How many register are there in ARM?

5. Which are the different types of ARM instructions?

Sri Venkateswara Engineering College, Dept of E C E. Page 121


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

ADDITIONAL EXPERIMENTS

EXP NO: 13 Date:

Sri Venkateswara Engineering College, Dept of E C E. Page 122


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

8259 INTERRUPT CONTROLLER


INTERFACING WITH 8086
AIM: To write an Assembly Language Program to generate an interrupt using
8259 Programmable Interrupt Controller with 8086 Microprocessor.
APPARATUS REQUIRED:
1. ESA 86E trainer kit
2.8259 Programmable Interrupt Controller kit

PROGRAM:

ORG 2000H; Set PC value to 2000H


MOV AX, 0000H; Initialize Segment Registers
MOV CS, AX
MOV ES, AX
MOV SS, AX
MOV SP, 3000H; Initialize Stack Pointer
; Interrupt Vector Initialization
MOV SI, 0120H; INT 0 Vector address 0120H is the base of
Interrupt Vector Table.
MOV AX, 2200H
MOV [SI], AX
ADD SI, 02H
MOV AX, 0000H
MOV [SI], AX
ADD SI, 02H; Interrupt 1 Vector Address
MOV AX, 2210H

Sri Venkateswara Engineering College, Dept of E C E. Page 123


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

MOV [SI], AX
ADD SI, 02H
MOV AX, 0000H
MOV [SI], AX
ADD SI, 02H; Interrupt 2 Vector Address
MOV AX, 2220H
MOV [SI], AX
ADD SI, 02H
MOV AX, 0000H
MOV [SI], AX
ADD SI, 02H; Interrupt 3 Vector Address
MOV AX, 2230H
MOV [SI], AX
ADD SI, 02H
MOV AX, 0000H
MOV [SI], AX
ADD SI, 02H; Interrupt 4 Vector Address
MOV AX, 2240H
MOV [SI], AX
ADD SI, 02H
MOV AX, 0000H
MOV [SI], AX
ADD SI, 02H; Interrupt 5 Vector Address
MOV AX, 2250H
MOV [SI], AX
ADD SI, 02H
MOV AX, 0000H
Sri Venkateswara Engineering College, Dept of E C E. Page 124
(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

MOV [SI], AX
ADD SI, 02H; Interrupt 6 Vector Address
MOV AX, 2260H
MOV [SI], AX
ADD SI, 02H
MOV AX, 0000H
MOV [SI], AX
ADD SI, 02H; Interrupt 7 Vector Address
MOV AX, 220H
MOV [SI], AX
ADD SI, 02H
MOV AX, 0000H
MOV [SI], AX ; 8259 INTIALIZATION
MOV DX, 0FFC8H; Indicates Port address of 8259
MOV AL, 17H; ICW1 initialization (IC4 needed, Single, Interval
4, edge triggered)
OUT DX, AL
MOV DX, 0FFCAH; ICW2 (Multiple for int vector address table)
for masking 120H as base address of Interrupt
Vector Table)
MOV AL, 48H
OUT DX, AL
MOV AL, 03H; ICW4 (8086 mode, auto EOI)
OUT DX, AL
MOV AL, 00H
OUT DX, AL

Sri Venkateswara Engineering College, Dept of E C E. Page 125


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

STI; (Set Interrupt Flag) Enable INTR of 8086 trainer


kit
HERE: JUMP HERE
ORG 2100H; MESSAGES FOR ISRs
MSG0: DB 20H, 20H, 0AH,'INT0 OCCURRED', 0AH, 0DH
MSG1: DB 20H, 20H, 0AH,'INT1 OCCURRED', 0AH, 0DH
MSG2: DB 20H, 20H, 0AH,'INT2 OCCURRED', 0AH, 0DH
MSG3: DB 20H, 20H, 0AH,'INT3 OCCURRED', 0AH, 0DH
MSG4: DB 20H, 20H, 0AH,'INT4 OCCURRED', 0AH, 0DH
MSG5: DB 20H, 20H, 0AH,'INT5 OCCURRED', 0AH, 0DH
MSG6: DB 20H, 20H, 0AH,'INT6 OCCURRED', 0AH, 0DH
MSG7: DB 20H, 20H, 0AH,'INT7 OCCURRED', 0AH, 0DH
ORG 2200H; INT0 ISR
CLI
LEA DX, MSG0
JMP DISP
INT 03H
ORG 2210H; INT1 ISR
CLI
LEA DX, MSG1
JMP DISP
INT 03H
ORG 2220H; INT2 ISR
CLI
LEA DX, MSG2
JMP DISP
INT 03H
Sri Venkateswara Engineering College, Dept of E C E. Page 126
(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

ORG 2230H; INT3 ISR


CLI
LEA DX, MSG3
JMP DISP
INT 03H
ORG 2240H; INT4 ISR
CLI
LEA DX, MSG4
JMP DISP
INT 03H
ORG 2250H; INT5 ISR
CLI
LEA DX, MSG5
JMP DISP
INT 03H
ORG 2260H; INT6 ISR
CLI
LEA DX, MSG6
JMP DISP
INT 03H
ORG 2270H; INT7 ISR
CLI
LEA DX, MSG7
JMP DISP
INT 03H
ORG 2300H; COMMON DISPLAY ROUTINE FOR ALL ISRs
DISP: MOV SI, DX
Sri Venkateswara Engineering College, Dept of E C E. Page 127
(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

MOV CX, 11H


L1: MOV AL, [SI]
CALL FAR 0FE00:0000H; CALL ROUTINE TO DISPLAY THE
MSGS
INC SI
LOOP L1
STI
IRET
PROCEDURE:

1. Open win 86E window and initialize PC address as 20000H


2. Enter the instruction until entire program is completed and click on the
disassembly icon.
3. Provide the connections between 8086 and 8259 as follows
JP1=23 JP6=23
JP2=23 JP7=23
JP3=23 JP8=23
JP4=23 JP9=12
JP5=23 JP10=12
4. Go to command prompt and give G 2000H.
5. Specific interrupt can be selected by 4 ways DIP switch selection for
different interrupts are as follows:

Sri Venkateswara Engineering College, Dept of E C E. Page 128


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

3 2 1 4 Ways
0 0 0 IR0
0 0 1 IR1
0 1 0 IR2
0 1 1 IR3
1 0 0 IR4
1 0 1 IR5
1 1 0 IR6
1 1 1 IR7

6. While Program is running press the PUSH button on the 8259 kit to provide
service for specific interrupt service routine.

RESULT:

CONCLUSION:

Sri Venkateswara Engineering College, Dept of E C E. Page 129


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

VIVA QUEATIONS:

1. What is programmable interrupt controller in microprocessor?

2. How many interrupt levels can be handled by 8259?

3. What are the two types of control words in 8259?

4. What is the function of programmable interrupt controller?

5. What are the modes of operation of 8259?

Sri Venkateswara Engineering College, Dept of E C E. Page 130


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

EXP. NO: 14 DATE:

PROGRAM USING ARITHMETIC, LOGICAL, AND BIT


MANIPULATION INSTRUCTIONS OF 8051.

AIM: Program using arithmetic, logical and bit manipulation instructions of 8051.
.

APPARATUS REQUIRED:
1. 8051 Trainer kit
2. Power supply
PROGRAMS:

A. ARTHIMETIC OPERATIONS:

ADDITION:

MOV A,#05
MOV
B(0XF0),#0X05
ADD A,B(0XF0)
END
SUBTRACTION:

MOV A,#0X05
MOV
B,B(0XF0),#0X02
SUBB A,B(0XF0)
END

MULTIPLICATION:

MOV A,#0X05
MOV
B(0XF0),#0X03
MUL AB
END

Sri Venkateswara Engineering College, Dept of E C E. Page 131


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

DIVISION:

MOV A,#0X09
MOV
B(0XF0),#0X03
DIV AB
END

OUTPUT:

ADDITION: A=05
SUBTRACTION:A=03
MULTIPLICATION:A=0F
DIVISION:A=03

B. LOGICAL OPERATIONS:
OR Logic:
MOV A,#0X03
MOV
B(0XF0),#0X02
ORL A,B(0XF0)
END
AND Logic:

MOV A,#0X04
MOV
B(0XF0),#0X02
ANL A,B(0XF0)
END

XOR Logic:

MOV A,#0X04
MOV
B(0XF0),#0X02
XRL A,B(0XF0)
END

Sri Venkateswara Engineering College, Dept of E C E. Page 132


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

OUTPUT:
OR LOGIC: A=03
AND LOGIC: A=00
XOR LOGIC: A=06
C. BIT MANIPULATION OPERATORS

ROTATE RIGHT:

MOV A,#0X0F
RR A
END

ROTATE RIGHT WITH CARRY:

MOV ,#0X05
RRC A
END

ROTATE LEFT:
MOV
A,#0X05
RL A
END
ROTATE LEFT WITH CARRY:
MOV
A,#0X0C
RLC
A
END
SWAP:
MOV
A,#0X08
SWAP A
END

Sri Venkateswara Engineering College, Dept of E C E. Page 133


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

OUTPUT:

ROTATE RIGHT:A=07
ROTATE RIGHT WITH CARRY:A=02

ROTATE LEFT:A=0A

ROTATE LEFT WITH CARRY:A=18

SWAP:A=80

RESULT:

CONCLUSION:

Sri Venkateswara Engineering College, Dept of E C E. Page 134


(19A04601P)MICROPROCESSOR AND MOCROCONTROLLER III B.Tech II SEM ECE

VIVA QUESTIONS:
1. What are different arithmetic flags used in 8051?

2. What are different arithmetic & logical operations available for 8051?

3. Which of the following is a bit manipulation instruction in 8051?

4. What are logical instructions explain various logical instructions of 8051


giving suitable examples?

5. Which of the following is logical and bit manipulation instructions?

Sri Venkateswara Engineering College, Dept of E C E. Page 135

You might also like