100% found this document useful (1 vote)
937 views84 pages

MP Lab Manual

This document appears to be a laboratory manual for a Microprocessor and Microcontroller course. It includes an introduction, list of experiments to be performed, additional programs, sample questions, and an appendix. It provides details about the course objectives, experiments involving assembly language programs for 8086 and ARM processors, interfacing with devices like displays, motors and I/O ports. It also lists the structure and commands used for MASM assembly language programs.

Uploaded by

yguptas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
937 views84 pages

MP Lab Manual

This document appears to be a laboratory manual for a Microprocessor and Microcontroller course. It includes an introduction, list of experiments to be performed, additional programs, sample questions, and an appendix. It provides details about the course objectives, experiments involving assembly language programs for 8086 and ARM processors, interfacing with devices like displays, motors and I/O ports. It also lists the structure and commands used for MASM assembly language programs.

Uploaded by

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

Jyothy Institute of Technology

(Affiliated to V.T.U., Belagavi)


Off Kanakpura Road, Tataguni, Bengaluru 560082

MP & MC Laboratory
15CSL48

Department of Information Science and Engineering


2016-2017
FOREWORD

It gives me a great amount of pleasure and pride to present this manual for P and C
Laboratory. I would like to appreciate the efforts put in by the faculty of both the departments
of CSE and ISE in this endeavour. The presentation of the laboratory manual is very aesthetic
and I believe it will be greatly useful for all students and faculty fraternity. I congratulate our
departments on the successful completion of this work and thank all the people responsible
for this directly or indirectly.

Dr. Mahendra K V
Principal
Jyothy Institute of Technology
ACKNOWLEDGEMENTS

Any work is done only with enough support from people around us. The same is true for this
as well. We have been genuinely supported by our friends, colleagues and families in what
appeared initially to be a herculean task making it look like cake walk on completion.

We would like to extend our heart felt gratitude to the Management of JIT, for presenting us
with the challenges that made us better.

We would also like to thank M/S ALS, Bangalore for providing support related to ARM kits
and Programs.

We thank our beloved Principal Dr. Mahendra K V, for supporting us throughout the process
of writing this manual and for being kind enough to write a befitting foreword to it.

We thank Prof. Nagaraj A, HOD-ISE for being a source of constant appreciation and support
without whom this endeavour would have been near impossible.

Finally we would like to thank our students and colleagues who have directly or indirectly
helped us in making this thought real.

Team
Department of CSE & ISE
Jyothy Institute of Technology
Team
Editors:

1. Prof. Nagaraj A
2. Prof. Abhishek K
3. Prof. Pruthvi Kumar K R
4. Prof. Vadiraja A
5. Prof. Harish K

Hardware and Software Solutions:

1. Mr. Ravi, Marketing Manager, Advanced Electronics Systems

Front Page Design:

1. Prof. Vadiraja A
MICROPROCESSOR AND MICROCONTROLLER LABORATORY 15CSL48

SCHEME and SYLLABUS

MICROPROCESSOR AND MICROCONTROLLER LABORATORY

[As per Choice Based Credit System (CBCS) scheme]


(Effective from the academic year 2016 -2017)
SEMESTER IV
Subject Code 15CSL48 IA Marks 20
Number of Lecture Hours/Week 01 I + 02 P Exam Marks 80
Total Number of Lecture Hours 40 Exam Hours 03
CREDITS 02
Course objectives: This course will enable students to:
To provide practical exposure to the students on microprocessors, design and coding Knowledge on
80x86 family/ARM.
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.
Description
Demonstration and Explanation hardware components and Faculty in-charge should explain 8086
architecture, pin diagram in one slot. The second slot, the Faculty in-charge should explain instruction
set types/category etc. Students have to prepare a write-up on the same and include it in the Lab
record and to be evaluated.
Laboratory Session-1: Write-up on Microprocessors, 8086 Functional block diagram, Pin diagram and
description. The same information is also taught in theory class; this helps the students to understand
better.
Laboratory Session-2: Write-up on Instruction group, Timing diagrams, etc. The same information is
also taught in theory class; this helps the students to understand better.
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.
Experiments
Develop and execute the following programs using 8086 Assembly Language. Any suitable assembler
like MASM/TASM/8086 kit or any equivalent software may be used. Program should have suitable
comments. The board layout and the circuit diagram of the interface are to be provided to the student

Dept. of CSE/ISE Jyothy Institute of Technology Page 1


MICROPROCESSOR AND MICROCONTROLLER LABORATORY 15CSL48

during the examination. Software Required: Open source ARM Development platform, KEIL IDE and
Proteus for simulation
1 Sign 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)

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 45specify 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 moto56r
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).

Dept. of CSE/ISE Jyothy Institute of Technology Page 2


MICROPROCESSOR AND MICROCONTROLLER LABORATORY 15CSL48

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.

Dept. of CSE/ISE Jyothy Institute of Technology Page 3


MICROPROCESSOR AND MICROCONTROLLER LABORATORY 15CSL48

INDEX

Serial Content Page


No Number

1 5
MASM Commands

2 Introduction 9

3 Lab Programs 19

4 Additional Programs 63

5 Viva Questions and applications 67

6 Appendix 73

Dept. of CSE/ISE Jyothy Institute of Technology Page 4


MICROPROCESSOR AND MICROCONTROLLER LABORATORY 15CSL48

MASM COMMANDS:

C :/>cd foldername

C:/foldername>edit filename.asm

After this command executed in command prompt an editor window will open. Program
should be typed in this window and saved. The program structure is given below.

Structure of Program:

.model tiny/small/medium/large

.Stack <some number>

.data
; Initialize data
; Which is used in program
.code
; Program logic goes here
;
end

To run the program, the following steps have to be followed:

C:/foldername>masm filename.asm

After this command is executed in command prompt if there are no errors in program regarding
to syntax the assembler will generates an object module as discuss above.

C:/foldername>link filename.obj

Dept. of CSE/ISE Jyothy Institute of Technology Page 5


MICROPROCESSOR AND MICROCONTROLLER LABORATORY 15CSL48

After verifying the program for correct syntax and the generated object files should be linked
together. For this the above link command should be executed and it will give an EXE file if the model
directive is small as discuss above.

C:/foldername>debug filename.exe

After generating EXE file by the assembler its the time to check the output. For this the above
command is used and the execution of the program can be done in different ways. It is as shown
below:

__ g ; complete execution of program in single step.

__ t ; Stepwise execution.

__d ds: starting address or ending address ; To see data in memory locations

__p ; Used to execute interrupt or procedure during stepwise execution of program

__ q ; To quit the execution.

Note:
Develop and execute the following programs using an 8086 Assembly Language. All the
programs to be executed using an assembler like MASM, TASM etc.
Program should have suitable comments.
The board layout and the circuit diagram of the interface are to be provided to the student
during the examination.

Dept. of CSE/ISE Jyothy Institute of Technology Page 6


MICROPROCESSOR AND MICROCONTROLLER LABORATORY 15CSL48

LAB PROGRAMS

SOFTWARE & HARDWARE PROGRAMS:

Sl P.
Description
no No

1 Sign 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. 16

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. 21

3 Develop an assembly language program to reverse a given string and verify whether it is a
palindrome or not. Display the appropriate message. 24

4 Develop an assembly language program to compute nCr using recursive procedure. Assume
that n and r are non-negative integers. 26

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 28

6 To write and simulate ARM assembly language programs for data transfer, arithmetic and
logical operations (Demonstrate with the help of a suitable program). 30

7 To write and simulate C Programs for ARM microprocessor using KEIL (Demonstrate with
the help of a suitable program) 37

8 c) Design and develop an assembly program to demonstrate BCD Up-Down Counter (00-
99) on the Logic Controller Interface.
d) Design and develop an assembly program to read the status of two 8-bit inputs (X & 37
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 43

Dept. of CSE/ISE Jyothy Institute of Technology Page 7


MICROPROCESSOR AND MICROCONTROLLER LABORATORY 15CSL48

time. Ensure a flashing rate that makes it easy to read both the messages (Examiner does not
45specify these delay values nor is it necessary for the student to compute these values).

10 De52sign and develop an assembly program to drive a Stepper Motor interface and rotate the
moto56r 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 45
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). 38
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
52

13 To interface Stepper motor with ARM processor-- ARM7TDMI/LPC2148. Write a program


to rotate stepper motor. 56

Dept. of CSE/ISE Jyothy Institute of Technology Page 8


MICROPROCESSOR AND MICROCONTROLLER LABORATORY 15CSL48

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

Dept. of CSE/ISE Jyothy Institute of Technology Page 9


MICROPROCESSOR AND MICROCONTROLLER LABORATORY 15CSL48

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


Dept. of CSE/ISE Jyothy Institute of Technology Page 10
MICROPROCESSOR AND MICROCONTROLLER LABORATORY 15CSL48

Note: All registers are of size 16-bits.

Different registers and their operations are listed below:

Register Uses/Operations
AX As accumulator in Word multiply & Word divide operations, Word I/O operations
Operations
AL As accumulator in Byte Multiply, Byte Divide, Byte I/O, translate,
Decimal Arithmetic
AH Byte Multiply, Byte Divide
BX As Base register to hold the address of memory
CX String Operations, as counter in Loops
CL As counter in Variable Shift and Rotate operations

DX Word Multiply, word Divide, Indirect I/O

Dept. of CSE/ISE Jyothy Institute of Technology Page 11


MICROPROCESSOR AND MICROCONTROLLER LABORATORY 15CSL48

Dept. of CSE/ISE Jyothy Institute of Technology Page 12


MICROPROCESSOR AND MICROCONTROLLER LABORATORY 15CSL48

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

Dept. of CSE/ISE Jyothy Institute of Technology Page 13


MICROPROCESSOR AND MICROCONTROLLER LABORATORY 15CSL48

Assembly Language Development Tools:

1. EDITOR:
It.s a 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.
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.

Dept. of CSE/ISE Jyothy Institute of Technology Page 14


MICROPROCESSOR AND MICROCONTROLLER LABORATORY 15CSL48

3. LINKER:
Its 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 .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.

Dept. of CSE/ISE Jyothy Institute of Technology Page 15


MICROPROCESSOR AND MICROCONTROLLER LABORATORY 15CSL48

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.

Control Word format

D7 D6 D5 D4 D3 D2 D1 D0
1 for I/O PA mode: PA PCU(upper) PB mode PB PCU(upper)
00 mode 0, direction Direction 0 mode 0 Direction Direction
01 mode 1, 0 output 0 output 1 mode 1 0 output 0 output
10/11- mode2 1 - input 1 - input 1 - input 1 - input

Dept. of CSE/ISE Jyothy Institute of Technology Page 16


MICROPROCESSOR AND MICROCONTROLLER LABORATORY 15CSL48

How to write and execute your ALP 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 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.

Dept. of CSE/ISE Jyothy Institute of Technology Page 17


MICROPROCESSOR AND MICROCONTROLLER LABORATORY 15CSL48

Once you are familiar with the architecture and basics of assembly language tools, you can start typing
and executing your program.

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.

Dept. of CSE/ISE Jyothy Institute of Technology Page 18


MICROPROCESSOR AND MICROCONTROLLER LABORATORY 15CSL48

1 . Search a key element in a list of n numbers using the Binary Search algorithm.

.MODEL SMALL
.DATA ; data segment area. Define all variables and messages here
A1 DW 010H, 020H, 030H, 040H, 50H ;Array holding 5 elements
LEN DW (LEN-A1)/2 ; length of array
KEY DW 40H ; key element to be searched

M1 DB 'KEY FOUND AT
RES DB ? ; assigning value later
M3 DB POSITION $'
M2 DB 'KEY NOT FOUND $'

.CODE
MOV AX, @DATA ; Initialization of data segment
MOV DS, AX

MOV BX, 01 ;BX = low


MOV DX, LEN ;DX = high
MOV CX, KEY ; CX = key
L2: CMP BX, DX ;low <= high , BX should be less than DX
JA FAIL ; if low > high condition fails
MOV AX, BX ; AX = low
ADD AX, DX ;AX = low + high
SHR AX, 01 ;AX(mid) = (low + high)/2
MOV SI, AX ;SI = mid
DEC SI ;to adjust the pointer position
ADD SI, SI ;SI points to the mid element
CMP CX, A1 [SI] ; if key = A1[mid]
JAE L1 ;if key is greater or equal to A1[mid] jump
MOV DX, AX ;if key is lesser than A1[mid], high = mid

Dept. of CSE/ISE Jyothy Institute of Technology Page 19


MICROPROCESSOR AND MICROCONTROLLER LABORATORY 15CSL48

DEC DX ;high = mid -1


JMP L2 ;continue search between low and mid-1
L1: JE SUCCESS ;if key = A1[mid] jump to success
MOV BX, AX ;if key is greater than A1[mid] low = mid
INC BX ;low = mid + 1
JMP L2 ;continue search between mid+1 and high

FAIL: LEA DX, M2 ;Displaying fail message, store msg address in D


JMP L3

SUCCESS: ADD AX, 30H ;if found AX i.e mid contains position
MOV RES, AL ;AL contains position of element in array
LEA DX, M1 ; store success msg address in DX
L3: MOV AH, 09H ; number 09H has to be in AH for display
INT 21H ; call interrupt 21

MOV AH, 04CH ;DOS interrupt to terminate the program


INT 21H
END

Dept. of CSE/ISE Jyothy Institute of Technology Page 20


MICROPROCESSOR AND MICROCONTROLLER LABORATORY 15CSL48

OUTPUT:
KEY FOUND AT 3 POSITION

400BH
400AH LEN
4009H
50H
4008H
4007H
40H
4006H
4005H
30H
4004H
4003H
20H
4002H
4001H
10H
4000H

Figure 1.1: Pictorial representation of memory segment with starting address 4000H

Dept. of CSE/ISE Jyothy Institute of Technology Page 21


MICROPROCESSOR AND MICROCONTROLLER LABORATORY 15CSL48

Figure 1.2: Example for binary search

Dept. of CSE/ISE Jyothy Institute of Technology Page 22


MICROPROCESSOR AND MICROCONTROLLER LABORATORY 15CSL48

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.

DISPLAY MACRO M ; M stores the address the of message


LEA DX, M ; for displaying message its address should be in DX
MOV AH, 09 ; print a string pointed by DX
INT 21H ; interrupt displays message
ENDM ; end of macro

.MODEL SMALL
.DATA
A DB 01, 08, 04, 02, 03
LEN DW $-A ; $ indicates last used byte(LEN here)
M1 DB 10, 13, "UNSORTED ARRAY IS", 10, 13, '$'
M2 DB 10, 13, "SORTED ARRAY IS", 10, 13, '$'

.CODE
MOV AX, @DATA ; Initialization of data segment
MOV DS, AX

DISPLAY M1 ; Calling DISPLAY macro

CALL PRINT ; calling PRINT procedure for printing unsorted array

MOV BX, LEN ; BX = LEN


DEC BX ; BX = LEN - 1

OUTLOOP: MOV CX, BX ; CX = LEN - 1


MOV SI, 0 ; SI = 0, SI works as array pointer

INLOOP: MOV AL, A[SI] ; Move the array member pointed by SI to AL, AL = A[SI]

Dept. of CSE/ISE Jyothy Institute of Technology Page 23


MICROPROCESSOR AND MICROCONTROLLER LABORATORY 15CSL48

INC SI ; SI points to next member


CMP AL, A[SI] ; Comparing AL with array member pointed by SI
JA NEXT ; JA (jump if above) for descending order, for ascending order
; use JB (jump if below) instead of JA
XCHG AL, A[SI] ; Exchange the contents of AL with array member pointed by SI
MOV A[SI-1], AL ; store AL to previous location in array
NEXT: LOOP INLOOP ; repeat the comparison and exchanging, (LOOP executes until
; CX becomes 0, for each run it decrements CX by 1)
DEC BX ; BX = BX - 1
JNZ OUTLOOP ; if BX is not 0 repeat the loop

DISPLAY M2 ; calling DISPLAY macro with M2

CALL PRINT ; calling PRINT procedure


MOV AH, 4CH ; DOS interrupt to terminate the procedure
INT 21H

PRINT PROC NEAR ; start of the procedure PRINT


MOV BX, LEN ; BX = LEN
LEA SI, A ; SI = Address of array A
REPEAT: MOV AL, [SI] ; taking array element to AL
AAM ; adjusting the number ex. If AL = 25H after AAM
; AL = 0205H
MOV CX, AX ; CX = AX
ADD CX, 3030H ; converting number to ASCII equivalent, CX = 3235H
MOV AH, 02 ;To display a number AH must contain control value 02H
MOV DL, CH ; the number should be in DL, DL = CH (in ex. 02H)
INT 21H ; DOS interrupt to print number

MOV DL, CL ; take CL into DL for display (in ex. 05H)


INT 21H
MOV DL, ' ' ; printing one space between each number
Dept. of CSE/ISE Jyothy Institute of Technology Page 24
MICROPROCESSOR AND MICROCONTROLLER LABORATORY 15CSL48

INT 21H

INC SI ; incrementing pointer to address next number in array

DEC BX ; BX = BX 1, (counter)
JNZ REPEAT ; if BX is not zero repeat
RET ; if BX is zero return to main program
PRINT ENDP ; end of procedure
END ; end of main program

OUTPUT

UNSORTED ARRAY IS
01 08 04 02 03

SORTED ARRAY IS
01 02 03 04 08

Dept. of CSE/ISE Jyothy Institute of Technology Page 25


MICROPROCESSOR AND MICROCONTROLLER LABORATORY 15CSL48

3. Develop an assembly language program to reverse a given string and verify


whether it is a palindrome or not. Display the appropriate message

DISPLAY MACRO M
MOV AH, 09
LEA DX, M
INT 21H
ENDM

.MODEL SMALL
.DATA
STR DB 'MADAM'
LEN DW LEN-STR
M1 DB 'PALINDROME$'
M2 DB 'NOT PALINDROME$'

.CODE
MOV AX, @DATA
MOV DS, AX
LEA DI, STR ; load address of STR to DI,
MOV SI, DI ; SI = DI
ADD SI, LEN ; SI = SI + LEN
DEC SI ; SI pointing last byte in string
REPEAT: MOV AL, [DI] ; AL = string byte indexed by DI
CMP [SI], AL ; comparing two bytes
JNZ FAIL ; fails if both characters are different
INC DI ; increment the DI pointer
DEC SI ; decrement SI pointer
DEC LEN ; decrement counter value
JNZ REPEAT ; if counter is not zero repeats
DISPLAY M1 ; display M1 message

Dept. of CSE/ISE Jyothy Institute of Technology Page 26


MICROPROCESSOR AND MICROCONTROLLER LABORATORY 15CSL48

JMP FINISH ; unconditional jump


FAIL: DISPLAY M2 ; display M2 message
FINISH: MOV AH, 4CH ; terminate the program
INT 21H
END

OUTPUT:
PALINDROME
Note: Change the string and check the output.

M A D A M LEN

2000H 2001H 2002H 2003H 2004H 2005H


2006H 2007H 2008H

DI SI

Dept. of CSE/ISE Jyothy Institute of Technology Page 27


MICROPROCESSOR AND MICROCONTROLLER LABORATORY 15CSL48

4. Compute nCr using recursive procedure. Assume that n and r are non
negative integers.

DISPLAY MACRO M
MOV AH, 09
LEA AX, M
INT 21H
ENDM

.MODEL SMALL
.DATA
N DW 5
R DW 3
RES DW ?
M1 DB 10, 13 The nCr of the number is: $

.CODE
MOV AX, @DATA
MOV DS, AX

MOV BX, N ; BX = N
MOV CX, R ; CX = R
CALL NCR ; Calling a procedure NCR

MOV AH, 4CH ; DOS interrupt to terminate the program


INT 21H

NCR PROC NEAR ; start of the procedure


CMP CX, 0 ; if CX = = 0 i.e. if R = = 0
JE EXIT ; jump to specified location, RES = 1

Dept. of CSE/ISE Jyothy Institute of Technology Page 28


MICROPROCESSOR AND MICROCONTROLLER LABORATORY 15CSL48

PUSH CX ; storing CX(R) in stack


DEC CX ; CX = CX - 1
CALL NCR ; calling NCR procedure (recursive call until CX
; becomes 0
POP CX ; popping value from stack to CX
MOV AX, BX
INC AX
SUB AX, CX ; AX = AX - CX
MOV DX, 00
MUL RES ; AX = AX * RES
DIV CX ; AX = AX / CX
MOV RES, AX ; RES = AX
RET ; return from the procedure after computing result
EXIT: MOV RES, 1
RET ; returning RES = 1when CX = 0
NCR ENDP ; end of procedure
DIPLAY PROC NEAR ; Procedure to display result
MOV AX, RES
AAM
MOV CX, AX
ADD CX, 3030H
MOV AH, 02 ; write to std output device, print a character in DL
MOV DL, CH ; on monitor, the contents have to be in DL for display
INT 21H
MOV DL, CL
INT 21H
RET
DISPLAY ENDP ; end of procedure
END ; end of main program

Dept. of CSE/ISE Jyothy Institute of Technology Page 29


MICROPROCESSOR AND MICROCONTROLLER LABORATORY 15CSL48

OUTPUT:

The nCr of the number is: 10

1
2
3

STACK

Dept. of CSE/ISE Jyothy Institute of Technology Page 30


MICROPROCESSOR AND MICROCONTROLLER LABORATORY 15CSL48

5. Read the current time from the system and display it in the standard format on
the screen.

DISPLAY MACRO M1 ; Macro for displaying message


MOV AH, 09
LEA DX, M1
INT 21H
ENDM

DIS MACRO M ; Macro for displaying a single character


MOV AL, M
AAM
MOV BX, AX
ADD BX, 3030H
MOV DL, BH
MOV AH, 02
INT 21H
MOV DL, BL
INT 21H
ENDM

.MODEL SMALL
.DATA
STR DB ' CURRENT SYSTEM TIME IS $'
.CODE
MOV AX, @DATA
MOV DS, AX

DISPLAY STR

Dept. of CSE/ISE Jyothy Institute of Technology Page 31


MICROPROCESSOR AND MICROCONTROLLER LABORATORY 15CSL48

MOV AH, 02CH ; DOS interrupt which returns the system time,
INT 21H ; hours in CH, minutes in CL and seconds in DH

DIS CH ; CH holding hours


MOV DL, ': '
INT 21H

DIS CL ; CL holding minutes


MOV DL, ': '
INT 21H
DIS DH ; DH holding seconds

MOV AH, 4CH ; DOS interrupt to terminate the program


INT 21H
END

Dept. of CSE/ISE Jyothy Institute of Technology Page 32


MICROPROCESSOR AND MICROCONTROLLER LABORATORY 15CSL48

6. To write and simulate ARM assembly language programs for data transfer,
arithmetic and logical operations (Demonstrate with the help of a suitable
program).

a) To add two words

; program to add two words


; R1,=0X43210010 + R3,=0X43212102 = R4 = 0x8642212
; R0,=0X1234E640 + R2,=0X12348900 = R5 = 0x24696f40

EXPORT ADD64
AREA ADDITION , CODE , READONLY
ADD64
LDR R0,=0X1234E640
LDR R1,=0X43210010
LDR R2,=0X12348900
LDR R3,=0X43212102
ADDS R4,R1,R3
ADC R5,R0,R2
NOP
NOP
BX LR
END

b) Data transfer program


;PROGRAM TO TRANSFER DATA FROM CODE AREA TO DATA AREA
; COMPILE AND DEBUG PROGRAM
; SET BREAKPOINT AT NOP INSTRUCTION
; PRESS F5 TO RUN THE PROGRAM
; HAVE MEMORY1 WINDOW OPENED AND SET ADDRESS AT 0X40000000
AND AFTER EXECUTION CHECK 0X44444444 APPEAR AT MEMORY1 WINDOW

Dept. of CSE/ISE Jyothy Institute of Technology Page 33


MICROPROCESSOR AND MICROCONTROLLER LABORATORY 15CSL48

AREA LARGEST , CODE, READONLY


ENTRY ;Mark first instrution to execute
START
LDR R1,=VALUE1 ; LOADS THE ADDRESSOF FIRST VALUE
LDR R2,[R1],#4 ; WORD ALIGN T0 ARRAY ELEMENT
LDR R4,=RESULT ; LOADS THE ADDRESSOF RESULT
STR R2,[R4] ; STORES THE RESULT IN R2
NOP
NOP
NOP
VALUE1
DCD 0X44444444 ;
AREA DATA2,DATA,READWRITE ; TO STORE RESULT IN GIVEN AD DRESS
RESULT DCD 0X0
END

c) To divide two numbers


;/* PROGRAM TO Divide TWO NUMBERS */
;/* TAKE TWO NUMBERS 0X00000002, 0X00000008 */

;/* RESULT CAN BE VIEWED IN REGISTERS R5 (REMINDER) & R6


(QUOTIENT) */
;/* SET A BREAKPOINT AT NOP INSTRUCTION,RUN THE PROGRAM
& CHECK THE RESULT */
;/* PROGRAM WRITTEN BY ALS R&D TEAM BENGALURU DATE:25/12
/2013 */
EXPORT divide
AREA DIVISION , CODE, READONLY
ENTRY

Dept. of CSE/ISE Jyothy Institute of Technology Page 34


MICROPROCESSOR AND MICROCONTROLLER LABORATORY 15CSL48

START
Divide
MOV R0,#0 ; INTIALISE R0 TO ZERO
LDR R1,=VALUE ; LOADS THE ADDRESS OF FIRST VALUE
LDR R2,[R1],#4 ; WORD ALIGN T0 ARRAY ELEMENT (First element)
LDR R4,[R1],#4 ; WORD ALIGN T0 ARRAY ELEMENT (Second element)
CMP R2,R4
BHI ERROR
LOOP1
SUB R4,R4,R2 ; SUBTRACT R2 IN R4& STORE IN R4
ADD R0,R0,#1 ; INCREMENT THE R0 EVERYTIME BY 1
CMP R4,R2 ; COMPARE NUMBERS IN R4 & R2
BGE LOOP1 ; IF THE NUMBER in R4 > R2 THEN GOTO LOOP1
LOOP2
MOV R5,R4 ; CHECK REMINDER IN R5
MOV R6,R0 ; CHECK QUOTIENT INR6
ERROR
NOP
NOP
MOV PC,LR
BX LR
VALUE
DCD 0X00000002 ; divider (ALWAYS SMALLER)
DCD 0X00000008 ; dividend (ALWAYS GREATER)
END ; Mark end of file

Dept. of CSE/ISE Jyothy Institute of Technology Page 35


MICROPROCESSOR AND MICROCONTROLLER LABORATORY 15CSL48

d) Multiplication

; program to multiply two 32 bit numbers


; r0 = 0x706F
; r1 = 0X0161
; r2 = r0 * r1 = 0X009B090F
; check the result in r2 register

EXPORT MULTIPLY
AREA MULTI , CODE , READONLY
MULTIPLY
LDR R0,=0X706F
LDR R1,=0X0161
MULS R2,R1,R0
NOP
NOP
MOV PC,LR
END

e) Subtraction
EXPORT SUB64
AREA SUNTRACT , CODE , READONLY
SUB64
LDR R0,=0X1234E640
LDR R1,=0X43210010
LDR R2,=0X12348900
LDR R3,=0X43212102
SUB R4,R1,R0
SBC R5,R3,R2
NOP
NOP
Dept. of CSE/ISE Jyothy Institute of Technology Page 36
MICROPROCESSOR AND MICROCONTROLLER LABORATORY 15CSL48

BX LR
END

LOGICAL OPERATIONS
a) AND

;PROGRAM TO DEMONSTRATE LOGICAL AND INSTRUCTION


; COMPILE AND DEBUG PROGRAM
; SET BREAKPOINT AT NOP INSTRUCTION
; PRESS F5 TO RUN THE PROGRAM
;STEP THROUGH THE PROGRAM AND FIND
;FIRST OPERNAD AT R2= 55AAAA55
;SECOND OPERNAD AT R3= AA5555AA
; AND AFTER EXECUTION CHECK REGISTER R2 = FFFFFFFF
; AND AT 0X40000000 FFFFFFFF AT MEMORY 1 WINDOW1

AREA LARGEST , CODE, READONLY


ENTRY ;Mark first instruction to execute
START
LDR R1,=VALUE1 ; LOADS THE ADDRESSOF FIRST VALUE
LDR R2,[R1] ; WORD ALIGN T0 ARRAY ELEMENT
LDR R1,=VALUE2 ; LOADS THE ADDRESSOF FIRST VALUE
LDR R3,[R1]
AND R2,R3
LDR R4,=RESULT ; LOADS THE ADDRESSOF RESULT
STR R2,[R4] ; STORES THE RESULT IN R2 AND ATT MEMORY 0X40000000
NOP
NOP
NOP
VALUE1
DCD 0X55AAAA55 ;
Dept. of CSE/ISE Jyothy Institute of Technology Page 37
MICROPROCESSOR AND MICROCONTROLLER LABORATORY 15CSL48

VALUE2
DCD 0X5555AA55 ;
AREA DATA2,DATA,READWRITE ; TO STORE RESULT IN GIVEN ADDRESS
RESULT DCD 0X0
END

b) NOT

;PROGRAM TO DEMONSTRATE LOGICAL NOT INSTRUCTION


; COMPILE AND DEBUG PROGRAM
; SET BREAKPOINT AT NOP INSTRUCTION
; PRESS F5 TO RUN THE PROGRAM
; AND AFTER EXECUTION CHECK REGISTER R1 = FFFF2EDC

AREA LARGEST , CODE, READONLY


ENTRY ;Mark first instruction to execute
START
LDR R1,=VALUE1 ; LOADS THE ADDRESSOF FIRST VALUE
LDR R2,[R1],#4 ; WORD ALIGN T0 ARRAY ELEMENT
MVN R2,R2
LDR R4,=RESULT ; LOADS THE ADDRESSOF RESULT
STR R2,[R4] ; STORES THE RESULT IN R2
NOP
NOP
NOP
VALUE1
DCD 0XC123 ;
AREA DATA2,DATA,READWRITE ; TO STORE RESULT IN GIVEN ADDRESS
RESULT DCD 0X0
END

Dept. of CSE/ISE Jyothy Institute of Technology Page 38


MICROPROCESSOR AND MICROCONTROLLER LABORATORY 15CSL48

c) OR

;PROGRAM TO DEMONSTRATE LOGICAL OR INSTRUCTION


; COMPILE AND DEBUG PROGRAM
; SET BREAKPOINT AT NOP INSTRUCTION
; PRESS F5 TO RUN THE PROGRAM
; AND AFTER EXECUTION CHECK REGISTER R1 = FFFF3EDC

AREA LARGEST , CODE, READONLY


ENTRY ;Mark first instruction to execute
START
LDR R1,=VALUE1 ; LOADS THE ADDRESSOF FIRST VALUE
LDR R2,[R1] ; WORD ALIGN T0 ARRAY ELEMENT
LDR R1,=VALUE2 ; LOADS THE ADDRESSOF FIRST VALUE
LDR R3,[R1]
ORR R2,R3
LDR R4,=RESULT ; LOADS THE ADDRESSOF RESULT
STR R2,[R4] ; STORES THE RESULT IN R2
NOP
NOP
NOP
VALUE1
DCD 0X55AAAA55 ;
VALUE2
DCD 0XAA5555AA ;
AREA DATA2,DATA,READWRITE ; TO STORE RESULT IN GIVEN ADDRESS
RESULT DCD 0X0
END

Dept. of CSE/ISE Jyothy Institute of Technology Page 39


MICROPROCESSOR AND MICROCONTROLLER LABORATORY 15CSL48

7. To write and simulate C Programs for ARM microprocessor using KEIL


(Demonstrate with the help of a suitable program)

#include <lpc214x.h>
Void main(void)
{
int a,b,c;
a=4;
b=5;
c=a+b;
a=5;
}

Dept. of CSE/ISE Jyothy Institute of Technology Page 40


MICROPROCESSOR AND MICROCONTROLLER LABORATORY 15CSL48

HARDWARE PROGRAMS:
PART B

8. a. Design and develop an assembly program to demonstrate BCD Up-Down


Counter (00-99) on the Logic Controller Interface.

.MODEL SMALL
.DATA
PA EQU 0D0A0H
PB EQU 0D0A2H
CT EQU 0D0A3H

.CODE
MOV AX, @DATA
MOV DS, AX
MOV DX, CT
MOV AL, 82H
OUT DX, AL
MOV DX, PB ; PB is input port
IN AL, DX
CMP AL, 00H
JNE L2 ; if AL != 0, BCD UP DOWN counter
L1: CALL UP
JMP L1
L2: CALL UP

CALL DOWN
JMP L2

STOP: MOV AH, 04CH


INT 21H

Dept. of CSE/ISE Jyothy Institute of Technology Page 41


MICROPROCESSOR AND MICROCONTROLLER LABORATORY 15CSL48

UP PROC NEAR ; procedure to display BCD numbers from 0 to 9


MOV AL, 00H

L3: MOV DX, PA ; PA is output port


OUT DX, AL
INC AX
PUSH AX ; save count value in stack
MOV AH, 0BH ; checks whether a character is available from the keyboard
INT 21H ; AL = 00, not available, AL = FFH available, if available
OR AL, AL ; i.e AL = FF stop displaying and exit if AL = 00 continue
JNZ STOP ; displaying number
POP AX ; get back count value from stack
MOV AH, 86H ; AH =86 and INT 15H : wait
MOV CX, 020H ; this suspends execution of the caller for the specified interval
MOV DX, 0CH ;
INT 15H
CMP AL, 0AH ; if count value less than 10 (AL < 10) display the number
JNE L3 ; if the count value i.e AL = 10 return to the main program
RET
UP ENDP ; end of the procedure
DOWN PROC NEAR ; procedure to display numbers from 9 to 0
MOV AL, 09H

L4: MOV DX, PA ; PA is output port


OUT DX, AL ; Display the contents of AL i.e count value
DEC AX
PUSH AX ; store AX value in stack
MOV AH, 0BH ; check whether any character entered in key board
INT 21H
OR AL, AL
JNZ STOP
Dept. of CSE/ISE Jyothy Institute of Technology Page 42
MICROPROCESSOR AND MICROCONTROLLER LABORATORY 15CSL48

POP AX
MOV AH, 086H ; delay
MOV CX, 020H
MOV DX, 0CH
INT 15H
CMP AL, 00H
JNE L4
RET
DOWN ENDP
END

Dept. of CSE/ISE Jyothy Institute of Technology Page 43


MICROPROCESSOR AND MICROCONTROLLER LABORATORY 15CSL48

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.

DISMSG MACRO M
LEA DX, M
MOV AH, 09
INT 21H
ENDM

WAIT1 MACRO
MOV AH, 01 ; CHARACTER I/P WITH ECHO
INT 21H
ENDM

.MODEL SMALL
.DATA
.STACK
MSG_X DB 10,13,"SET VALUE FOR X ON LOGIC CONTLR & PRESS ANY KEY...$"
MSG_Y DB 10,13,"SET VALUE FOR Y ON LOGIC CONTLR & PRESS ANY KEY...$"
M3 DB 'LOWER BYTE FORM PORTA AND ENTER FOR HIGHER BYTE$'
M4 DB 'HIGHER BYTE FROM PORTA$'
PORTA EQU 0D0A0H
PORTB EQU 0D0A2H
CTRL EQU 0D0A3H

.CODE
MOV AX, @DATA
MOV DS, AX

MOV DX, CTRL


MOV AL, 82H

Dept. of CSE/ISE Jyothy Institute of Technology Page 44


MICROPROCESSOR AND MICROCONTROLLER LABORATORY 15CSL48

OUT DX, AL

DISMSG MSG_X
WAIT1

MOV DX, PORTB ; port B is input port


IN AL, DX
MOV BL, AL ; BL = X;

DISMSG MSG_Y
WAIT1

MOV DX, PORTB


IN AL, DX ; AL = Y

MOV AH, 00
MUL BL ; AX = AL * BL

PUSH AX ; STORING RESULT IN STACK

DISMSG M3

POP AX

MOV DX, PORTA


OUT DX, AL ; SENDING LOWER BYTE RESULT
MOV BL, AH

WAIT1

DISMSG M4
Dept. of CSE/ISE Jyothy Institute of Technology Page 45
MICROPROCESSOR AND MICROCONTROLLER LABORATORY 15CSL48

MOV DX, PORTA


MOV AL, BL ; SENDING HIGHR BYTE RESULT
OUT DX, AL

MOV AH, 4CH


INT 21H
END

Dept. of CSE/ISE Jyothy Institute of Technology Page 46


MICROPROCESSOR AND MICROCONTROLLER LABORATORY 15CSL48

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).

DELAY MACRO
MOV AH, 86H
MOV CX, 10H
MOV DX, 10H
INT 15H
ENDM

.MODEL SMALL
.STACK
.DATA
DISPLAY DB 61H, 0F5H, 0F3H, 71H ;( ASCII codes for E, R, I, F)
DB 31H, 0E3H, 61H, 91H ;(ASCII code for P, L, E, H)
CR EQU 0D0A3H
PA EQU 0D0A0H
PB EQU 0D0A1H
PC EQU 0D0A2H
.CODE
MOV AX, @DATA
MOV DS, AX

MOV AL, 80H


MOV DX, CR
OUT DX, AL

GET_KEY: MOV BX, 00H

Dept. of CSE/ISE Jyothy Institute of Technology Page 47


MICROPROCESSOR AND MICROCONTROLLER LABORATORY 15CSL48

L2: MOV CX, 08


MOV AL, DISPLAY [BX] ; taking data from look-up table
L1: MOV DX, PB
OUT DX, AL

PUSH AX

MOV DX, PC
MOV AL, 01 ; sending high pulse to the SIPO register
OUT DX, AL

MOV AL, 00 ; sending low pulse to the SIPO register


OUT DX, AL

POP AX ; the data will be sent serially, means bit by bit


SHR AL, 01
LOOP L1
INC BX
CMP BL, 08H
JNE NO_DELAY
DELAY
NO_DELAY: CMP BX, 08H
JNZ L2

MOV AH, 01 ; checks whether any key is pressed in keyboard


INT 16H ; if any key is pressed Z flag sets to 1, if no key is pressed
JZ GET_KEY ; Z = 0, continue display

MOV AH, 4CH ; end of the program


INT 21H
END

Dept. of CSE/ISE Jyothy Institute of Technology Page 48


MICROPROCESSOR AND MICROCONTROLLER LABORATORY 15CSL48

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).

.MODEL SMALL
.STACK 20
.DATA
STEP DB 20
PORTA EQU 0D0A0H
CTR EQU 0D0A3H
.CODE
MOV AX, @DATA
MOV DS, AX

MOV DX, CTR


MOV AL, 80H
OUT DX, AL

MOV AL, 88H ; AL = 10001000, it activates one of the 4 coils of


L1: MOV DX, PORTA ; the stepper motor (you can use 80H also)
OUT DX, AL

CALL DELAY

ROR AL, 01 ; rotating AL makes activation of the next


DEC STEP ; coils
JNZ L1

L2: MOV DX, PORTA

Dept. of CSE/ISE Jyothy Institute of Technology Page 49


MICROPROCESSOR AND MICROCONTROLLER LABORATORY 15CSL48

OUT DX, AL

CALL DELAY

ROL AL, 01
DEC STEP
JNZ L2

MOV AH, 4CH ; end of the program


INT 21H

DELAY PROC
PUSH CX
PUSH BX
MOV CX, 1000H

OUTER: MOV BX, 0FFFFH

INNER: DEC BX
JNZ INNER ; REPEAT INNER LOOP FFFF TIMES

LOOP OUTER ; REPEAT OUTER LOOP 1000H TIMES

POP BX
POP CX
RET
DELAY ENDP
END

Dept. of CSE/ISE Jyothy Institute of Technology Page 50


MICROPROCESSOR AND MICROCONTROLLER LABORATORY 15CSL48

STEPPER MOTOR

Dept. of CSE/ISE Jyothy Institute of Technology Page 51


MICROPROCESSOR AND MICROCONTROLLER LABORATORY 15CSL48

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).

.MODEL SMALL
.DATA
CTR EQU 9403H
PA EQU 9400H
TABLE DB 127, 149, 170, 190, 208, 224, 236, 246, 252, 254
DB 252, 246, 236, 224, 208, 190, 170, 149, 127
DB 104, 83, 63, 45, 29, 17, 7, 1, 0
DB 1, 7, 17, 29, 45, 63, 83, 104, 104 ; The above values are in decimal.
.CODE
MOV AX, @DATA
MOV DS, AX
MOV DX, CTR
MOV AL, 80H
OUT DX, AL
AGAIN: LEA SI, TABLE ; Table address in SI
MOV DX, PA
MOV CX, 37 ; CX = 37( number of elements in TABLE, in decimal)
BACK: LODSB
OUT DX, AL
CALL DELAY
LOOP BACK ; LOOP EXCECUTES 37 TIMES
MOV AH, 01H ; If any key if pressed, stop displaying wave in CRO
INT 16H
JZ AGAIN ; if key is not pressed continue the display
MOV AH, 4CH
INT 21H

Dept. of CSE/ISE Jyothy Institute of Technology Page 52


MICROPROCESSOR AND MICROCONTROLLER LABORATORY 15CSL48

DELAY PROC
MOV BX, 0FFFFH
LOOP1: DEC BX
JNZ LOOP1
RET
DELAY ENDP
END

Formula for calculation of table value X, X = 127 + 127 * SIN


For ex., if = 00 , X = 127, = 100 , X = 149 so on

Dept. of CSE/ISE Jyothy Institute of Technology Page 53


MICROPROCESSOR AND MICROCONTROLLER LABORATORY 15CSL48

b. Generate a Half Rectified Sine waveform using the DAC interface. (The output
of the DAC is to be displayed on the CRO).

.MODEL SMALL
.DATA
CTR EQU 9403H
PA EQU 9400H
TABLE DB 127, 149, 170, 190, 208, 224, 236, 246, 252, 254
DB 252, 246, 236, 224, 208, 190, 170, 149, 127
DB 127, 127, 127, 127, 127, 127, 127, 127, 127
DB 127, 127, 127, 127, 127, 127, 127, 127, 127

; The above values are in decimal.


.CODE
MOV AX, @DATA
MOV DS, AX
MOV DX, CTR
MOV AL, 80H
OUT DX, AL
AGAIN: LEA SI, TABLE ; Table address in SI
MOV DX, PA
MOV CX, 37 ; CX = 37( number of elements in TABLE, in decimal)
BACK: LODSB
OUT DX, AL
CALL DELAY
LOOP BACK ; LOOP EXCECUTES 37 TIMES
MOV AH, 01H ; If any key if pressed, stop displaying wave in CRO
INT 16H
JZ AGAIN ; if key is not pressed continue the display
MOV AH, 4CH
INT 21H

Dept. of CSE/ISE Jyothy Institute of Technology Page 54


MICROPROCESSOR AND MICROCONTROLLER LABORATORY 15CSL48

DELAY PROC
MOV BX, 0FFFFH
LOOP1: DEC BX
JNZ LOOP1
RET
DELAY ENDP
END

Dept. of CSE/ISE Jyothy Institute of Technology Page 55


MICROPROCESSOR AND MICROCONTROLLER LABORATORY 15CSL48

12. To interface LCD with ARM processor-- ARM7TDMI/LPC2148. Write and


execute programs in C language for displaying text messages and numbers on
LCD

#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[] = "ALS BENGALURU",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 intialisation


delay(3200); // delay 1.06ms

clr_disp(); //clear display


delay(3200); // delay 1.06ms

Dept. of CSE/ISE Jyothy Institute of Technology Page 56


MICROPROCESSOR AND MICROCONTROLLER LABORATORY 15CSL48

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')
{
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();
Dept. of CSE/ISE Jyothy Institute of Technology Page 57
MICROPROCESSOR AND MICROCONTROLLER LABORATORY 15CSL48

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)
Dept. of CSE/ISE Jyothy Institute of Technology Page 58
MICROPROCESSOR AND MICROCONTROLLER LABORATORY 15CSL48

{
temp = temp1 & 0xf0; //masking higher nibble first
wr_cn();
temp = temp1 & 0x0f; //masking lower nibble
temp = temp << 4;
wr_cn();
delay(500); // some delay
}

// 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


Dept. of CSE/ISE Jyothy Institute of Technology Page 59
MICROPROCESSOR AND MICROCONTROLLER LABORATORY 15CSL48

// 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++);
}

Dept. of CSE/ISE Jyothy Institute of Technology Page 60


MICROPROCESSOR AND MICROCONTROLLER LABORATORY 15CSL48

13. To interface Stepper motor with ARM processor-- ARM7TDMI/LPC2148.


Write a program to rotate stepper motor

#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

Dept. of CSE/ISE Jyothy Institute of Technology Page 61


MICROPROCESSOR AND MICROCONTROLLER LABORATORY 15CSL48

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 perticular bit

for( k = 0 ; k < 3000 ; k++ ); //for step speed variation

void anti_clock_wise(void)
{
var1 = 0x00800000 ; //For Anticlockwise

IO1CLR =0x00F00000 ; //clearing all 4 bits

IO1SET = var1 ;

for( k = 0 ; k < 3000 ; k++ ) ;

for( i = 0 ; i < 3 ; i++ ) // for A B C D Stepping


{
var1 >>=1; //rotating bits
Dept. of CSE/ISE Jyothy Institute of Technology Page 62
MICROPROCESSOR AND MICROCONTROLLER LABORATORY 15CSL48

IO1CLR =0x00F00000 ; // clar all bits before setting

IO1SET = var1 ; // setting perticular bit

for( k = 0 ; k < 3000 ; k++ ) ; //for step speed variation

}
}

Dept. of CSE/ISE Jyothy Institute of Technology Page 63


MICROPROCESSOR AND MICROCONTROLLER LABORATORY 15CSL48

ADDITIONAL PROGRAMS

1. ALP TO MOVE DATA BETWEEN THE REGISTERS.

.model tiny

.data
num1 db 50h
num2 dw 1234h

.code
mov ax,@data
mov ds,ax ;DATA SEGMENT INITIALIZATION

mov al,num1
mov ah,al
mov bh,ah
mov bl,al ;MOVES BYTE LENGTH OF DATA FROM REG.AL TO REG.BL

mov cx,num2
mov dx,cx
mov si,ax
mov di,si ;MOVES WORD LENGHT OF DATA FROM REG.CX TO REG.DX

int 3 ;TERMINATES THE PROGRAM EXECUTION

align 16 ;DATA SEGMENT STARTS FROM PAGE BOUNDARY


end

Run1: AX=5050, BX=5050, CX=1234, DX=1234, SI=1234, DI=1234

Dept. of CSE/ISE Jyothy Institute of Technology Page 64


MICROPROCESSOR AND MICROCONTROLLER LABORATORY 15CSL48

2. ALP TO MOVE IMMEDIATE DATA

.model tiny

.code
mov al,10h
mov ah,10
mov cl,50h
mov ch,50 ;MOVES IMMEDIATE VALUE TO 8 BIT REGISTER

mov bx,1234h
mov dx,1234 ;MOVES IMMEDIATE VALUE TO 16 BIT REGISTER

mov si,4000h
mov di,2000h

int 3 ;TERMINATE THE PROGRAM EXECUTION


end

Run1: AX=1010, BX=1234, CX=5050, DX=1234, SI=4000, DI=2000

Dept. of CSE/ISE Jyothy Institute of Technology Page 65


MICROPROCESSOR AND MICROCONTROLLER LABORATORY 15CSL48

3. ALP TO ADD TWO NUMBERS

.model small

.data
num1 db 05h
num2 db 06h
num3 dw 1234h
num4 dw 0002h
sum db ?
sum2 dw ?

.code
mov ax,@data
mov ds,ax ;INITIALIZES DATA SEGMENT

mov al,num1
mov bl,num2
add al,bl ;ADD THE 2 BYTES
mov sum,al ;STORES THE RESULT IN MEMORY

mov cx,num3
add cx,num4 ;ADD THE 2 WORDS
mov sum2,cx ;STORES THE RESULT IN MEMORY

int 3 ;TERMINATE THE PROGRAM EXECUTION

align 16 ;DS STARTS FROM PAGE BOUNDARY


end

Run1: AX=xx0B, CX=1236

Dept. of CSE/ISE Jyothy Institute of Technology Page 66


MICROPROCESSOR AND MICROCONTROLLER LABORATORY 15CSL48

4. ALP TO MULTIPLY TWO 16-BIT NUMBERS

.model small

.data
num1 dw 1234h
num2 dw 0ffffh
res dw 5 dup(0)

.code
mov ax,@data
mov ds,ax ;INITIALIZATION OF DATA SEGMENT

mov ax,num1
mov dx,num2
mul dx ;MULTIPLIES 2 16-BIT NUMBERS

mov res,ax
mov res+2,dx ;STORES THE IN MEMORY

int 3 ;TERMINATE THE PROGRAM EXECUTION


align 16 ;DS STARTS FROM PAGE BOUNDARY
end

Dept. of CSE/ISE Jyothy Institute of Technology Page 67


MICROPROCESSOR AND MICROCONTROLLER LABORATORY 15CSL48

VIVA QUESTIONS AND 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?

Dept. of CSE/ISE Jyothy Institute of Technology Page 68


MICROPROCESSOR AND MICROCONTROLLER LABORATORY 15CSL48

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.

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?

Dept. of CSE/ISE Jyothy Institute of Technology Page 69


MICROPROCESSOR AND MICROCONTROLLER LABORATORY 15CSL48

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?

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?

Dept. of CSE/ISE Jyothy Institute of Technology Page 70


MICROPROCESSOR AND MICROCONTROLLER LABORATORY 15CSL48

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?

Dept. of CSE/ISE Jyothy Institute of Technology Page 71


MICROPROCESSOR AND MICROCONTROLLER LABORATORY 15CSL48

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.

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.

Dept. of CSE/ISE Jyothy Institute of Technology Page 72


MICROPROCESSOR AND MICROCONTROLLER LABORATORY 15CSL48

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.

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.

Dept. of CSE/ISE Jyothy Institute of Technology Page 73


MICROPROCESSOR AND MICROCONTROLLER LABORATORY 15CSL48

APPENDIX A

INTERRUPT INT 21H


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.

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 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.

Invoked by: Parameters for O/P: DL = 0255

Dept. of CSE/ISE Jyothy Institute of Technology Page 74


MICROPROCESSOR AND MICROCONTROLLER LABORATORY 15CSL48

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, 06h
MOV DL, 0ffh
INT 21h

Function 09h - Write a string to standard output at DS: 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

Dept. of CSE/ISE Jyothy Institute of Technology Page 75


MICROPROCESSOR AND MICROCONTROLLER LABORATORY 15CSL48

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

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.

Dept. of CSE/ISE Jyothy Institute of Technology Page 76


MICROPROCESSOR AND MICROCONTROLLER LABORATORY 15CSL48

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

Function 03h Get cursor position.


Invoked by: BH = page number. (In general 0)
Dept. of CSE/ISE Jyothy Institute of Technology Page 77
MICROPROCESSOR AND MICROCONTROLLER LABORATORY 15CSL48

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.

Dept. of CSE/ISE Jyothy Institute of Technology Page 78


MICROPROCESSOR AND MICROCONTROLLER LABORATORY 15CSL48

APPENDIX B
ASCII TABLE

Dept. of CSE/ISE Jyothy Institute of Technology Page 79

You might also like