View
7
Download
1
Category
Preview:
Citation preview
MICROPROCESSOR & MICROCONTROLLER
LABORATORY -15CSL48
[As per Choice Based Credit System (CBCS) scheme ]
Prepared By
Hemavathi M N
Asst Prof
Department of Information Science and Engineering
(2017-2018)
MAHARAJA INSTITUTE OF TECHNOLOGY MYSORE
BELAWADI, SRIRANGAPATNA Taluk, MANDYA-571438
Department of Information Science & Engineering
Vision of the Institute
To Gift the Nation with Eminent Engineers & Managers, Capable of Contributing Towards Technological
Advancement and Betterment of the Society.
Mission of the Institute
To advance the well being of society through excellence in teaching, research and service that
exploits the rapidly changing technical diversity via collaborative environment that stimulates faculty,
staff and students to reach their highest potential through continuous learning.
Instill the foundation of professionalism and provide the tools required to advance the technological
world.
Inculcate knowledge and ethics, and nurture/foster innovation and team man ship among the
graduates/alumnae.
Endow eminent education to serve the society with graduates/alumnae possessing ace skills and
potential.
Sustain highest reception of the institute‟s alumnae among the stakeholders.
Vision of the department
To be the best technical education offering centre by producing competent professionals to meet the global
challenges in the field of information science and engineering.
Mission of the department
To Provide good Teaching and Research environment with best teaching methods and mentoring
along with extra-curricular activities
Inculcate moral ethics in students enabling them to become socially committed with entrepreneurship
attitude & leadership qualities.
Program Educational Objectives:
Apply the knowledge of mathematics, basic sciences and engineering fundamentals to find solutions
for engineering related problems.
Excel with IT proficiency in the field of Information Science and Engineering by preparing graduates
to face the competitive world.
Exhibit professionalism, leadership qualities, team work and expose to current trends towards
continuous learning.
MAHARAJA INSTITUTE OF TECHNOLOGY MYSORE
BELAWADI, SRIRANGAPATNA Taluk, MANDYA-571438
Department of Information Science & Engineering
Program Outcome
PO1. Engineering knowledge: Apply the knowledge of mathematics, science, engineering fundamentals, and an
engineering specialization to the solution of complex engineering problems.
PO2. Problem analysis: Identify, formulate, research literature, and analyze complex engineering problems reaching
substantiated conclusions using first principles of mathematics, natural sciences, and engineering sciences.
PO3. Design/development of solutions: Design solutions for complex engineering problems and design system
components or processes that meet the specified needs with appropriate consideration for the public health and safety,
and the cultural, societal, and environmental considerations.
PO4. Conduct investigations of complex problems: Use research-based knowledge and research methods including
design of experiments, analysis and interpretation of data, and synthesis of the information to provide valid
conclusions.
PO5. Modern tool usage: Create, select, and apply appropriate techniques, resources, and modern engineering and IT
tools including prediction and modeling to complex engineering activities with an understanding of the limitations.
PO6. The engineer and society: Apply reasoning informed by the contextual knowledge to assess societal, health,
safety, legal and cultural issues and the consequent responsibilities relevant to the professional engineering practice.
PO7. Environment and sustainability: Understand the impact of the professional engineering solutions in societal and
environmental contexts, and demonstrate the knowledge of, and need for sustainable development.
PO8. Ethics: Apply ethical principles and commit to professional ethics and responsibilities and norms of the
engineering practice.
PO9. Individual and team work: Function effectively as an individual, and as a member or leader in diverse teams, and
in multidisciplinary settings.
PO10. Communication: Communicate effectively on complex engineering activities with the engineering community
and with society at large, such as, being able to comprehend and write effective reports and design documentation,
make effective presentations, and give and receive clear instructions.
PO11. Project management and finance: Demonstrate knowledge and understanding of the engineering and
management principles and apply these to one‟s own work, as a member and leader in a team, to manage projects and
in multidisciplinary environments.
PO12. Life-long learning: Recognize the need for, and have the preparation and ability to engage in independent and
life-long learning in the broadest context of technological change.
MAHARAJA INSTITUTE OF TECHNOLOGY MYSORE
BELAWADI, SRIRANGAPATNA Taluk, MANDYA-571438
Department of Information Science & Engineering
Course Syllabus with Overview & Objectives
Faculty Name : Hemavathi M N Academic Year: 2017 – 2018
Department: Information Science & Engineering
Course Code Course Title Core/Elective Prerequisite
Contact
Hours Total Hrs/
Sessions L T P
15CSL48
MICROPROCES
SORS AND
MICROCONTR
OLLERS
LABORATORY
CORE
Basic Electronics
Logic Design 1 2 40
Overview
This course involves demonstration and explanation of hardware components. Explanation of 8086
architecture, pin diagram is in first slot. The second slot comprises of explanation of instruction set
types/category etc.
Through this course students are able to write-up description on Microprocessors, 8086 Functional
block diagram, Pin diagram. Students will design assembly language program to demonstrate searching,
sorting, string manipulation and nCr operations. Students will implement ARM assembly program to simulate
data transfer, arithmetic and logical operations. Students are able to understand 8255 pin configuration and
implement assembly programs to interface various hardware devises. Implement hardware interfacing using
ARM assembly program and C program.
Note: These TWO Laboratory sessions are used to fill the gap between theory classes and practical
sessions. Both sessions are evaluated as lab experiments for 20 marks.
Objectives
1. To provide practical exposure to the students on microprocessors, design and coding
knowledge on 80x86 family/ARM.
2. To give the knowledge and practical exposure on connectivity and execute of
interfacing devices with 8086/ARM kit like LED displays, Keyboards, DAC/ADC, and
various other devices.
Topics Covered as per Syllabus
PART A: SOFTWARE PROGRAMS
1. Design and develop an assembly language program to search a key element “X” in a list of „n‟ 16-bit
numbers. Adopt Binary search algorithm in your program for searching.
2. Design and develop an assembly program to sort a given set of „n‟ 16-bit numbers in ascending order.
Adopt Bubble Sort algorithm to sort given elements.
3. Develop an assembly language program to reverse a given string and verify whether it is a palindrome
or not. Display the appropriate message.
4. Develop an assembly language program to compute nCr using recursive procedure. Assume that „n‟
and „r‟ are non-negative integers.
5. Design and develop an assembly language program to read the current time and Date from the system
and display it in the standard format on the screen.
6. To write and simulate ARM assembly language programs for data transfer, arithmetic and logical
operations (Demonstrate with the help of a suitable program).
7. To write and simulate C Programs for ARM microprocessor using KEIL (Demonstrate with the help of
a suitable program)
Note : To use KEIL one may refer the book: Insider’s Guide to the ARM7 based microcontrollers, Hitex
Ltd.,1st edition, 2005
PART B: HARDWARE PROGRAMS
8. a. Design and develop an assembly program to demonstrate BCD Up-Down Counter (00-99) on the
Logic Controller Interface.
b. Design and develop an assembly program to read the status of two 8-bit inputs (X & Y) from the
Logic Controller Interface and display X*Y.
9. Design and develop an assembly program to display messages “FIRE” and “HELP” alternately with
flickering effects on a 7-segment display interface for a suitable period of time. Ensure a flashing rate
that makes it easy to read both the messages (Examiner does not specify these delay values nor is it
necessary for the student to compute these values).
10. Design and develop an assembly program to drive a Stepper Motor interface and rotate the motor in
specified direction (clockwise or counter-clockwise) by N steps (Direction and N are specified by the
examiner). Introduce suitable delay between successive steps. (Any arbitrary value for the delay may be
assumed by the student).
11. Design and develop an assembly language program to
a. Generate the Sine Wave using DAC interface (The output of the DAC is to be displayed on the
CRO).
b. Generate a Half Rectified Sine waveform using the DAC interface. (The output of the DAC is to be
displayed on the CRO).
12. To interface LCD with ARM processor-- ARM7TDMI/LPC2148. Write and execute programs in C
language for displaying text messages and numbers on LCD
13. To interface Stepper motor with ARM processor-- ARM7TDMI/LPC2148. Write a program to rotate
stepper motor
List of URLs, Text Books, Notes, Multimedia Content, etc
1. https://en.wikipedia.org/wiki/Microprocessor
2. https://en.wikibooks.org/wiki/Microprocessor_Design
3. computer.howstuffworks.com/microprocessor5.htm
Conduction of Practical Examination: 1. All laboratory experiments (all 7 + 6 nos) are to be included for practical examination.
2. Students are allowed to pick one experiment from each of the lot.
3. Strictly follow the instructions as printed on the cover page of answer script for breakup of marks
PART –A: Procedure + Conduction + Viva: 10 + 25 +05 (40)
PART –B: Procedure + Conduction + Viva: 10 + 25 +05 (40)
4. Change of experiment is allowed only once and marks allotted to the procedure part to be made zero.
MAHARAJA INSTITUTE OF TECHNOLOGY MYSORE
BELAWADI, SRIRANGAPATNA Taluk, MANDYA-571438
Department of Information Science & Engineering
Date: 27/02/18
Course Outcome
Subject: Microprocessor and Microcontroller Laboratory Subject Code: 15CSL48
CO’s DESCRIPTION OF THE OUTCOMES
15CSL48.1 Design and develop assembly language program to demonstrate searching, sorting, string
manipulation and nCr operations.
15CSL48.2 Implement ARM assembly program to simulate data transfer, arithmetic and logical
operations.
15CSL48.3 Design and implement assembly programs to interface various hardware devises.
15CSL48.4 Implement hardware interfacing using ARM assembly program and C program.
CO No PO No PSO
1 2 3 4 5 6 7 8 9 10 11 12 1 2 3
CO1 3 3 3 3 - - - - 3 - - 2 2 3 2
CO2 3 3 3 3 3 - - - 3 - - 2 2 3 2
CO3 3 3 3 3 3 - - - 3 - - 2 - 3 -
CO4 3 3 3 3 3 - - - 3 - - 2 - 3 -
CO
Average 3 3 3 3 3 - - - 3 - - 2
2 3 2
Hemavathi M N Saraswathi D Hemavathi M N
Faculty Course Coordinator
Approval of the COs and their mapping with POs and PSOs was given on 27/02/18
Criterion 3 Coordinator NBA coordinator HOD
Convener Principal
MAHARAJA INSTITUTE OF TECHNOLOGY MYSORE
BELAWADI, SRIRANGAPATNA Taluk, MANDYA-571438
Department of Information Science & Engineering
Faculty Name: Hemavathi M N
MICROPROCESSORS AND MICROCONTROLLERS LABORATORY
Sub Code: 15CSL48 IA Marks: 20
Hours/week (L. T. P): 4.0.3 Exam Hours: 3 hours
Total Hours: 40 Exam Marks: 80
Semester: IV Section: B
Sl
no
Contents Page Nos
1 General Instructions 1
2 Laboratory DO‟s and DON‟Ts 1
3 Introduction to Microprocessor 2
4 Description of Microprocessor, block diagram, programming models 3
5 Assembly Language Development Tools 6
6 8255 Programmable Peripheral Interface 8
7 Procedure to write & execute a program using MASM 9
8 Instructions for Laboratory Exercises: 11
9 Lab cycle programs 12
10 Additional programs 48
11 VIVA questions with answers 55
12 Appendix A- Instruction set 60
13 Appendix B- Interrupts 72
15CSL48 Microprocessor and Microcontroller Laboratory 2017-18
Dept of ISE,MIT Mysore Page 1
MAHARAJA INSTITUTE OF TECHNOLOGY MYSORE
BELAWADI, SRIRANGAPATNA Taluk, MANDYA-571438
Department of Information Science & Engineering
MICROPROCESSOR & MICROCONTROLLER LABORATORY -15CSL48
General Instructions
Students should maintain an observation book and unit test book along with record.
Unit test will be evaluated for 05 Marks and Record for 05 Marks and final IA for 10 Marks.
Students should complete the observation book which should include the logic and tracing of
the respective program and should get it evaluated before departing from the lab.
They should produce the lab record Next week which should include lab set programs with
comments and necessary Board Layout and Circuit diagram if any.
If in case the student is unable to attend the regular batch, He / She should take prior
permission from the concerned faculty and try to attend the next batch.
DO’s and DON’Ts
Do’s
1. Know the location of the fire extinguisher and the first aid box and how to use them in case of
an emergency.
2. Read and understand how to carry out an activity thoroughly before coming to the laboratory.
3. Report fires or accidents to your faculty/laboratory technician immediately.
4. Report any broken plugs or exposed electrical wires to your faculty/laboratory technician
immediately.
Don’ts
1. Do not eat or drink in the laboratory.
2. Avoid stepping on electrical wires or any other computer cables.
3. Do not open the system unit casing or monitor casing particularly when the power is turned on.
Some internal components hold electric voltages of up to 230 volts, which can be fatal.
4. Do not insert metal objects such as clips, pins and needles into the computer casings. They
may cause fire.
5. Do not remove anything from the computer laboratory without permission.
6. Do not touch, connect or disconnect any plug or cable without your faculty /laboratory
technician‟s permission.
7. Do not misbehave in the computer laboratory.
15CSL48 Microprocessor and Microcontroller Laboratory 2017-18
Dept of ISE,MIT Mysore Page 2
MICROPROCESSOR
A Microprocessor is a programmable, digital logic device fabricated on a single
VLSI chip which can perform a set of arithmetic and logic operations as per the
instructions given by the user.
Any microprocessor has minimum three basic functional blocks: Arithmetic Logic
Unit (ALU), Timing & Control unit, Register array The user writes his/her programs using English-like words (called mnemonics) and is
known as assembly language program (ALP).
A software called .Assembler. converts the user ALP into HEX/binary form (called
machine language) which is fed to the processor. The processor internally decodes
this binary code and performs the operation.
Figure: 8086 IC
8086 Internal Block diagram 8086 is a 16-bit processor having 16-bit data bus and 20-bit address bus. The block diagram
of 8086 is as shown. This can be subdivided into two parts; the Bus Interface Unit (BIU) and
Execution Unit(EU)
Figure: Internal block diagram
15CSL48 Microprocessor and Microcontroller Laboratory 2017-18
Dept of ISE,MIT Mysore Page 3
BUS INTERFACE UNIT:
The BIU consists of segment registers, an adder to generate 20 bit address and instruction
pre-fetch queue. It is responsible for all the external bus operations like opcode fetch,
memory read, memory write, I/O read/write etc., Once this address is sent OUT of BIU, the
instruction and data bytes are fetched from memory and they fill a 6-byte First In First Out
(FIFO) queue.
EXECUTION UNIT:
The execution unit consists of: General purpose (scratch pad) registers AX, BX, CX and DX;
Pointer registers SP (Stack Pointer) and BP (Base Pointer); index registers source index (SI)
& destination index (DI) registers; the Flag register, the ALU to perform operations and a
control unit with associated internal bus. The 16-bit scratch pad registers can be split into two
8-bit registers. AX => AL, AH; BX =>BL, BH; CX => CL, CH; DX =>DL, DH.
Figure: Architecture of 8086
Note: All registers are of size 16-bits.
15CSL48 Microprocessor and Microcontroller Laboratory 2017-18
Dept of ISE,MIT Mysore Page 4
Different registers and their operations are listed below:
15CSL48 Microprocessor and Microcontroller Laboratory 2017-18
Dept of ISE,MIT Mysore Page 5
15CSL48 Microprocessor and Microcontroller Laboratory 2017-18
Dept of ISE,MIT Mysore Page 6
The Execution of Instructions in 8086:
The microprocessor sends OUT a 20-bit physical address to the memory and fetches the first
instruction of a program from the memory. Subsequent addresses are sent OUT and the queue
is filled up to 6 bytes. The instructions are decoded and further data (if necessary) are fetched
from memory. After the execution of the instruction, the results may go back to memory or to
the output peripheral devices as the case may be.
8086 Flag Register format
Programming Models: Depending on the size of the memory the user program occupies, different types of assembly
language models are defined.
TINY : All data and code in one segment
SMALL : one data segment and one code segment
MEDIUM : one data segment and two or more code segments
COMPACT : one code segment and two or more data segments
LARGE : any number of data and code segments
Assembly Language Development Tools:
1. EDITOR:
It’s system software (program) which allows users to create a file containing assembly
Instructions and statements. Ex: WordStar, DOS Editor, Norton Editor
Using the editor, you can also edit/delete/modify already existing files.
15CSL48 Microprocessor and Microcontroller Laboratory 2017-18
Dept of ISE,MIT Mysore Page 7
While saving, you must give the file extension as “.asm”.
Follow the AL syntax while typing the programs
Editor stores the ASCII codes for the letters and numbers keyed in.
Any statement beginning with semicolon is treated as comment. When you typed all
your program, you have to save the file on the disk. This file is called .source. file,
having a “.asm” extension. The next step is to convert this source file into a machine
2. ASSEMBLER:
An “assembler” is a system software (program) used to translate the assembly
language mnemonics for instructions to the corresponding binary codes.
An assembler makes two passes thro your source code. On the first pass, it determines
the displacement of named data items, the offset of labels etc., and puts this
information in a symbol table. On the second pass, the assembler produces the binary
code for each instruction and inserts the offsets, etc., that is calculated during the first
pass. The assembler checks for the correct syntax in the assembly instructions and
provides appropriate warning and error messages. You have to open your file again
using the editor to correct the errors and reassemble it using assembler. Unless all the
errors are corrected, the program cannot be executed in the next step.
The assembler generates two files from the source file; the first file, called the object
file having an extension “.obj” which contains the binary codes for instructions and
information about the addresses of the instructions. The second file is called “list file”
with an extension “.lst”. This file contains the assembly language statements, the
binary codes for each instruction, and the offset for each inst. It also indicates any
syntax errors or typing errors in the source program.
Note: The assembler generates only offsets (i.e., effective addresses); not absolute physical
Addresses.
3. LINKER:
It’s a program used to join several object files into one large object file. For large
programs, usually several modules are written and each module is tested and
debugged. When all the modules work, their object modules can be linked together to
form a complete functioning program.
The LINK program must be run on “.obj” file.
The linker produces a link file which contains the binary codes for all the combined
modules. The linker also produces a link map file which contains the address
information about the linked files.
The linker assigns only relative addresses starting from zero, so that this can be put
anywhere in physical primary memory later (by another program called .locator. or
15CSL48 Microprocessor and Microcontroller Laboratory 2017-18
Dept of ISE,MIT Mysore Page 8
.loader.). Therefore, this file is called relocatable. The linker produces link files with
“.exe” extension.
Object modules of useful programs (like square root, factorial etc) can be kept in a
library and linked to other programs when needed.
4. LOADER:
It is a program used to assign absolute physical addresses to the segments in the “.exe”
file, in the memory. IBM PC DOS environment comes with EXE2BIN loader
program. The “.exe” file is converted into “.bin” file
The physical addresses are assigned at run time by the loader. So, assembler does not
know about the segment starting addresses at the time program being assembled.
5. DEBUGGER:
If your program requires no external hardware; you can use a program called
debugger to load and run the “.exe” file.
A debugger is a program which allows you to load your object code program into
system memory, execute the program and troubleshoot or debug it. The debugger also
allows you to look at the contents of registers and memory locations after you run
your program.
The debugger allows you to change the contents of registers & memory locations and
rerun the program. Also, if facilitates to set up breakpoints in your program, single
step feature, and other easy-to-use features.
If you are using a prototype SDK 86 board, the debugger is usually called .monitor
program…
8255 Programmable Peripheral Interface:
8255 is a programmable peripheral IC which can be used to interface computer (CPU) to
various types of external peripherals such as: ADC, DAC, Motor, LEDs, 7-segment displays,
Keyboard, Switches etc. It has 3 ports A, B and C and a Control word register. User can
program the operation of ports by writing appropriate 8-bit “control word” into the control
word register.
15CSL48 Microprocessor and Microcontroller Laboratory 2017-18
Dept of ISE,MIT Mysore Page 9
Control Word format
How to write and execute LP using MASM?
Steps to be followed:
1. Type EDIT at the command prompt (C:\>\MASM\). A window will be opened with
all the options like File, Edit etc., In the workspace, type your program according to
the assembly language syntax and save the file with a “.asm” extension. (say test.asm)
2. Exit the Editor using File menu or pressing ALT + F + X.
3. At the prompt, type the command MASM followed by filename.asm (say, test.asm).
Press Enter key 2 or 3 times. The assembler checks the syntax of your program and
creates “.obj” file, if there are no errors. Otherwise, it indicates the error with line
numbers. You have to correct the errors by opening your file with EDIT command
and changing your instructions. Come back to DOS prompt and again assemble your
program using MASM command. This has to continue until MASM displays .0
Severe Errors.. There may still be .Warning Errors.. Try to correct them also.
4. Once you get the “.obj” file from step 3, you have to create the “.exe” file. At the
prompt, type the command LINK followed by “filename.obj” (say, test.obj) and press
Enter key. (Note that you have to give the extension now as “.obj” and not as “.asm”).
If there are no linker errors, linker will create “.exe” file of your program. Now, your
program is ready to run.
5. There are two ways to run your program.
a). If your program accepts user inputs through keyboard and displays the result on
the screen, then you can type the name of the file at the prompt and press Enter key.
Appropriate messages will be displayed.
b).If your program works with memory data and if you really want to know the
contents of registers, flags, memory locations assigned, opcodes etc., then type CV
test (file name) at the prompt. Another window will be opened with your program,
machine codes, register contents etc., Now, you also get a prompt > sign within CV
window. Here you can use .d. command to display memory contents, .E. command to
15CSL48 Microprocessor and Microcontroller Laboratory 2017-18
Dept of ISE,MIT Mysore Page 10
enter data into memory and .g. command to execute your program. Also, you can
single step thro. your program using the menu options. In many ways, CV (Code
View) is like Turbo C environment.
Once you are familiar with the architecture and basics of assembly language tools, you can
start typing and executing your program.
Procedure to write a program using MASM software
Start
↓
Run
↓
Type CMD
↓
Ok
Display shows
↓
C :\> D:
(Change to D drive because MASM is in D drive)
↓
Press ENTER
↓
D :\> CD MASM
↓
Press ENTER
↓
D: \MASM> EDIT FILENAME.ASM
Example edit <filename>.asm
↓
Press ENTER
↓
Then the display shows editor
↓
Type the asm program
↓
Then the save the program (Use Alt+F keys to appear the option window).
15CSL48 Microprocessor and Microcontroller Laboratory 2017-18
Dept of ISE,MIT Mysore Page 11
Instructions for Laboratory Exercises:
1. The programs with comments are listed for your reference. Write the programs in
observation book.
2. Create your own subdirectory in the computer. Edit (type) the programs with program
number and place them in your subdirectory. Have a copy of MASM.EXE, CV.EXE
and LINK.EXE files in your subdirectory. You can write comments for your
instructions using Semicolon (;) symbol.
3. Execute the programs as per the steps discussed earlier and note the results in your
observation book.
4. Make changes to the original program according to the questions given at the END of
each program and observe the outputs.
5. For part A programs, input-output is through computer keyboard and monitor or
through memory.
6. For part B programs, you need an external interface board. Connect the board to the
computer using the FRC available. Some boards may require external power supply
also.
7. Consult the Lab In-charge/Instructor before executing part B experiments.
8. The assembler is not case sensitive. However, we have used the following notation:
uppercase letters to indicate register names, mnemonics and assembler directives;
lowercase letters to indicate variable names, labels, segment names, and models.
15CSL48 Microprocessor and Microcontroller Laboratory 2017-18
Dept of ISE,MIT Mysore Page 12
SOFTWARE PROGRAMS: PART A
EXP NO: 1
BINARY SEARCH
Aim:
Design and develop an assembly language program to search a key element “X” in a list of
„n‟ 16-bit numbers. Adopt Binary search algorithm in your program for searching.
Program:
data segment
array dw 1023h,1024h,1025h,1026h,1027h
key dw 1025h
n dw 05h
pos dw ?
r dw ?
data ends
code segment
assume cs:code, ds:data
start: mov ax,data ;data segment initialization
mov ds,ax
lea si,array
mov ax,key ;initialize variables key=>ax, low=>bx ,high=>dx ,mid=>si &
tempReg=>cx
mov bx,00h
mov dx,n
dec dx
back: cmp bx,dx ;if(low>=high) goto unsuccess(0000h) else continue
ja unsuccess
mov cx,bx
add cx,dx ;mid=(low+high)/2
shr cx,01h
mov si,cx
add si,si
cmp ax,[si]
jz success ;if(key=a[mid]) then key element found goto success(0ffffh)
ja shalf ;if(key>a[mid]) then search second-half else search first-half
fhalf: mov dx,cx
dec dx ;high=mid-1
jmp back
shalf: mov bx,cx
inc bx ;low=mid+1
15CSL48 Microprocessor and Microcontroller Laboratory 2017-18
Dept of ISE,MIT Mysore Page 13
jmp back
unsuccess: mov r,0000h
jmp termi
success: mov r,0ffffh
mov pos,si ;move key element position into „pos‟
jmp termi
termi: int 03h
code ends
end start
Expected Output:
Trace the program after the debug command –t to get the location of SI then type the
command -d ds:0000 to find the declared array use the debug command –g for executing the
program go to the same location to find the element found or not found.
Result:
The program used the binary search algorithm to find a particular element from an array of
elements and at a specific location.
Input Output
The array elements are:
1023h,1024h,1025h,1026h,1027h
Search element: 1025
The array elements:
1023h,1024h,1025h,1026h,1027h
Search element: 1028h
FFFF in r
0000 in r
15CSL48 Microprocessor and Microcontroller Laboratory 2017-18
Dept of ISE,MIT Mysore Page 14
EXP NO: 2
BUBBLE SORT
Aim:
Design and develop an assembly program to sort a given set of „n‟ 16-bit numbers in
ascending order. Adopt Bubble Sort algorithm to sort given elements.
Algorithm:
Step 1: Declare the array with the numbers that need to be sorted.
Step 2 : Initialize iteration count (n-1)
Step 3 : Initialize comparison counter
Step 4 : Compare num1 and num2
Step 5 : Num1<=num2 do not exchange
Step 6 : Num1>=num2 then exchange the number positions
Step 7 : Decrement iteration counter, comparison counter
Step 8 : Terminate the program
Program:
data segment
array dw 1080h,1060h,1040h,1030h,1010h ;define 5 elements in unordered
list
count db 05h ;number of elements
data ends
code segment
assume cs:code, ds:data
start: mov ax,data ;data segment initialization
mov ds,ax
mov bl,count ;bl->number of iterations
dec bl
iter:lea si,array
mov cl,04h ;cl=>number of comparisons
cmpr:mov ax,[si] ;al=>temp register
add si,02h
cmp ax,[si] ;if(a[i]>a[i+1]) then swap them else do nothing
jbe skip ;replace jc by jnc for sorting in ascending order
swap: xchg ax,[si] ;swap a[i] and a[i+1]
xchg ax,[si-2]
skip: dec cl
jnz cmpr
dec bl
jnz iter
termi: int 03h
15CSL48 Microprocessor and Microcontroller Laboratory 2017-18
Dept of ISE,MIT Mysore Page 15
code ends
end start
Expected Output:
Trace the program after the debug command –t to get the location of SI then type the
command -d ds:0000 to find the declared array use the debug command –g for executing the
program go to the same location to find the sorted array.
Result: The 8086 assembly program sorts the declared array using bubble sort algorithm in
ascending order.
Output:
The array is sorted in ascending order using bubble sort algorithm
At source before
execution
1080 1060 1040 1030 1010
-g ( to execute)
At source after
execution
1010 1030 1040 1060 1080
15CSL48 Microprocessor and Microcontroller Laboratory 2017-18
Dept of ISE,MIT Mysore Page 16
EXP NO: 3
PALINDROME
Aim:
Develop an assembly language program to reverse a given string and verify whether it is a
palindrome or not. Display the appropriate message.
Procedure: The program illustrates the use of string instructions.
Initialize a pointer to end of the string.
Store the string in reverse order in some memory location.
Initialize one pointer to string and one more to the reversed string.
Compare both the strings character by character.
If all the characters match, display the message „Palindrome‟
Else display the message „Not Palindrome‟.
Algorithm:
Step 1 : Create display macro to display the message
Step 2 : Declare the string
Step 3 : Declare the message to display
Step 4 : Find the reverse of string and store in string1
Step 5 : Is string=string1,display it is a palindrome
Step 6 : Else if display not a palindrome
Step 7 : Terminate the program
Program:
disp macro msg
lea dx,msg
mov ah,09h
int 21h
endm
data segment
str1db "MADAM$"
len dw ($-str1)
str2 db 20 dup('$')
m1 db 10,13,"Success$"
m2 db 10,13,"Failure$"
data ends
code segment
assume cs:code, ds:data
start: mov ax,data ;data and extra segment initialization
mov ds,ax
mov es,ax
mov cx,len ;len=>CX
15CSL48 Microprocessor and Microcontroller Laboratory 2017-18
Dept of ISE,MIT Mysore Page 17
lea si,str1
lea di,str2
mov si,cx ;to point to last element
dec si
next:std ;set d=1 to process string in auto-decrement mode
lodsb ;load memory content pointed by SI into AL &
decrement SI
cld ;clear d=0 to process string in auto-increment mode
stosb ;store AL content into memory pointed by DI &
increment DI
loop next ;loop until CX=0
lea si,str1
lea di,str2
mov cx,len
repe cmpsb ;repeatedly compare byte in data segment pointed by SI
with byte in
jz success ;extra segment pointed by DI, also, increment SI & DI
;if all bytes are equal then goto success else goto
unsucces
unsuccess:disp m2 ;display message m2
jmp termi
success:disp m1 ;display message m1
jmp termi
termi:mov ah,04ch ;fun(4c) to terminate program
int 21h
code ends
end start
Expected output:
The string declared is checked with the original and reverse of the string and if the original
and the reverse is equal then it is palindrome else it is not a palindrome.
Result: The entered string is reversed and compared with the original string to see if it is a
palindrome or not, appropriate messages are displayed.
INPUT OUTPUT
MADAM/RACECAR/MALAYALAM PALINDROME
SIR/HELLO/WELCOME NOT A PALINDROME
15CSL48 Microprocessor and Microcontroller Laboratory 2017-18
Dept of ISE,MIT Mysore Page 18
EXP NO: 4
COMPUTE NCR USING RECURSIVE PROCEDURE
Aim: Develop an assembly language program to compute nCr using recursive procedure.
Assume that „n‟ and „r‟ are non-negative integers.
Procedure:
Input n and r.
If n = 0 and r = 0 , then res = 0
Else
Case i: If r = 0 or r = n then ncr = 1
Case ii: If r = 1 or r = n-1 then ncr = n
Else
Formula: nCr=( n-1) Cr + ( n-1) Cr-1
Program:
data segment
n db 05h
r db ?
res db 00h
data ends
code segment
assume cs:code, ds:data
start: mov ax,data
mov ds,ax
mov al,n
mov bl,r
call ncr
termi: mov ah,4ch
int 21h
ncr proc near
cmp bl,00 ;if r=0 then res=1
je exit1
cmp bl,01 ;if r=1 then res=n
je exit2
cmp bl,al ;if r=n then res=1
je exit1
dec al
cmp bl,al ;if r=n-1 then res=n
je exit3
15CSL48 Microprocessor and Microcontroller Laboratory 2017-18
Dept of ISE,MIT Mysore Page 19
push ax ;else nCr=
n-1Cr+
n-1Cr-1
push bx
call ncr
pop bx
pop ax
dec bl
push ax
push bx
call ncr
pop bx
pop ax
ret
exit1:inc res
ret
exit3:inc res
exit2:add res,al
ret
ncr endp
code ends
end start
Expected Result: The nCr is calculated using the recursive procedure. N and R are non-
negative integers. Result: For the value N=5, various cases of R and the result is shown in
below table.
Input Output
N=5 R=0 01H
N=5 R=1 05H
N=5 R=5 01H
N=5 R=4 05H
N=5 R=3 OAH
15CSL48 Microprocessor and Microcontroller Laboratory 2017-18
Dept of ISE,MIT Mysore Page 20
EXP NO: 5
READ THE CURRENT TIME AND DATE FROM THE SYSTEM AND DISPLAY
Aim:
Design and develop an assembly language program to read the current time and Date from the
system and display it in the standard format on the screen.
Procedure:
The program depicts the use of DOS routines.
DOS function 2Ch is used to read the system time.
To start with 2Ch is loaded in AH register and the respective function is called by interrupt
INT21h.
When this function is invoked
Register CH is loaded with hours
Register CL is loaded with minutes
Register DH is loaded with seconds
Register DL is loaded with hundredths of seconds.
In this program we read the time in hh:mm:ss format and display it.
To read Date, 2Ah is loaded in AH register and the respective function is called by interrupt
INT21h.
When this function is invoked
Register CX is loaded with year
Register DH is loaded with month
Register DL is loaded with the day.
In this program we read the date in dd:mm:yyyy format and display it.
Algorithm:
Step1 : Create display message macro to display the message
Step2 : Create dis macro for displaying two digits after converting to ascii.
Step3 : Create main program.
Step4 : Call display message.
Step5 : Use INT 21H function 02ch to get the system time.
Step6 : Call dis macro to display hours
Step7 : Call dis macro to display minutes
Step8 : Call dis macro to display seconds.
Step9 : The system date is displayed on the screen
Step10 :Terminate the program.
Program:
disp macro msg ;macro to display message on screen
lea dx,msg ;dx contains offset address of string to be displayed
mov ah,09h ;function(09)/int 21h to display string on screen
int 21h
endm
data segment
15CSL48 Microprocessor and Microcontroller Laboratory 2017-18
Dept of ISE,MIT Mysore Page 21
msg1 db 10,13, “the current system time is:$”
msg2 db 10,13, “the current system date is:$”
data ends
code segment
assume ds:data, cs:code
start: mov ax,data ;data segment initialization
mov ds,ax
disp msg1 ;displays the current system time is:
call systime ;subroutine
disp msg1 ;displays the current system date is:
call systime ;subroutine
termi: mov ah,4ch ;function(4c)/int 21h to terminate program
int 21h
systime proc near
mov ah,2ch ;function(2c)/int 21h to get system time CH=hr, CL=min & DH=s
mov al,ch
aam ;to convert packed-BCD into unpacked-BCD & to display hr
mov bx,ax
call show
mov dl,':' ;dl contains a character
mov ah,02h ;function(02)/int 21h to display a character on screen
int 21h
mov al,cl
aam ;to convert packed-BCD into unpacked-BCD & to display min
mov bx,ax
call show
mov dl,':' ;dl contains a character
mov ah,02h ;function(02)/int 21h to display a character on screen
int 21h
mov al,dh
aam ;to convert packed-BCD into unpacked-BCD & to
display sec
mov bx,ax
call show
ret
systime endp
sysdate proc near
mov ah,2ah ;function(2a)/int 21h to get system date CX=Year, DH=Month & DL=Day
int 21h
15CSL48 Microprocessor and Microcontroller Laboratory 2017-18
Dept of ISE,MIT Mysore Page 22
mov al,dl
aam ;to convert packed-BCD into unpacked-BCD & to display date
mov bx,ax
call show
mov dl,'/' ;dl contains a character
mov ah,02h ;function(02)/int 21h to display a character on screen
int 21h
mov al,dh
aam ;to convert packed-BCD into unpacked-BCD & to display
month
mov bx,ax
call show
mov dl,'/' ;dl contains a character
mov ah,02h ;function(02)/int 21h to display a character on screen
int 21h
mov dx,0 ; to display year
mov ax,cx
mov bl,100
div bl
aam
mov bx,ax ; to convert packed-BCD into unpacked-BCD & to display 1st two digits
call show
mov al,dl
aam ;to convert packed-BCD into unpacked-BCD & to display last two digits
mov bx,ax
call show
ret
sysdate endp
show proc near ;subroutine to display a character on screen
mov dl,bh
add dl,30h ;obtain ASCII code of digit in BH
mov ah,02h ;function(02)/int 21h to display a character on screen
int 21h
mov dl,bl
add dl,30h ;obtain ASCII code of digit in BL
mov ah,02h ;function(02)/int 21h to display a character on screen
int 21h
ret
show endp
code ends
end start
15CSL48 Microprocessor and Microcontroller Laboratory 2017-18
Dept of ISE,MIT Mysore Page 23
Expected output:
The current time from the system is displayed in the standard format on the screen.
Result:
The current time and date from the system is displayed.
CURRENT SYSTEM TIME IS 11:30:30
CURRENT SYSTEM DATE IS 12:03:2018
15CSL48 Microprocessor and Microcontroller Laboratory 2017-18
Dept of ISE,MIT Mysore Page 24
EXP NO: 6
ARM ASSEMBLY LANGUAGE PROGRAMS
Aim:
To write and simulate ARM assembly language programs for data transfer, arithmetic
And logical operations (Demonstrate with the help of a suitable program).
Program:
; PROGRAM TO TRANSFER DATA FROM CODE AREA TO DATA AREA
; COMPILE AND DEBUG PROGRAM
; SET BREAKPOINT AT NOP INSTRUCTION
; PRESS F11 TO RUN THE PROGRAM
; HAVE MEMORY1 WINDOW OPENED AND SET ADDRESS AT 0X40000000
; AND AFTER EXECUTION CHECK 0X44444444 APPEAR AT MEMORY1 WINDOW
a. data transfer
area largest , code, readonly
start
ldr r0,=var1 ; loads the address of first value
ldr r1,[r2],#4 ; word align t0 array element
ldr r2,=result ; loads the address of result
str r1,[r2] ; stores the result in r2
; array of 32 bit numbers(n=7)
b. arithmetic
ldr r3,=0x00000005
ldr r4,=0x00000003
add r5,r3,r4
sub r6,r3,r4
mul r7,r3,r4
c. logical
and r8,r3,r4
orr r9,r3,r4
eor r10,r3,r4
nop
nop
nop
var1 dcd 0x00000045
area datafield,data,readony
result dcd 0x0
end
15CSL48 Microprocessor and Microcontroller Laboratory 2017-18
Dept of ISE,MIT Mysore Page 25
EXP NO: 7
C PROGRAMS FOR ARM MICROPROCESSOR USING KEIL
Aim:
To write and simulate C Programs for ARM microprocessor using KEIL (Demonstrate with
the help of a suitable program).
Program:
#include <lpc214x.h>
void main(void)
{
int a,b,add,sub,mul,div,and,orr,not,xor,mod;
a=4;
b=5;
add=a+b;
sub=a-b;
mul=a*b;
div=a/b;
orr=a|b;
and=a&b;
not=~a;
xor=a^b;
mod=a%b;
return0;
}
15CSL48 Microprocessor and Microcontroller Laboratory 2017-18
Dept of ISE,MIT Mysore Page 26
HARDWARE PROGRAMS: PART B
EXP NO:8A
BCD Up-Down Counter (00-99) on the Logic Controller Interface.
Aim:
Design and develop an assembly program to demonstrate BCD Up-Down Counter (00-99)
on the Logic Controller Interface.
Algorithm:
Step 1: Create a delay macro
Step 2: Create an up procedure to count form 00-99
Step 3: Send the initial value 0 to the logic controller interface, sense a key
15CSL48 Microprocessor and Microcontroller Laboratory 2017-18
Dept of ISE,MIT Mysore Page 27
from the keyboard to stop
Step 4: Call the up procedure
Step 5: Increment the value and send it to output until it reaches a value
greater than 99
Step 6: Call the down procedure to count from 99-00
Step 7: Decrement the value to be sent to the output until it reaches the
value 0
Step 8: Repeat the steps from step2, until any key is pressed from the
Keyboard.
Step 9: Terminate the program
Program:
disp macro msg
mov ah,09h
lea dx,msg
int 21h
endm
data segment
portA dw 0b0coh
portB dw 0b0c1h
portC dw 0b0c2h
cr dw 0b0c3h
data ends
code segment
assume cs:code, ds:data
start: mov ax,data ;data segment initialization
mov ds,ax
mov al,82h ;control register initialization
mov dx,cr ;porta=output portb=input
out dx,al
mov cx,63H ;cx=counter
mov al,1 ;load first value
back1:mov dx, portA ;display the value via portA
out dx,al
call delay ;cause delay
inc al ;increment to get next value
dec cx
jnz back1
mov cx,63H ;cx=counter
mov al,63H ;load first value
back2:mov dx, portA ;display the value via portA
out dx,al
call delay ;cause delay
15CSL48 Microprocessor and Microcontroller Laboratory 2017-18
Dept of ISE,MIT Mysore Page 28
dec al ;increment to get next value
dec cx
jnz back2
termi:mov ah,4ch
int 21h
delay proc near
push ax
push bx
push cx
push dx
mov ax,5000h
back2:mov cx,0ffffh
back1:dec cx
jnz back1
dec ax
jnz back2
pop dx
pop cx
pop bx
pop ax
ret
delay endp
code ends
end start
Expected Result: The LED of the logic controller glows from 00-99 and 99-00 until key is
pressed on the keyboard to stop.
Result: The output shows the behavior of a BCD UP-DOWN Counter.
15CSL48 Microprocessor and Microcontroller Laboratory 2017-18
Dept of ISE,MIT Mysore Page 29
EXP NO:8B
DISPLAY X*Y ON THE LOGIC CONTROLLER INTERFACE
Aim:
Design and develop an assembly program to read the status of two 8-bit inputs (X & Y) from
the Logic Controller Interface and display X*Y.
Algorithm:
Step1: Give the input value of X from the interface
Step 2: Read the input from the logic controller
Step 3: Repeat step1 and step2 for y value
Step 4: Multiply X*Y
Step 5: The result is shown on the LED of the interface, first the LSB is
shown on the led then the MSB is seen on the led
Step 6: Sense any key on the keyboard
Step 7: Terminate the program
Program:
disp macro msg
mov ah,09h
lea dx,msg
int 21h
endm
read macro
mov ah,01h
int 21h
endm
data segment
portA dw 0b0c0h
portB dw 0b0c1h
portC dw 0b0c2h
cr dw 0b0c3h
m1 db 10,13, “enter first operand $”
m2 db 10,13, ”enter second operand $”
op1 db 00h
op2 db 00h
data ends
code segment
assume cs:code,ds:data
start: mov ax,data ;data segment initialization
mov ds,ax
mov al,82h ;control register initialization
mov dx,cr ;portA=output portB=input
out dx,al
15CSL48 Microprocessor and Microcontroller Laboratory 2017-18
Dept of ISE,MIT Mysore Page 30
disp m1
read
mov dx, portB
in al,dx ;read 1st data via portB
mov op1,al
disp m2
read
mov dx, portB
in al,dx ;read 2nd
data via portB
mov op2,al
mov al,op1
mov bl,op2 ;al=al*bl
mul bl
mov dx, portA ;display product via portA
out dx,al
termi:mov ah,4ch
int 21h
code ends
end start
Expected Result:
The input of x and y is given from the input port by switching on/off the 8 switches e.g.
x=00000010 & y=00000100, then x*y=00001000 that is x=2, y=4 x*y=8. The result is
specified by the equivalent glowing of LED‟S
Result:
The result is seen at the output port of the interface, the LED‟S glow according the result of
multiplication the lower byte is displayed first, press enter the higher byte is displayed.
Input given to the logic controller Output displayed on the logic controller
X=00000101, Y=00000010 X*Y=00010101
X=00000011 ,Y=00000101 X*Y=00010101
15CSL48 Microprocessor and Microcontroller Laboratory 2017-18
Dept of ISE,MIT Mysore Page 31
EXP NO:9
DISPLAY MESSAGES ALTERNATIVELY
Aim:
Design and develop an assembly program to display messages “FIRE” and “HELP”
alternately with flickering effects on a 7-segment display interface for a suitable period of
time. Ensure a flashing rate that makes it easy to read both the messages (Examiner does not
specify these delay values nor is it necessary for the student to compute these values).
Algorithm:
Step1: Create delay macro, initialize count to display no of times and the
number of characters.
Step 2: Declare the 7 segment codes of the characters that is to be
displayed(FIRE BLANK HELP)
Step3 : Call display procedure to display FIRE
Step4 : Call display procedure to display BLANK
Step5: Call display procedure to display HELP
Step 6: Select the 7-segment position, send data to be displayed
Step7 : Sense if any key is pressed on the keyboard
Step8: Call delay
Step 9: Repeat to display all characters step 2 to step 6
15CSL48 Microprocessor and Microcontroller Laboratory 2017-18
Dept of ISE,MIT Mysore Page 32
Program:
data segment
array1 db 079h,0f7h,030h,071h,00h,00h ;hexadecimal value of FIRE in reverse
order
array2 db 073h,038h,079h,076h,00h,00h ;hexadecimal value of HELP in reverse
order
pa dw 0b0c0h
pb dw 0b0c1h
pc dw 0b0c2h
pr dw ob0c3h
data ends
code segment
assume cs:code,ds:data
start:mov ax,data ;data segment initialization
mov ds,ax
mov dx,cr ;control register initialization
mov al,80h ;portA=output portC=output portB=not used
out dx,al
mov di,04h ;di=no 0f times to display FIRE/HELP
again:mov ch,50d
line1:mov cl,00h ;select first position
lea bx,array1
chr1:mov dx,pc ;select position of character (0th
t0 5th
) via portc
mov al,cl
out dx,al
15CSL48 Microprocessor and Microcontroller Laboratory 2017-18
Dept of ISE,MIT Mysore Page 33
xlat ;obtain 7-segment value of character from lookup table
mov dx,pa ;send 7 segment value via porta
out dx,al
call delay
inc cl ;increment to select position of next character to be displayed
cmp cl,05h ;check if 5th
position is reached
jne chr1
dec ch
jnz line1
mov ch,50d
line2:mov cl,00h ;select first position
lea bx,array2
chr2:mov dx,pc ;select position of character (0th
t0 5th
) via portc
mov al,cl
out dx,al
xlat ;obtain 7-segment value of character from lookup table
mov dx,pa ;send 7 segment value via porta
out dx,al
call delay
inc cl ;increment to select position of next character to be displayed
cmp cl,05h ;check if 5th
position is reached
jne chr2
dec ch
jnz line2
dec di
jnz again
stop:mov ah,4ch
int 21h
delay proc near
push ax
push bx
push cx
push dx
mov bx,05ffh
b2:mov cx,0fffh
b1:dec cx
Jnz b1
dec bx
Jnz b2
pop dx
pop cx
pop bx
pop ax
ret
delay endp
15CSL48 Microprocessor and Microcontroller Laboratory 2017-18
Dept of ISE,MIT Mysore Page 34
code ends
end start
Expected result: The 7 segment interface needs to display FIRE and HELP blinking
alternately.
Result:
Input data to be displayed Output data to be displayed
FIRE HELP on the 7 segment
display (BLINKING)
FIRE HELP on the 7 segment
display (BLINKING)
15CSL48 Microprocessor and Microcontroller Laboratory 2017-18
Dept of ISE,MIT Mysore Page 35
EXP NO:10 STEPPER MOTOR IN BOTH DIRECTIONS
Aim:
Design and develop an assembly program to drive a Stepper Motor interface and rotate the
motor in specified direction (clockwise or counter-clockwise) by N steps (Direction and N
are specified by the examiner). Introduce suitable delay between successive steps. (Any
arbitrary value for the delay may be assumed by the student).
Algorithm:
Step1: Create delay macro
Step2: Initialize the steps in which the stepper motor should rotate.
Step3: Set the phase value
Step4: Send the values to the motor to rotate
Step5: Call delay between steps
Step 6: Set the direction by rotating the value of phase
Step 7: Repeat step 2 to step 5 until steps=0
Step 8: Terminate the program
15CSL48 Microprocessor and Microcontroller Laboratory 2017-18
Dept of ISE,MIT Mysore Page 36
Program:
data segment
portA dw 0b0c0h
portB dw 0b0c1h
portC dw 0b0c2h
cr dw 0b0c3h
data segment
code segment
assume cs:code, ds:data
start: mov ax,data ;data segment initialization
mov ds,ax
mov al,80h ;control register initialization
mov dx,cr ;portC=output
outdx,al
mov cx,08h ;cx=counter
mov al,0eeh ;energize A as first coil
back1:mov dx,portC
out dx,al ;energize each coil via portA
call delay
ror al,1 ;rotate right to energize each coil(A=>B=>C=>D=>A=>B=>C=>D)
dec cx
jnz back1
mov cx,0Ah ;cx=counter
mov al,0eeh ;energize D as first coil
back2:mov dx,portC
out dx,al ;energize each coil via portA
call delay
rol al,1 ;rotate left to energize each coil(D=>C=>B=>A=>D=>C=>B=>A)
dec cx
jnz back2
stop: mov ah,4ch
int 21h
delay proc near ;procedure to cause delay
push ax
pushbx
push cx
push dx
mov cx,06000h
z2: mov ax,0ffffh
z1: dec ax
jnz z1
dec cx
jnz z2
15CSL48 Microprocessor and Microcontroller Laboratory 2017-18
Dept of ISE,MIT Mysore Page 37
pop dx
pop cx
popbx
pop ax
ret
delay endp
code ends
end start
Expected Result:
The stepper motor rotates in clockwise or anti-clock wise direction in specified number of
steps.
Result:
Input no of steps the motor rotates output
8 The motor rotates in steps of 8 clockwise
10 The motor rotates in steps of 10
anticlockwise
15CSL48 Microprocessor and Microcontroller Laboratory 2017-18
Dept of ISE,MIT Mysore Page 38
EXP NO: 11A
GENERATE SINE-WAVE
Aim:
Design and develop an assembly language program to generate the Sine Wave Using DAC
interface (The output of the DAC is to be displayed on the CRO).
Algorithm:
Step1: Initialize the values for generating Sine Wave.
Step2: Initialize count to the number of values to be plotted.
Step3: Send the values to DAC and plot on CRO.
Step4: Decrement count.
Step5: Repeat step3 until count becomes zero.
Step6: Sense the keyboard input to stop the program
Step7: Terminate the program
15CSL48 Microprocessor and Microcontroller Laboratory 2017-18
Dept of ISE,MIT Mysore Page 39
Program:
data segment
porta dw 0b090h
cr dw 0b093h
table db 80h,96h,0abh,0c1h,0d2,0e2h,0ech,0f8h,0feh
db 0ffh,0feh,0f8h,0ech,0e2h,0d2h,0c1h,0abh,096h
db 80h, 69h,54h,40h,2dh,1dh,11h,07h,01h
db 00h,01h,07h,11h,1dh,2dh,40h,54h,69h
data ends
code segment
assume cs:code, ds:data
start: mov ax,data
movds,ax
mov al,80h
movdx,cr
out dx,al
again: lea si,table
mov cx,36
back: mov al,[si]
mov dx,porta
out dx,al
call delay
inc si
dec cx
jnz back
mov ah,01h
int 16h
jz again
stop: mov ah,4ch
int 21h
delay proc
mov bx,0ffffh
back1:dec bx
jnz back1
ret
delay endp
code ends
end start
Expected Result:
Sine wave is generated using DAC interface and output is observed on the
CRO.
15CSL48 Microprocessor and Microcontroller Laboratory 2017-18
Dept of ISE,MIT Mysore Page 40
Result:
Sine wave is generated using the DAC interface.
15CSL48 Microprocessor and Microcontroller Laboratory 2017-18
Dept of ISE,MIT Mysore Page 41
EXP NO: 11B
HALF RECTIFIED SINE WAVEFORM USING THE DAC
Aim:
Generate a Half Rectified Sine waveform using the DAC interface. (The output of the DAC is
to be
displayed on the CRO).
Algorithm:
Step 1: Initialize the values for generating Half Rectified Sine Wave.
Step 2: Initialize count to the number of values to be plotted.
Step 3: Send the values to DAC and plot on CRO.
Step 4: Decrement count.
Step 5: Repeat step3 until count becomes zero.
Step 6: Sense the keyboard input to stop the program
Step 7: Terminate the program
Program:
data segment
porta dw 0b0c0h
cr dw 0b0c3h
table db 80h,96h,0abh,0c1h,0d2,0e2h,0ech,0f8h,0feh
db 0ffh,0feh,0f8h,0ech,0e2h,0d2h,0c1h,0abh,096h
db 80h,80h,80h,80h,80h,80h,80h,80h,80h
db 80h,80h,80h,80h,80h,80h,80h,80h,80h
data ends
code segment
assume cs:code, ds:data
start: mov ax,data
movds,ax
mov al,80h
movdx,cr
out dx,al
again: lea si,table
mov cx,36
back: mov al,[si]
mov dx,porta
out dx,al
call delay
inc si
dec cx
jnz back
mov ah,01h
int 16h
15CSL48 Microprocessor and Microcontroller Laboratory 2017-18
Dept of ISE,MIT Mysore Page 42
jz again
stop: mov ah,4ch
int 21h
delay proc
mov bx,0ffffh
back1:dec bx
jnz back1
ret
delay endp
code ends
end start
Expected output: The Half Rectified Sine waveform is observed in the CRO.
15CSL48 Microprocessor and Microcontroller Laboratory 2017-18
Dept of ISE,MIT Mysore Page 43
EXP NO: 12
INTERFACE LCD WITH ARM PROCESSOR
Aim:
To interface LCD with ARM processor-- ARM7TDMI/LPC2148. Write and execute programs
in C language for displaying text messages and numbers on LCD.
Program:
#include<lpc214x.h>
#include<stdio.h>
//Function prototypes
void lcd_init(void);
void wr_cn(void);
void clr_disp(void);
void delay(unsigned int);
void lcd_com(void);
void wr_dn(void);
void lcd_data(void);
unsigned char temp1;
unsigned long int temp, r=0;
unsigned char *ptr,disp[] = "MIT MYSURU",disp1[]="LCD INTERFACING";
int main()
{
PINSEL0 = 0X00000000; // configure P0.0 TO P0.15 as GPIO
IO0DIR = 0x000000FC; //configure o/p lines for lcd [P0.2-P0.7]
lcd_init(); //lcd initialisation
delay(3200); // delay 1.06ms
clr_disp(); //clear display
delay(3200); // delay 1.06ms
temp1 = 0x81; //Display starting address of first line 2nd pos
lcd_com(); //function to send command to lcd
ptr = disp; // pointing data
while(*ptr!='\0')
{
temp1 = *ptr;
lcd_data(); //function to send data to lcd
ptr ++;
}
temp1 = 0xC0; // Display starting address of second line 1st pos
lcd_com(); //function to send command to lcd
ptr = disp1; // pointing second data
while(*ptr!='\0')
15CSL48 Microprocessor and Microcontroller Laboratory 2017-18
Dept of ISE,MIT Mysore Page 44
{
temp1 = *ptr;
lcd_data(); //send data to lcd ptr ++;
}
while(1);
} //end of main()
// lcd initialisation routine.
void lcd_init(void)
{
temp = 0x30; //command to test LCD voltage level
wr_cn();
delay(3200);
temp = 0x30; //command to test LCD voltage level
wr_cn();
delay(3200);
temp = 0x30; //command to test LCD voltage level
wr_cn();
delay(3200);
temp = 0x20; // change to 4 bit mode from default 8 bit mode
wr_cn();
delay(3200);
temp1 = 0x28; // load command for lcd function setting with lcd in 4 bit mode,
lcd_com(); // 2 line and 5x7 matrix display delay(3200);
temp1 = 0x0C; // load a command for display on, cursor on and blinking off
lcd_com();
delay(800);
temp1 = 0x06; // command for cursor increment after data dump
lcd_com();
delay(800);
temp1 = 0x80; // set the cursor to beginning of line 1
lcd_com();
delay(800);
}
void lcd_com(void)
{
temp = temp1 & 0xf0; //masking higher nibble first wr_cn();
temp = temp1 & 0x0f; //masking lower nibble temp = temp << 4;
wr_cn();
delay(500); // some delay
}
15CSL48 Microprocessor and Microcontroller Laboratory 2017-18
Dept of ISE,MIT Mysore Page 45
// command nibble o/p routine
void wr_cn(void) //write command reg
{
IO0CLR = 0x000000FC; // clear the port lines.
IO0SET = temp; // Assign the value to the PORT lines
IO0CLR = 0x00000004; // clear bit RS = 0
IO0SET = 0x00000008; // E=1
delay(10);
IO0CLR = 0x00000008; //E=0
}
// data nibble o/p routine
void wr_dn(void) ////write data reg
{
IO0CLR = 0x000000FC; // clear the port lines.
IO0SET = temp; // Assign the value to the PORT lines
IO0SET = 0x00000004; // set bit RS = 1
IO0SET = 0x00000008; // E=1
delay(10);
IO0CLR = 0x00000008; //E=0
}
// data o/p routine which also outputs high nibble first
// and lower nibble next
Void lcd_data(void)
{
temp = temp1 & 0xf0; //masking higher nibble first temp = temp ;
wr_dn();
temp= temp1 & 0x0f; //masking lower nibble
temp= temp << 4; //shift 4bit to left wr_dn();
delay(100);
}
void clr_disp(void) // function to clear the LCD screen
{
temp1 = 0x01;
lcd_com();
delay(500);
}
void delay(unsigned int r1) // delay function using for loop
{
for(r=0;r<r1;r++);
}
15CSL48 Microprocessor and Microcontroller Laboratory 2017-18
Dept of ISE,MIT Mysore Page 46
EXP NO: 13
TO INTERFACE STEPPER MOTOR WITH ARM PROCESSOR
Aim:
To interface Stepper motor with ARM processor-- ARM7TDMI/LPC2148. Write a program to
rotate stepper motor.
Program:
#include <LPC21xx.h>
void clock_wise(void) ;
void anti_clock_wise(void) ;
unsigned int var1 ;
unsigned long int i = 0 , j = 0 , k = 0 ;
int main(void)
{
PINSEL2 = 0x00000000; //P1.20 to P1.23 GPIO
IO1DIR |= 0x00F00000 ; //P1.20 to P1.23 made as output
while(1)
{
for( j = 0 ; j < 50 ; j++ ) // 50 times in Clock wise Rotation
clock_wise() ; // rotate one round clockwise
for( k = 0 ; k < 65000 ; k++ ) ; // Delay to show anti_clock Rotation
for( j=0 ; j < 50 ; j++ ) // 50 times in Anti Clock wise Rotation
anti_clock_wise() ; // rotate one round anticlockwise
for( k = 0 ; k < 65000 ; k++ ) ; // Delay to show ANTI_clock Rotation
}
} // End of main
void clock_wise(void)
{
var1 = 0x00080000; //For Clockwise
for( i = 0 ; i <= 3 ; i++ ) // for A B C D Stepping
{
var1 <<= 1 ;
IO1CLR =0x00F00000 ; //clearing all 4 bits
IO1SET = var1; // setting particular bit
for( k = 0 ; k < 3000 ; k++ ); //for step speed variation
}
}
void anti_clock_wise(void)
{
var1 = 0x00800000 ; //For Anticlockwise
15CSL48 Microprocessor and Microcontroller Laboratory 2017-18
Dept of ISE,MIT Mysore Page 47
IO1CLR =0x00F00000 ; //clearing all 4bits
IO1SET = var1 ;
for( k = 0 ; k < 3000 ; k++ ) ;
for( i = 0 ; i < 3 ; i++ ) // for A B C D Stepping
{
var1 >>=1; //rotating bits
IO1CLR =0x00F00000 ; // clear all bits before setting
IO1SET = var1; // setting particular bit
for( k = 0 ; k < 3000 ; k++ ) ; //for step speed variation
}
}
15CSL48 Microprocessor and Microcontroller Laboratory 2017-18
Dept of ISE,MIT Mysore Page 48
ADDITIONAL PROGRAMS
1) PROGRAM TO ADD 2 NUMBERS
code segment
assume cs: code
start: mov al,3 ;read 2 numbers
mov bl,2
add al,bl ;compute sum
mov cl,al ;output result
int 03h
code ends
end start
2) PROGRAM TO ADD TWO 8 BIT NUMBERS PRESENT IN MEMORY
data segment
x db 3
y db 2
z db ?
data ends
code segment
assume cs: code, ds: data
start: mov ax,data ;data segment initialization
mov ds,ax
mov al,x ;read 2 numbers
mov bl,y
add al,bl ;compute sum ie al=al+bl
mov z,al ;output result
termi: int 03h
code ends
end start
3) PROGRAM TO SUBTRACT y FROM x
data segment
x db 3
y db 2
z db ?
data ends
code segment
assume cs: code, ds: data
start: mov ax,data ;data segment initialization
mov ds,ax
15CSL48 Microprocessor and Microcontroller Laboratory 2017-18
Dept of ISE,MIT Mysore Page 49
mov al,x ;read 2 numbers
mov bl,y
sub al,bl ;compute difference
mov z,al ;output result
termi: int 03h
code ends
end start
4) PROGRAM TO ADD 3 NUMBERS PRESENT IN MEMORY
data segment
x db 3
y db 2
z db 1
p db ?
data ends
code segment
assume cs: code, ds: data
start: mov ax,data ;data segment initialization
mov ds,ax
mov al,x ;read 2 numbers
mov bl,y
mov cl,z
add al,bl ;compute sum
add al,cl
mov p,al ;output result
termi:int 03h
code ends
end start
5) PROGRAM TO FIND AVERAGE OF 2 NUMBERS PRESENT IN MEMORY
data segment
x db 3
y db 2
z db ?
data ends
code segment
assume cs:code, ds: data
start: mov ax,data ;data segment initialization
mov ds,ax
mov al,x ;read 2 numbers
mov bl,y
add al,bl ;compute sum
shr al,1 ;compute sum/2
15CSL48 Microprocessor and Microcontroller Laboratory 2017-18
Dept of ISE,MIT Mysore Page 50
mov z,al ;output result
termi:int 03h
code ends
end start
6) PROGRAM TO ADD TWO 16 BIT NUMBERS PRESENT IN MEMORY
data segment
x dw 3
y dw 2
z dw ?
data ends
code segment
assume cs:code, ds:data
start: mov ax,data ;data segment initialization
mov ds,ax
mov ax,x
mov bx,y
add ax,bx
mov z,ax
termi:int 03h
code ends
end start
7) PROGRAM TO MULTIPLY 2 NUMBERS PRESENT IN MEMORY
data segment
x dw 3
y db 2
z dw ?
data ends
code segment
assume cs:code, ds:data
start: mov ax,data ;data segment initialization
mov ds,ax
mov ax,x ;read 2 numbers
mov bl,y
mul bl ;compute product(ax=ax*bl)
mov z,ax ;output result
termi:int 03h
code ends
end start
8) PROGRAM TO PERFORM DIVISION
data segment
x dw 7
15CSL48 Microprocessor and Microcontroller Laboratory 2017-18
Dept of ISE,MIT Mysore Page 51
y db 3
r db ?
q db ?
data ends
code segment
assume cs: code, ds: data
start: mov ax,data ;data segment initialization
mov ds,ax
mov ax,x ;read 2 numbers
mov bl,y
div bl ;perform division (ax=ax/bl)
mov q,al ;after division al-> quotient ah->remainder
mov e,ah
termi:int 03h
code ends
end start
9) PROGRAM TO DISPLAY A MESSAGE ON THE SCREEN
data segment
msg db “WELCOME TO MICROPROCESSOR LAB $”
data ends
code segment
assume cs:code, ds: data
start: mov ax,data ;data segment initialization
mov ds,ax
lea dx,msg ;dx contains offset address of message to be displayed
mov ah,09h ;fun(09h)/int 21h to display a message
int 21h
termi:mov ah,4ch ;fun(4ch)/int 21h to terminate program normally
int 21h
code ends
end start
10) PROGRAM TO DISPLAY A CHARACTER ON THE SCREEN
data segment
msg db “DISPLAYED CHARACTER: $”
data ends
code segment
assume cs:code, ds:data
start: mov ax,data ;data segment initialization
mov ds,ax
15CSL48 Microprocessor and Microcontroller Laboratory 2017-18
Dept of ISE,MIT Mysore Page 52
lea dx,msg
mov ah,09h ;fun(09h)/int 21h to display a message
int 21h
mov dl,‟z‟
mov ah,02h ;fun(02h)/int 21h to display a character
int 21h
termi:mov ah,4ch ;fun(4ch)/int 21h to terminate program normally
int 21h
code ends
end start
11) PROGRAM TO READ AND DISPLAY A CHARACTER ON THE SCREEN
data segment
msg db “ENTER ONE CHARACTER: $”
data ends
code segment
assume cs:code, ds:data
start: mov ax,data ;data segment initialization
mov ds,ax
lea dx,msg
mov ah,09h ;fun(09h)/int 21h to display a message
int 21h
mov ah,01h ;fun(01h)/int 21h to read a character
int 21h
mov dl,al
mov ah,02h ;fun(02h)/int 21h to display a character
int 21h
termi:mov ah,4ch ;fun(4ch)/int 21h to terminate program normally
int 21h
code ends
end start
12) PROGRAM TO SET CURSOR POSITION
code segment
assume cs:code
start: mov ah,00h ;fun(03h)/int 10h to clear screen
mov al,03h
int 10h
mov ah,02h ;fun(02h)/int 10h to set cursor position
mov dh,10 ;dh-> row num(00-18h)
mov dl,10 ;dl->col num(00-49h)
int 10h
15CSL48 Microprocessor and Microcontroller Laboratory 2017-18
Dept of ISE,MIT Mysore Page 53
mov ah,01h ;fun(01h)/int 21h to read a character III getch()
int 21h
termi:mov ah,4ch ;fun(4ch)/int 21h to terminate program normally
int 21h
code ends
end start
13) PROGRAM TO DISPLAY A MESSAGE USING MACRO
disp macro msg
lea dx,msg ;dx contains offset address of message to be displayed
mov ah,09h ;fun(09h)/int 21h to display a message
int 21h
endsm
data segment
msg db “WELCOME TO MICROPROCESSOR LAB $”
data ends
code segment
assume cs:code, ds: data
start: mov ax,data
mov ds,ax
disp msg
mov ah,4ch ;fun(4ch)/int 21h to terminate program normally
int 21h
code ends
end start
14) PROGRAM TO SET CURSOR POSITION USING MACRO
clear macro
mov ah,00h ;fun(03h)/int 10h to clear screen
mov al,03h
int 10h
endm
setcur macro
mov ah,02h ;fun(02h)/int 10h to set cursor position
mov dh,10
mov dl,10
int 10h
endm
read macro
mov ah,01h ;fun(01h)/int 21h to read a character III getch()
int 21h
endm
15CSL48 Microprocessor and Microcontroller Laboratory 2017-18
Dept of ISE,MIT Mysore Page 54
code segment
assume cs:code
start: clear
setcur
read
mov ah,4ch ;fun(4ch)/int 21h to terminate program normally
int 21h
code ends
end start
15) PROGRAM TO COPY A BLOCK OF DATA FROM ONE MEMORY
LOCATION TO ANOTHER
data segment
blk1 db 23h,24h,25h,26h
blk2 db 5 dup(?)
count db 04h
data ends
code segment
assume cs:code, ds:data
start: mov ax,data ;data segment initialization
mov ds,ax
mov cx, count
lea si, blk1
lea di, blk2
back:mov al,[si]
mov [di],al
inc si
inc di
dec cx
jnz back
termi: int 03h
code ends
end start
15CSL48 Microprocessor and Microcontroller Laboratory 2017-18
Dept of ISE,MIT Mysore Page 55
VIVA QUESTIONS WITH ANSWERS
1. What is a Microprocessor?
ANS: Microprocessor is a program-controlled device, which fetches the instructions from
memory, decodes and executes the instructions. Most Micro Processors are single- chip
devices.
2. What is the difference between 8086 and 8088?
ANS: The BIU in 8088 is 8-bit data bus & 16- bit in 8086.Instruction queue is 4 byte long in
8088and 6 byte in 8086.
3. What are the functional units in 8086?
ANS: 8086 has two independent functional units because of that the processor speed is more.
The Bus interface unit and Execution unit are the two functional units.
4. What are the flags in 8086?
ANS: In 8086 Carry flag, Parity flag, Auxiliary carry flag, Zero flag, Overflow flag, Trace
flag, Interrupt flag, Direction flag, and Sign flag.
5. What is the Maximum clock frequency in 8086?
ANS: 5 Mhz is the Maximum clock frequency in 8086.
6. What are the various segment registers in 8086?
ANS: Code, Data, Stack, Extra Segment registers in 8086.
7. Logic calculations are done in which type of registers?
ANS: Accumulator is the register in which Arithmetic and Logic calculations are done.
8. How 8086 is faster than 8085?
ANS: Because of pipelining concept. 8086 BIU fetches the next instruction when EU busy in
executing the anoter instruction.
9. What does EU do?
ANS: Execution Unit receives program instruction codes and data from BIU, executes these
instructions and store the result in general registers.
10. Which Segment is used to store interrupt and subroutine return address registers?
ANS: Stack Segment in segment register is used to store interrupt and subroutine return
address registers.
15CSL48 Microprocessor and Microcontroller Laboratory 2017-18
Dept of ISE,MIT Mysore Page 56
11. What does microprocessor speed depend on?
ANS: The processing speed depends on DATA BUS WIDTH.
12. What is the size of data bus and address bus in 8086?
ANS: 8086 has 16-bit data bus and 20- bit address bus.
13. What is the maximun memory addressing capability of 8086?
ANS: The maximum memory capability of 8086 is 1MB.
14. What is flag?
ANS: Flag is a flip-flop used to store the information about the status of a processor and the
status of the instruction executed most recently.
15. Which Flags can be set or reset by the programmer and also used to control the operation
of the processor?
ANS: Trace Flag, Interrupt Flag, Direction Flag.
16. In how many modes 8086 can be opertaed and how?
ANS: 8086 can be opertaed in 2 modes. They are Minimum mode if MN/MX pin is active
high and Maximum mode if MN/MX pin is ground.
17. What is the difference between min mode and max mode of 8086?
ANS: Minimum mode operation is the least expensive way to operate the 8086
microprocessor because all the control signals for the memory and I/O are generated by the
micro processor. In Maximum mode some of the control signals must be externally
generatred. This requires the addition of an external bus controller. It used only when the
system contains external coprocessors such as 8087 arithmetic coprocessor.
18. Which bus controller used in maximum mode of 8086?
ANS: 8288 bus controller is used to provide the signals eliminated from the 8086 by the
maximum mode operation.
19. What is stack?
ANS: Stack is a portion of RAM used for saving the content of Program Counter and general
purpose registers.
20. Which Stack is used in 8086?
ANS: FIFO (First In First Out) stack is used in 8086.In this type of Stack the first stored
information is retrieved first.
21. What is the position of the Stack Pointer after the PUSH instruction?
15CSL48 Microprocessor and Microcontroller Laboratory 2017-18
Dept of ISE,MIT Mysore Page 57
ANS: The address line is 02 less than the earlier value.
22. What is the position of the Stack Pointer after the POP instruction?
ANS: The address line is 02 greater than the earlier value.
23. What is interrupt?
ANS: Interrupt is a signal send by external device to the processor so as to request the
processor to perform a particular work.
24. What are the various interrupts in 8086?
ANS: Maskable interrupts, Non-Maskable interrupts.
25. What is meant by Maskable interrupts?
ANS: An interrupt that can be turned off by the programmer is known as Maskable interrupt.
26. What is Non-Maskable interrupts?
ANS: An interrupt which can be never be turned off (ie.disabled) is known as Non-Maskable
interrupt.
27. Which interrupts are generally used for critical events?
ANS: Non-Maskable interrupts are used in critical events. Such as Power failure, Emergency,
Shut off etc.,
28. Give example for Non-Maskable interrupts?
ANS: Trap is known as Non-Maskable interrupts, which is used in emergency condition.
29. Give examples for Maskable interrupts?
ANS: RST 7.5, RST6.5, RST5.5 are Maskable interrupts. When RST5.5 interrupt is received
the processor saves the contents of the PC register into stack and branches to 2Ch
(hexadecimal) address.
When RST6.5 interrupt is received the processor saves the contents of the PC register into
stack and branches to 34h (hexadecimal) address.
When RST7.5 interrupt is received the processor saves the contents of the PC register into
stack and branches to 3Ch (hexadecimal) address.
30. What is SIM and RIM instructions?
ANS: SIM is Set Interrupt Mask. Used to mask the hardware interrupts. RIM is Read
Interrupt Mask. Used to check whether the interrupt is Masked or not.
15CSL48 Microprocessor and Microcontroller Laboratory 2017-18
Dept of ISE,MIT Mysore Page 58
31. What is macro?
ANS: Macro is a set of instructions that perform a task and all the isntructions defined in it is
inserted in the program at the point of usage.
32. What is the difference between Macro and Procedure?
ANS: A procedure is accessed via a CALL instruction and a macro will inserted in the
program at the point of execution.
33. What is meant by LATCH?
ANS: Latch is a D- type flip-flop used as a temporary storage device controlled by a timing
signal, which can store 0 or 1. The primary function of a Latch is data storage. It is used in
output devices such as LED, to hold the data for display
34. What is a compiler?
ANS: Compiler is used to translate the high-level language program into machine code at a
time. It doesn.t require special instruction to store in a memory, it stores automatically. The
Execution time is less compared to Interpreter.
35. What is the disadvantage of microprocessor?
ANS: It has limitations on the size of data. Most Microprocessor does not support floating-
point operations.
36. What is the 82C55A device?
ANS: The 8255A/82C55A interfaces peripheral I/O devices to the microcomputer system
bus. It is programmable by the system software. It has a 3-state bi-directional 8-bit buffer
which interfaces the 8255A/82C55A to the system data bus.
37. What kind of input/output interface dose a PPI implement?
ANS: It provides a parallel interface, which includes features such as single-bit, 4-bit, and
byte-wide input and output ports; level-sensitive inputs; latched outputs; strobed inputs or
outputs; and strobed bidirectional input/outputs.
38. How many I/O lines are available on the 82C55A?
ANS: 82C55A has a total of 24 I/O lines.
15CSL48 Microprocessor and Microcontroller Laboratory 2017-18
Dept of ISE,MIT Mysore Page 59
39. Describes the mode 0, mode 1, and mode 2 operations of the 82C55A?
ANS: MODE 0: Simple I/O mode. In this mode, any of the ports A, B, and C can be
programmed as input or output. In this mode, all the bits are out or in.
MODE 1: Ports A and B can be used as input or output ports with handshaking capabilities.
Handshaking signals are provided by the bits of port C.
MODE 2: Port A can be used as a bidirectional I/O port with handshaking capabilities whose
signals are provided by port C. Port B can be used either in simple I/O mode or handshaking
mode 1.
40. What is the mode and I/O configuration for ports A, B, and C of an 82C55A after its
control register is loaded with 82H?
ANS: If control register is loaded with 82H, then the port B is configured as an input port,
port A and port C are configured as output ports and in mode 0
15CSL48 Microprocessor and Microcontroller Laboratory 2017-18
Dept of ISE,MIT Mysore Page 60
APPENDIX A
INSTRUCTION SET
Instructions Operands Description
MOV REG, memory
memory, REG
REG, REG
memory,
immediate
REG, immediate
SREG, memory
memory, SREG
REG, SREG
SREG, REG
Copy operand2 to operand1.
The MOV instruction cannot:
Set the value of the CS and IP registers.
Copy value of one segment register to another
segment
register (should copy to general register first).
Copy immediate value to segment register
(should copy to
general register first).
Algorithm: operand1 = operand2
Ex:
Mov AX,BX ;Copy contents of BX to AX
Mov si,00h ;load Si with 00h
MUL REG
Memory
Unsigned multiply.
Multiply the contents of REG/Memory with
contents of AL register.
Algorithm:
When operand is a byte:
AX = AL * operand.
When operand is a word:
(DX: AX) = AX * operand.
CMP REG, memory
memory, REG
REG, REG
memory,
Compare.
Algorithm:operand1 - operand2
Result is not stored anywhere, flags are set (OF, SF,
ZF, AF, PF,
15CSL48 Microprocessor and Microcontroller Laboratory 2017-18
Dept of ISE,MIT Mysore Page 61
immediate
REG, immediate
CF) according to result.
JMP Label Unconditional Jump.
Transfers control to another part of the program. 4-
byte address may
be entered in this form: 1234h: 5678h, first value is
a segment
second value is an offset.
Algorithm: always jump
JA Label Jump If Above.
Short Jump if first operand is Above second
operand (as set by CMP
instruction). Unsigned.
Algorithm:if (CF = 0) and (ZF = 0) then jump
JAE Label Jump If Above Or Equal
Short Jump if first operand is Above or Equal to
second operand (as
set by CMP instruction). Unsigned.
Algorithm:
if CF = 0 then jump
JB Label Jump If Below.
Short Jump if first operand is Below second
operand (as set by CMP
instruction). Unsigned.
Algorithm:
if CF = 1 then jump
JBE Label Jump If Below Or Equal
Short Jump if first operand is Below second
15CSL48 Microprocessor and Microcontroller Laboratory 2017-18
Dept of ISE,MIT Mysore Page 62
operand (as set by CMP
instruction). Unsigned.
Algorithm:
if CF = 1 then jump
JC Label Jump If Carry
Short Jump if Carry flag is set to 1.
Algorithm:
if CF = 1 then jump
JE Label Jump If Equal.
Short Jump if first operand is Equal to second
operand (as set by
CMP instruction). Signed/Unsigned.
Algorithm:
if ZF = 1 then jump
JG Label Jump If Greater
Short Jump if first operand is Greater then second
operand (as set by
CMP instruction). Signed.
Algorithm:
if (ZF = 0) and (SF = OF) then jump
JGE Label Jump If Greater Or Equal.
Short Jump if first operand is Greater or Equal to
second operand (as
set by CMP instruction). Signed.
Algorithm:
if SF = OF then jump
JL Label Jump If Less than.
Short Jump if first operand is Less then second
15CSL48 Microprocessor and Microcontroller Laboratory 2017-18
Dept of ISE,MIT Mysore Page 63
operand (as set by
CMP instruction). Signed.
Algorithm:
if SF <> OF then jump
JLE Label Jump If Less Or Equal.
Short Jump if first operand is Less or Equal to
second operand (as
set by CMP instruction). Signed.
Algorithm:
if SF <> OF or ZF = 1 then jump
JNZ Label Jump If Non Zero.
Short Jump if Not Zero (not equal). Set by CMP,
SUB, ADD, TEST,
AND, OR, XOR instructions.
Algorithm:
if ZF = 0 then jump
JZ Label Jump If Zero.
Short Jump if Zero (equal). Set by CMP, SUB,
ADD, TEST, AND,
OR, XOR instructions.
LEA REG, memory Load Effective Address.
Algorithm:
REG = address of memory (offset)
LOOP Label Decrease CX, jump to label if CX not zero.
Algorithm:
CX = CX - 1
if CX <> 0 then
15CSL48 Microprocessor and Microcontroller Laboratory 2017-18
Dept of ISE,MIT Mysore Page 64
jump
else
o no jump, continue
ADD REG, memory
memory, REG
REG, REG
memory,
immediate
REG, immediate
Add.
Algorithm:
operand1 = operand1 + operand2
AND REG, memory
memory, REG
REG, REG
memory,
immediate
REG, immediate
Logical AND between all bits of two operands.
Result is stored in
operand1.
These rules apply:
1 AND 1 = 1; 1 AND 0 = 0
0 AND 1 = 0; 0 AND 0 = 0
OR REG, memory
memory, REG
REG, REG
memory,
immediate
REG, immediate
Logical OR between all bits of two operands. Result
is stored in first
operand.
These rules apply:
1 OR 1 = 1; 1 OR 0 = 1
0 OR 1 = 1; 0 OR 0 = 0
SUB REG, memory
memory, REG
REG, REG
memory,
immediate
REG, immediate
Subtract.
Algorithm:
operand1 = operand1 - operand2
DAA No Operands adjust After Addition.
15CSL48 Microprocessor and Microcontroller Laboratory 2017-18
Dept of ISE,MIT Mysore Page 65
Corrects the result of addition of two packed BCD
values.
Algorithm:
if low nibble of AL> 9 or AF = 1 then:
AL = AL + 6
AF = 1
if AL> 9Fh or CF = 1 then:
AL = AL + 60h
CF = 1
DAS No Operands Decimal adjust After Subtraction.
Corrects the result of subtraction of two packed
BCD values.
Algorithm:
if low nibble of AL> 9 or AF = 1 then:
AL = AL - 6
AF = 1
if AL> 9Fh or CF = 1 then:
AL = AL - 60h
CF = 1
INC REG
memory
Increment.
Algorithm:operand = operand + 1
DEC REG
memory
Decrement.
Algorithm:operand = operand – 1
DIV REG
memory
Unsigned divide.
Algorithm:
when operand is a byte:
AL = AX / operand
15CSL48 Microprocessor and Microcontroller Laboratory 2017-18
Dept of ISE,MIT Mysore Page 66
AH = remainder (modulus)
when operand is a word:
AX = (DX AX) / operand
DX = remainder (modulus)
SHL memory,
immediate
REG, immediate
memory, CL
REG, CL
Shift Left.
Shift operand1 Left. The number of shifts is set by
operand2.
Algorithm:
Shift all bits left, the bit that goes off is set to
CF.
Zero bit is inserted to the right-most position.
SHR memory,
immediate
REG, immediate
memory, CL
REG, CL
Shift Right.
Shift operand1 Right. The number of shifts is set by
operand2.
Algorithm:
Shift all bits right, the bit that goes off is set to
CF.
Zero bit is inserted to the left-most position.
ROL
memory,
immediate
REG, immediate
memory, CL
REG, CL
Rotate Left.
Rotate operand1 left. The number of rotates is set
by operand2.
Algorithm:
Shift all bits left, the bit that goes off is set to CF
and the
same bit is inserted to the right-most position
ROR
memory,
immediate
REG, immediate
memory, CL
Rotate Right.
Rotate operand1 right. The number of rotates is set
by operand2.
Algorithm:
15CSL48 Microprocessor and Microcontroller Laboratory 2017-18
Dept of ISE,MIT Mysore Page 67
REG, CL
Shift all bits right, the bit that goes off is set to CF
and the
same bit is inserted to the left-most position.
RCL
memory, immediate
REG, immediate
memory, CL
REG, CL
Rotate operand1 left through Carry Flag. The
number of rotates is
set by operand2.
Algorithm:
Shift all bits left, the bit that goes off is set to CF
and
previous value of CF is inserted to the right-most
position.
Example:
STC ; set carry (CF=1).
MOV AL, 1Ch ; AL = 00011100b
RCL AL, 1 ; AL = 00111001b, CF=0.
RET
C O
r r
OF=0 if first operand keeps original sign.
CALL
procedure name
label
Transfers control to procedure, return address is
(IP)pushed to stack.
RET
No operands
Or even immediate
date
Return from near procedure.
Algorithm:
Pop from stack:
o IP
if immediate operand is present: SP = SP + operand
IN AL, im.byte Input from port into AL or AX.
15CSL48 Microprocessor and Microcontroller Laboratory 2017-18
Dept of ISE,MIT Mysore Page 68
AL, DX
AX, im.byte
AX, DX
Second operand is a port number. If required to
access port number
over 255 - DX register should be used.
OUT
AL, im.byte
AL, DX
AX, DX
Output from AL or AX to port.
First operand is a port number. If required to access
port number
over 255 - DX register should be used.
POP
REG
SREG
memory
Get 16 bit value from the stack.
Algorithm: Operand = SS : [SP](top of stack)
SP = Sp + 2.
PUSH
REG
SREG
memory
Store 16 bit value in the stack.
Algorithm:
SP = SP - 2
SS:[SP] (top of the stack) = operand
XOR
REG, memory
memory, REG
REG, REG
memory,
immediate
REG, immediate
Logical XOR (Exclusive OR) between all bits of
two operands.
Result is stored in first operand.
These rules apply:
1 XOR 1 = 0; 1 XOR 0 = 1
0 XOR 1 = 1; 0 XOR 0 = 0
XCHG
REG, memory
memory, REG
REG, REG
Exchange values of two operands.
Algorithm:operand1 < - > operand2
15CSL48 Microprocessor and Microcontroller Laboratory 2017-18
Dept of ISE,MIT Mysore Page 69
XLAT No Operands Translate byte from table.
Copy value of memory byte at DS:[BX + unsigned
AL] to AL
register.
Algorithm: AL = DS:[BX + unsigned AL]
AAA No Operands ASCII Adjust after Addition.
Corrects result in AH and AL after addition when
working with
BCD values.
Algorithm:
if low nibble of AL> 9 or AF = 1 then:
AL = AL + 6
AH = AH + 1
AF = 1
CF = 1
else
AF = 0
CF = 0
in both cases:
clear the high nibble of AL.
Corrects result in AH and AL after addition when
working with
BCD values.
Algorithm:
if low nibble of AL> 9 or AF = 1 then:
AL = AL + 6
AH = AH + 1
15CSL48 Microprocessor and Microcontroller Laboratory 2017-18
Dept of ISE,MIT Mysore Page 70
AF = 1
CF = 1
else
AF = 0
CF = 0
in both cases:
clear the high nibble of AL.
AAS No Operands ASCII Adjust after Subtraction.
Corrects result in AH and AL after subtraction
when working with
BCD values.
Algorithm:
if low nibble of AL> 9 or AF = 1 then:
AL = AL - 6
AH = AH - 1
AF = 1
CF = 1
else
AF = 0
CF = 0
in both cases:
clear the high nibble of AL.
Example:
MOV AX, 02FFh ; AH = 02, AL = 0FFh
AAS ; AH = 01, AL = 09
AAM No Operands ASCII Adjust after Multiplication.
Corrects the result of multiplication of two BCD
15CSL48 Microprocessor and Microcontroller Laboratory 2017-18
Dept of ISE,MIT Mysore Page 71
values.
Algorithm:
AH = AL / 10
AL = remainder
Example:
MOV AL, 15 ; AL = 0Fh
AAM ; AH = 01, AL = 05
15CSL48 Microprocessor and Microcontroller Laboratory 2017-18
Dept of ISE,MIT Mysore Page 72
APPENDIX B
INTERRUPTS
INT 21h calls DOS functions.
INT 21h calls DOS functions.
Function 01h- Read character from standard input, result is stored in AL. If there
is no character in the keyboard buffer, the function waits until any key is pressed.
Invoked by: AH = 01h
Returns: AL = character entered.
Example:
Mov AH, 01h
INT 21h
Function 02h- Write a character to standard output.
INT 21h
Invoked by: DL = character to write.
AH =02h
After execution AL = DL.
Example:
Mov AH, 02h
Mov DL, ‟a‟ ; Character to be displayed on screen must be stored in DL reg.
INT 21h
Function 02h- set cursor position.
INT 10h / AH = 2 - set cursor position.
Input:
DH = row.
DL = column.
BH = page number (0...7).
Function 03h- gets cursor position and size.
INT 10h / AH = 03h -
input:
BH = page number.
return:
DH = row.
DL = column.
CH = cursor start line.
CL = cursor bottom line.
Function 06h – Direct console for input/output.If DL = 0FFH on entry, then this
function reads the console. If DL = ASCII character, then this function displays the
ASCII character on the console video screen.
15CSL48 Microprocessor and Microcontroller Laboratory 2017-18
Dept of ISE,MIT Mysore Page 73
Invoked by: Parameters for O/P: DL = 0…255
Parameters for I/P: DL = 255.
Returns: for O/P: AL = DL.
For I/P: ZF set if no character available &AL = 0
ZF clear if character available &AL = character.
Example:
mov ah, 6
mov dl, 'a'
int 21h ; output character.
mov ah, 6
mov dl, 255
int 21h ; get character from keyboard buffer (if any) or set ZF=1.
Function 09h - Write a string to standard output atDS: DX.
String must be terminated by '$'.The string can be of any length and may contain
control characters such as carriage return (0DH) and line feed (0AH).
Invoked by: DS = string to write.
AH = 09h
Example:
Mov AH, 09h
Mov DX, offset str ; Address of the string to be displayed
INT 21h
Function 2Ch- Get system time.
Invoked by: AH =2Ch
Return: CH = hour. CL = minute. DH = second. DL = 1/100 seconds.
Example:
Mov AH, 2ch
INT 21h
Function 3Ch - Create or truncate file.
Invoked by: CX = file attributes:
mov cx, 0 ; normal - no attributes.
mov cx, 1 ; read-only.
mov cx, 2 ; hidden.
mov cx, 4 ; system
mov cx, 7 ; hidden, system and read-only!
mov cx, 16 ; archive
mov cx, 0BH ; Volume label
mov cx, 10H ; Subdirectory
15CSL48 Microprocessor and Microcontroller Laboratory 2017-18
Dept of ISE,MIT Mysore Page 74
DS: DX -> filename. ; AH =3Ch
Returns:
CF clear if successful, AX = file handle.
CF set on error AX = error code.
Example:
Mov AH, 3ch
Mov CX, 01
Mov DX, offset Filename
INT 21h
Function 41h - Delete file (unlink).
Invoked by: DS: DX -> ASCIZ filename (no wildcards, but see notes).
AH=41h
Return:
CF clear if successful, AX destroyed.
CF set on error AX = error code.
Example:
Mov AH, 41h
Mov DX, offset Filename
INT 21h
Function 4Ch – Terminate a process.
Invoked by: AH = 4ch
Return: returns control to the operating system.
Example:
Mov AH, 4Ch
INT 21h
Interrupt INT 10h:
INT 10h calls the BIOS functions. This interrupt often called the video
services interrupt as it directly controls the video display in a system.
Function 02h - Set cursor position.
Invoked by: DH = row; DL = column; BH = page number (0...7); AH=02h.
Example:
MOV AH, 02h
MOV BH, 00
MOV DH, 06
MOV DL, 10
INT 10h
15CSL48 Microprocessor and Microcontroller Laboratory 2017-18
Dept of ISE,MIT Mysore Page 75
Function 03h – Get cursor position.
Invoked by: BH = page number. (In general 0)
AH = 03h
Return: DH = row number; DL = column number; CH = cursor start line;
CL = cursor bottom line.
Example:
Mov BH, 0
Mov AH, 03h
INT 10h
Function 06h – Scroll up window
Invoked by: AL = number of lines by which to scroll. (00h = clear the entire screen.)
BH = attribute used to write blank lines at bottom of window.
CH, CL = row, column of window's upper left corner.
DH, DL = row, column of window's lower right corner.
Recommended