6TH Semester MP Lab Manual 2017 - 3 PDF

Download as pdf or txt
Download as pdf or txt
You are on page 1of 85

Microprocessor Lab Manual 10ECL68

BMS INSTITUTE OF TECHNOLOGYAND MANAGEMENT


Avalahalli, Doddaballapur main road, Yelahanka, Bangalore-560064

DEPARTMENT OF ELECTRONICS AND COMMUNICATION ENGINEERING

MICROPROCESSOR LAB MANUAL (10ECL68)


VI Semester ECE
Department Vision

Provide Quality Education in Electronics, Communication and Allied


Engineering fields to Serve as Valuable Resource for Industry and Society.

Department Mission

1. Impart Sound Theoretical Concepts and Practical Skills.


2. Promote Inter-disciplinary Research.
3. Inculcate Professional Ethics.

Name:
USN: ..
Batch & Semester: .
Programme:....

1
BMS Institute of Technology and Management | Dept of ECE
Microprocessor Lab Manual 10ECL68

Programme Educational Objectives

Graduates of the programme will:

PEO1: Work as professionals in the area of Electronics and allied engineering fields

PEO2: Pursue higher studies and involve in the interdisciplinary research work

PEO3: Exhibit ethics, professional skills and leadership qualities in their profession.

Programme Specific Outcomes

Graduates will be able to:

PSO1: Exhibit Competency in Embedded System and VLSI Design.


PSO2: Capability to comprehend the technological advancements in Radio Frequency
Communication and Digital Signal Processing.

2
BMS Institute of Technology and Management | Dept of ECE
Microprocessor Lab Manual 10ECL68

Programme Outcomes

1. Engineering knowledge: Apply the knowledge of mathematics, science, engineering


fundamentals, and an engineering specialization for the solution of complex engineering
problems.

2. Problem analysis: Identify, formulate, research literature, and analyse complex


engineering problems reaching substantiated conclusions using first principles of
mathematics, natural sciences, and engineering sciences.

3. 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 public health and safety, and cultural, societal, and
environmental considerations.

4. Conduct investigations of complex problems: The problems that cannot be solved by


straightforward application of knowledge, theories and techniques applicable to the
engineering discipline that may not have a unique solution.

5. Modern tool usage: Create, select, and apply appropriate techniques, resources, and
modern engineering and IT tools, including prediction and modelling to complex
engineering activities, with an understanding of the limitations.

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

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

8. Ethics: Apply ethical principles and commit to professional ethics and responsibilities
and norms of the engineering practice.

9. Individual and team work: Function effectively as an individual, and as a member or


leader in diverse teams, and in multidisciplinary settings.

10. Communication: Communicate effectively on complex engineering activities with the


engineering community and with t h e 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.

11. Project management and finance: Demonstrate knowledge and understanding of t h e


engineering and management principles and apply these to ones own work, as a member
and leader in a team, to manage projects and in multidisciplinary environments.

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

3
BMS Institute of Technology and Management | Dept of ECE
Microprocessor Lab Manual 10ECL68

COURSE OBJECTIVES

1. To become familiar with architecture and instruction set of Intel 8086


Microprocessor.
2. To provide practical hands on experience with assembly language programming.
3. To familiarizing the students with interfacing of various peripheral devices with
8086 Microprocessor.

Course Outcomes

At the end of the course, students will be able to :

CO1 : Apply the fundamentals of assembly level programming of 8086 microprocessor.

CO2 : Write programs and debug them using MASM tool.

CO3 : Analyze and design applications for 8086 using 8255PPI.

CO4 : Present technical reports of the experiements conducted throughout the course.

Lab In-charges

1. Mr. Anil Kumar D Assistant Professer Dept. of ECE


2. Mr. Shivarudraiah B Assistant Professer Dept. of ECE

Lab Insturctor

Mr. Shivamallu Instructor Dept. of ECE

4
BMS Institute of Technology and Management | Dept of ECE
Microprocessor Lab Manual 10ECL68

Instructions to students
1. Students must bring updated observation book, lab record and manual along with
necessary stationaries, no borrowing from others.
2. Students must handle the PCs and interfacing components carefully, as they are
expensive.
3. Before entering to lab, must prepare for viva for which they are going to conduct
experiment.
4. After the completion of the experiment should return the components to the
respective lab instructors.
5. Before leaving the lab, should switch off the power supply and arrange the chairs
properly.

5
BMS Institute of Technology and Management | Dept of ECE
Microprocessor Lab Manual 10ECL68

SYLLABUS

SUBJECT CODE : 10ECL68 IA MARKS : 25


SUBJECT : MICROPROCESSOR LAB EXAM HOURS: 03
EXAM MARKS : 50 HOURS/WEEK: 03
TOTAL HOURS : 42

I. Programs involving

1) Data transfer instructions like:


i] Byte and word data transfer in different addressing modes.
ii] Block move (with and without overlap)
iii] Block interchange
2) Arithmetic & logical operations like:
i] Addition and Subtraction of multi precision nos.
ii] Multiplication and Division of signed and unsigned Hexadecimal nos.
iii] ASCII ajustment instructions
iv] Code conversions
v] Arithmetic programs to find square cube, LCM, GCD, factorial
3) Bit manipulation instructions like checking:
i] Whether given data is positive or negative
ii] Whether given data is odd or even
iii] Logical 1s and 0s in a given data
iv] 2 out 5 code
v] Bit wise and nibble wise palindrome
4) Branch/Loop instructions like:
i] Arrays: addition/subtraction of N nos.
Finding largest and smallest nos.
Ascending and descending order
ii] Near and Far Conditional and Unconditional jumps, Calls and Returns
5) Programs on String manipulation like string transfer, string reversing,
Searching for a string, etc.
6) Programs involving Software interrupts
Programs to use DOS interrupt INT 21h Function calls for Reading a Character from
keyboard, Buffered Keyboard input, Display of character/ String on console
6
BMS Institute of Technology and Management | Dept of ECE
Microprocessor Lab Manual 10ECL68

II. Experiments on interfacing 8086 with the following interfacing modules through
DIO (Digital Input/Output-PCI bus compatible) card :

a) Matrix keyboard interfacing


b) Seven segment display interface
c) Logical controller interface
d) Stepper motor interface

III) Other Interfacing Programs


a) Interfacing a printer to an X86 microcomputer
b) PC to PC Communication

7
BMS Institute of Technology and Management | Dept of ECE
Microprocessor Lab Manual 10ECL68

Introduction to Microprocessors and 8086 Architecture:


Background

In 1972, Intel launched the 8008, the first 8-bit microprocessor It implemented an
instruction set designed by Datapoint corporation with programmable CRT terminals in
mind, that also proved to be fairly general purpose. The device needed several additional
ICs to produce a functional computer, in part due to its small 18-pin "memory-package",
which ruled out the use of a separate address bus (Intel was primarily a DRAM
manufacturer at the time).

Two years later, in 1974, Intel launched the 8080[4], employing the new 40-pin
DIL packages originally developed for calculator ICs to enable a separate address bus. It
had an extended instruction set that was source- (not binary-) compatible with the 8008
and also included some 16-bit instructions to make programming easier. The 8080 device,
often described as the first truly useful microprocessor, was nonetheless soon replaced by
the 8085 which could cope with a single 5V power supply instead of the three different
operating voltages of earlier chips.[5] Other well known 8-bit microprocessors that
emerged during these years were Motorola 6800 (1974), Microchip PIC16X (1975), MOS
Technology 6502 (1975), Zilog Z80 (1976), and Motorola 6809 (1977), as well as others.

The Intel 8086 high performance 16-bit CPU is available in three clock rates: 5, 8
and 10 MHz. The CPU is implemented in N-Channel, depletion load, silicon gate
technology (HMOS-III), and packaged in a 40-pin CERDIP or plastic package. The 8086
operates in both single processor and multiple processor configurations to achieve high
performance levels.
The following is a block diagram of internal organization of the Intel 8086
microprocessor.

8
BMS Institute of Technology and Management | Dept of ECE
Microprocessor Lab Manual 10ECL68

8086 Microprocessor Architecture

8086 pin configuration

9
BMS Institute of Technology and Management | Dept of ECE
Microprocessor Lab Manual 10ECL68

Instruction set of 8086 Microprocessor


8086 instruction set consists of the following instructions:
Data Transfer Instructions
MOV Move byte or word to register or memory
IN, OUT Input byte or word from port, output word to port
LEA Load effective address
LDS, LES Load pointer using data segment, extra segment
PUSH, POP Push word onto stack, pop word off stack
XCHG Exchange byte or word
XLAT Translate byte using look-up table

Logical Instructions
NOT Logical NOT of byte or word (one's complement)
AND Logical AND of byte or word
OR Logical OR of byte or word
XOR Logical exclusive-OR of byte or word
TEST Test byte or word (AND without storing)

Shift and Rotate Instructions


SHL, SHR Logical shift left, right byte or word by 1 or CL
SAL, SAR Arithmetic shift left, right byte or word by 1 or CL
ROL, ROR Rotate left, right byte or word by 1 or CL
RCL, RCR Rotate left, right through carry byte or word by 1 or CL

Arithmetic Instructions
ADD, SUB Add, subtract byte or word
ADC, SBB Add, subtract byte or word and carry (borrow)
INC, DEC Increment, decrement byte or word
NEG Negate byte or word (two's complement)
CMP Compare byte or word (subtract without storing)
MUL, DIV Multiply, divide byte or word (unsigned)
IMUL, IDIV Integer multiply, divide byte or word (signed)
CBW, CWD Convert byte to word, word to double word (useful
before multiply/divide)
AAA, AAS, AAM, AAD ASCII adjust for addition, subtraction, multiplication,
division (ASCII codes 30-39)
DAA, DAS Decimal adjust for addition, subtraction (binary coded
decimal numbers)

Transfer Instructions
JMP Unconditional jump
JA (JNBE) Jump if above (not below or equal)
JAE (JNB) Jump if above or equal (not below)
JB (JNAE) Jump if below (not above or equal)
JBE (JNA) Jump if below or equal (not above)
JE (JZ) Jump if equal (zero)

10
BMS Institute of Technology and Management | Dept of ECE
Microprocessor Lab Manual 10ECL68

JG (JNLE) Jump if greater (not less or equal)


JGE (JNL) Jump if greater or equal (not less)
JL (JNGE) Jump if less (not greater nor equal)
JLE (JNG) Jump if less or equal (not greater)
JC, JNC Jump if carry set, carry not set
JO, JNO Jump if overflow, no overflow
JS, JNS Jump if sign, no sign
JNP (JPO) Jump if no parity (parity odd)
JP (JPE) Jump if parity (parity even)
LOOP Loop unconditional, count in CX
LOOPE (LOOPZ) Loop if equal (zero), count in CX
LOOPNE (LOOPNZ) Loop if not equal (not zero), count in CX
JCXZ Jump if CX equals zero

Subroutine and Interrupt Instructions


CALL, RET Call, return from procedure
INT, INTO Software interrupt, interrupt if overflow
IRET Return from interrupt

String Instructions
MOVS Move byte or word string
MOVSB, MOVSW Move byte, word string
CMPS Compare byte or word string
SCAS Scan byte or word string
LODS, STOS Load, store byte or word string
REP Repeat
REPE, REPZ Repeat while equal, zero
REPNE, REPNZ Repeat while not equal (zero)

Processor Control Instructions


STC, CLC, CMC Set, clear, complement carry flag
STD, CLD Set, clear direction flag
STI, CLI Set, clear interrupt enable flag
LAHF, SAHF Load AH from flags, store AH into flags
PUSHF, POPF Push flags onto stack, pop flags off stack
ESC Escape to external processor interface
LOCK Lock bus during next instruction
NOP No operation (do nothing)
WAIT Wait for signal on TEST input
HLT Halt processor

11
BMS Institute of Technology and Management | Dept of ECE
Microprocessor Lab Manual 10ECL68

Addressing Modes of 8086


1. Implied - the data value/data address is implicitly associated with the instruction.
2. Register - references the data in a register or in a register pair.

3. Immediate - the data is provided in the instruction.


4. Direct - the instruction operand specifies the memory address where data is located.

5. Register indirect - instruction specifies a register containing an address, where data


is located. This addressing mode works with SI, DI, BX and BP registers.

6. Based - 8-bit or 16-bit instruction operand is added to the contents of a base register
(BX or BP), the resulting value is a pointer to location where data resides.

7. Indexed - 8-bit or 16-bit instruction operand is added to the contents of an index


register (SI or DI), the resulting value is a pointer to location where data resides.

8. Based Indexed - the contents of a base register (BX or BP) is added to the contents
of an index register (SI or DI), the resulting value is a pointer to location where data
resides.
9. Based Indexed with displacement - 8-bit or 16-bit instruction operand is added to
the contents of a base register (BX or BP) and index register (SI or DI), the resulting
value is a pointer to location where data resides.

12
BMS Institute of Technology and Management | Dept of ECE
Microprocessor Lab Manual 10ECL68

Introduction to MASM Software

EDITOR
An editor is a program, which allows you to create a file containing the assembly
language statements for your program. As you type in your program, the editor stores the
ASCII codes for the letters and numbers in successive RAM locations. When you have
typed in all of your programs, you then save the file on a floppy of hard disk. This file is
called source file. The next step is to process the source file with an assembler. In the
MASM assembler, you should give your source file name the extension, .ASM In
MASM, edit filename.asm is issued to edit the file.

ASSEMBLER
An assembler program is used to translate the assembly language mnemonics for
instructions to the corresponding binary codes. When you run the assembler, it reads the
source file of your program the disk, where you saved it after editing on the first pass
through the source program the assembler determines the displacement of named data
items, the offset of labels and pails this information in a symbol table. On the second pass
through the source program, the assembler produces the binary code for each instruction
and inserts the offset etc that is calculated during the first pass. The assembler generates
two files on floppy or hard disk. The first file called the object file is given the extension.
OBJ. The object file contains the binary codes for the instructions and information about
the addresses of the instructions. The second file generated by the assembler is called
assembler list file. The list file contains your assembly language statements, the binary
codes for each instructions and the offset for each instruction. In TASM assembler,
TASM source file name ASM is used to assemble the file. Edit source file name LST is
used to view the list file, which is generated, when you assemble the file. In MASM,
masm filename.asm is issued to assemble the file.

LINKER
A linker is a program used to join several object files into one large object file and
convert to

13
BMS Institute of Technology and Management | Dept of ECE
Microprocessor Lab Manual 10ECL68

an exe file. The linker produces a link file, which contains the binary codes for all the
combined modules. The linker however doesnt assign absolute addresses to the program,
it assigns is said to be relocatable because it can be put anywhere in memory to be run. In
MASM, LINK source filename is used to link the file. In MASM, link filename.obj is
issued to link the file.

DEBUGGER
A debugger is a program which allows you to load your object code program into system
memory, execute the program and troubleshoot or debug it. the debugger allows you to
look at the contents of registers and memory locations after your program runs. It allows
you to change the contents of register and memory locations after your program runs. It
allows you to change the contents of register and memory locations and return the
program. A debugger also allows you to set a break point at any point in the program. If
you inset a breakpoint the debugger will run the program upto the instruction where the
breakpoint is set and stop execution. You can then examine register and memory contents
to see whether the results are correct at that point. In MASM, debug filename.exe is
issued to debug the file.

DEBUGGER FUNCTIONS
1. Debugger allows to look at the contents of registers and memory locations.
2. We can extend 8-bit register to 16-bit register which the help of extended register
option.
3. Debugger allows to set breakpoints at any point with the program.
4. The debugger will run the program up to the instruction where the breakpoint is set and
then stop execution of program. At this point, we can examine register and memory
contents at that point.
5. With the help of dump we can view register contents.
6. One can trace the program step by step with the help of t.
7. One can execute the program completely (one step execution) at a time using g.

DEBUGGER COMMANDS
DUMP: To see the specified memory contents

14
BMS Institute of Technology and Management | Dept of ECE
Microprocessor Lab Manual 10ECL68

D memory location first address last address


(Which displays the set of values stored in the specified range, which is given above?)
Eg: d 0100 0105 <cr>
Display the contents of memory locations from 100 to 105(including).
QUIT: To exit from the debugger.
Q <cr>
REGISTER: Shows the contents of Registers
R register name
Eg: r ax
Shows the contents of register.
TRACE: To trace the program instruction by instruction.
T <cr>: traces only the current instruction. (Instruction specified by IP)
T2 <cr>: Traces the next two instructions
UNASSEMBLE: To unassembled the program.
Shows the opcodes along with the assembly language program.
U <cr>
GO: To execute the program
G: one time instructions execution (address specified by IP)

Commands for executing the programs :


1. masm filename.asm;
2. link filename.obj;
3. debug filename.exe

15
BMS Institute of Technology and Management | Dept of ECE
Microprocessor Lab Manual 10ECL68

SIMULATION PROGRAMS

16
BMS Institute of Technology and Management | Dept of ECE
Microprocessor Lab Manual 10ECL68

1. PROGRAMS FOR DATA


TRANSFER IN DIFFERENT
ADDRESSING MODES

17
BMS Institute of Technology and Management | Dept of ECE
Microprocessor Lab Manual 10ECL68

A) REGISTER ADDRESSING MODE

.model small
.code
mov al, 05h
mov cl, al
mox bx,0600h
mov dx, bx
mov ah, 4ch
int 21h
end

Result:
Before Execution : Ax=0000 , Cx=0000 , Bx=0000, Dx=0000
After Execution : Ax=0005 , Cx=0005 , Bx=0600, Dx=0600

B) IMMEDIATE ADDRESSING MODE

.model small
.code
mov al,25h
mov bl,25h
mov cl,10010010b
mov dl,A
mov ah, 4ch
int 21h
end

Result:
Before Execution : Ax=0000 , Cx=0000 , Bx=0000, Dx=0000
After Execution : Ax=0025 , Bx=0025, Cx=0092, Dx=0041

18
BMS Institute of Technology and Management | Dept of ECE
Microprocessor Lab Manual 10ECL68

C) DIRECT ADDRESSING MODE

.model small
.data
d1 db 05h
d2 db 06h
d3 dw (?)
.code
mov ax,@data
mov ds,ax
mov cl,d1
mov ch,d2
mov d3,cx
moh ah,4ch
int 21h
end

Result:
Before Execution: 1098=05 After Execution: cx=0605
1099=06

D) INDIRECT ADDRESSING MODE


.model small
.data
d1 dw 0406h
d2 dw 00h
.code
mov ax, @data
mov ds,ax
mov si, offset d1
mov ax,[si]
mov di, offset d2
mov [di],ax
mov ah,4ch
int 21h
end

Result:
Before Execution: Si=0000 After Execution:Si=0004
di=0000 di=0006

19
BMS Institute of Technology and Management | Dept of ECE
Microprocessor Lab Manual 10ECL68

E) TO MOVE A BLOCK OF DATA (BYTE) WITHOUT OVERLAP.

.model small ; Create a model with one data and one code segment
.data ; Initialize data segment
d1 db 01h,02h,03h,04h.05h ; Define the input data.
d2 db 05h dup(?) ; Reserve output memory locations
.code ; Initialize code segment
mov ax, @data ; Starting address of data segnment
mov ds,ax
mov es,ax
mov cx,05h ; Initializing the counter
mov si,offset d1 ; starting address of d1 is moved to si
mov di,offset d2 ; starting address of d2 is moved to di
bk: mov al,[si] ; move the content of Memory location pointed by SI to al reg.
mov [di],al ; move al content of Memory location pointed by DI reg.
inc si ; Incrment Si register
inc di ; Incrment di register
dec cx ; Decrement counter
jnz bk ; jump to label if counter is not 0, else proceed next.
mov ah,4ch ; call DOS interrupt
int 21h
end ; Instruct Assembler to stop the execution.

Result:
Before Execution: d1[0001]: 01 02 03 04 05
D2[0006]: 00 00 00 00 00
After Execution d1[0001]: 01 02 03 04 05
D2[0006]: 01 02 03 04 05

20
BMS Institute of Technology and Management | Dept of ECE
Microprocessor Lab Manual 10ECL68

F) TO MOVE A BLOCK OF DATA (WORD) WITHOUT OVERLAP.

.model small
.data
d1 dw 0120h,0100h,1000h ; Define word input data
count equ ($-d1)/2 ; Define the counter
d2 dw 0Ah dup(?)
.code
mov ax, @data
mov ds,ax
mov es,ax
mov cx,count
mov si,offset d1
mov di,offset d2
bk: mov ax,[si]
mov [di],ax
add si,2 ; Increment SI by 2 times
add di,2 ; Increment Di by 2 times
loop bk ; Decrement the counter and check for zero flag
mov ah,4ch
int 21h
end

Result:
Before Execution:d1[ 0001]: 20 01 00 01 00 10
D2[0006]: 00 00 00 00 00 00
After Execution: d1[0001]: 20 01 00 01 00 10
D2[0006]: 20 01 00 01 00 10

21
BMS Institute of Technology and Management | Dept of ECE
Microprocessor Lab Manual 10ECL68

G) TO INTERCHANGE A BLOCK OF DATA (BYTE)

.model small
.data
d1 db 01h,02h,03h,04h
d2 db 05h,06h,07h,08h
count db 04h
.code
mov ax, @data
mov ds,ax
mov si,offset d1
mov di,offset d2
mov cl,count
bk: mov al,[si] ; move the content of Memory location pointed by SI to al
mov ah,[di] ; move the content of Memory location pointed by DI to ah
mov [si],ah ; Store ah content to Memory location pointed by SI
mov [di],al ; Store al content to Memory location pointed by DI
inc si
inc di
dec cl
jnz bk
mov ah,4ch
int 21h
end

Result:
Before Execution: d1[0001]: 01 02 03 04
D2[0006]: 05 06 07 08
After Execution: d1[0001]: 05 06 07 08
D2[0006]: 01 02 03 04

22
BMS Institute of Technology and Management | Dept of ECE
Microprocessor Lab Manual 10ECL68

H) TO INTERCHANGE A BLOCK OF DATA (WORD)

.model small
.data
d1 dw 1000h,2000h,3000h ; Define input word data
d2 dw 4000h,5000h,6000h ; Define input word data
count equ 03h
.code
mov ax, @data
mov ds,ax
mov si,offset d1
mov di,offset d2
mov cx,count
bk: mov ax,[si]
mov bx,[di]
mov [si],bx
mov [di],ax
add si,2 ; Increment SI by 2 times
add di,2 ; Increment DI by 2 times
loop bk ; Decrement counter and check for zero flag
mov ah,4ch
int 21h
end

Result:
Before Execution: 0001: 00 10 00 20 00 30
0006: 00 40 00 50 00 60
After Execution: 0001: 00 40 00 50 00 60
0006: 00 10 00 20 00 30

23
BMS Institute of Technology and Management | Dept of ECE
Microprocessor Lab Manual 10ECL68

I) TO TRANSFER A BLOCK OF DATA(BYTE) WITH OVERLAP.

.model small
.data
d1 db 01h,02h,03h,04h,05h
count equ ($-d1) ; Initialize the counter
x equ count/2 ; Divide the counter by 2
.code
mov ax,@data
mov ds,ax
mov es,ax
mov cx,count
LEA SI,d1 ; Initialize SI with offset address of d1
LEA DI,d1+x ; Initialize DI with sum of offset address of d1 & counter value
dec cx ; Decrement the counter
add SI,cx : Add counter value to SI address
add DI,cx ; Add counter value to DI address
inc cx
bk: mov al,[SI]
mov [DI],al
dec SI
dec DI
loop bk
mov ah,4ch
int 21h
end

Result:
Before Execution: 0001: 01 02 03 04 05 06
After Execution: 0001: 01 02 01 02 03 04 05 06

24
BMS Institute of Technology and Management | Dept of ECE
Microprocessor Lab Manual 10ECL68

J) TO TRANSFER A BLOCK OF DATA (WORD) WITH OVERLAP

.model small
.data
d1 dw 0001h,0002h,0003h,0004h,0005h
count equ ($-d1)/2

.code
mov ax,@data
mov ds,ax
mov cx,count
LEA SI,d1
LEA DI,d1+count

dec cx
mov ax,cx
rol ax,01

add SI,ax
add DI,ax
inc cx

bk:mov ax,[SI]
mov [DI],ax
dec SI
dec SI
dec DI
dec DI
loop bk
mov ah,4ch
int 21h
end

Result:
Before Execution: 0001: 00 10 00 20 00 30 00 40 00 50 00 60
After Execution: 0001: 00 10 00 20 00 10 00 20 00 30 00 40 00
50 00 60

25
BMS Institute of Technology and Management | Dept of ECE
Microprocessor Lab Manual 10ECL68

2. PROGRAMS ON ARITHMATIC
AND LOGICAL OPERATIONS

A) TO ADD THREE BYTES OF DATA

26
BMS Institute of Technology and Management | Dept of ECE
Microprocessor Lab Manual 10ECL68

.model small
.data
X db 0FFh,0AAh,30h
Count equ($-x)
result dw ? ; Reserve two memory locations to store the result
.code
mov ax, @data
mov ds,ax
lea si,x
mov cx,count
mov ax,00h ; Initialize accumulator to zero to perform addition
bk: add al,[si] ; add the content of memory location pointed by SI , with al
jnc next ; check for carry flag
inc ah ; store the carry in ah register
next: inc si
loop bk ; decrement the counter and check for zero flag
mov result,ax ; store the sum in result and carry in next memory location
mov ah,4ch
int 21h
end

Result:
Before Execution: 109A: FF AA 30
After Execution: 109A: FF AA 30 D9 01

27
BMS Institute of Technology and Management | Dept of ECE
Microprocessor Lab Manual 10ECL68

B) TO ADD THREE WORDS OF DATA

.model small
.data
X dw 0FFFFh,0AAAAh,3000h
Count equ($-x)/2
result dw 02h dup(?)
.code
mov ax, @data
mov ds,ax
lea si,x
mov cx,count
mov ax,00h
mov dx,ax
bk: add ax,[si]
jnc next
inc dx
next: add si,2
loop bk
mov result,ax
mov result+2,dx
mov ah,4ch
int 21h
end

Result:
Before Execution: 109A: FF FF AA AA 00 30
After Execution: 109A: FF FF AA AA 00 30 A9 DA 01

28
BMS Institute of Technology and Management | Dept of ECE
Microprocessor Lab Manual 10ECL68

C) TO PERFORM 8BIT SIGNED MULTIPLICATION OF ANY GIVEN


NUMBER

.model small
.data
d1 db -6h ; initialize a signed input data
d2 db 23h
d3 dw (?)
.code
mov ax,@data
mov ds,ax
mov al,d1
mov dh,d2
imul dh ; perform signed multiplication of AL and DH
mov d3,ax ; store the product in output memory location
mov ah,4ch
int 21h
end

Result:
Before Execution: 0010: FA 23
After Execution: 0010: FA 23 2E FF

29
BMS Institute of Technology and Management | Dept of ECE
Microprocessor Lab Manual 10ECL68

D) TO PERFORM 8BIT UNSIGNED MULTIPLICATION OF ANY GIVEN


NUMBER

.model small
.data
d1 db 66h
d2 db 23h
d3 dw (?)
.code
mov ax,@data
mov ds,ax
mov al,d1
mov dh,d2
mul dh ; multiply AL content with DH content and store product in AX register
mov d3,ax
mov ah,4ch
int 21h
end

Result:
Before Execution: 0010: 66 23
After Execution: 0010: FA 23 F2 0D

30
BMS Institute of Technology and Management | Dept of ECE
Microprocessor Lab Manual 10ECL68

E) TO PERFORM 16BIT SIGNED MULTIPLICATION OF TWO NUMBERS

.model small
.data
d1 dw 0AAAAh
d2 dw 3000h
d3 dw (?)
d4 dw (?)
.code
mov ax,@data
mov ds,ax
mov ax,d1
mov di,d2
imul di ; multiply DI content with AH content and store product in AX and DX
mov d3,ax
mov d4,dx
mov ah,4ch
int 21h
end

Result:
Before Execution: 0010: AA AA 00 30
After Execution: 0010: AA AA 00 30 00 E0 FF EF

F) TO PERFORM 16BIT BY 8BIT UNSIGNED DIVISION OF TWO NUMBERS

.model small
.data
d1 dw 0076h
d2 db 04h
d3 dw ?
.code
mov ax,@data
mov ds,ax
mov ax,d1
mov cl,d2
div cl ; divide AL contents by CL contents
mov d3,ax ; store the quotient in AL and remainder in AH
mov ah,4ch
int 21h
end

Result:
Before Execution: 0020: 76 00 04
After Execution: 0020: 76 00 04 1D 02

31
BMS Institute of Technology and Management | Dept of ECE
Microprocessor Lab Manual 10ECL68

G) TO PERFORM 32BIT BY 16BIT SIGNED DIVISION.

.model small
.data
d1 dw 1132h,2345h
d2 dw -4234h
res dw 02 dup(?)
.code
mov ax,@data
mov ds,ax
mov dx,d1
mov ax,d1+2
mov bx,d2
idiv bx ; divide AX by DX
mov res,ax ; store the quotient in RES
mov res+2,dx ; store the remainder in DX
mov ah,4ch
int 21h
end

Result:
Before Execution: 0010: 32 11 45 23 CC BD
After Execution: 0010: 32 11 45 23 CC BD 82 BD AD 25

32
BMS Institute of Technology and Management | Dept of ECE
Microprocessor Lab Manual 10ECL68

H) TO FIND THE SQUARE OF A GIVEN NUMBER.

.model small
.data
d1 db 06h
d2 dw (?)
.code
mov ax,@data
mov ds,ax
mov al,06h
mov cl,al
mul cl
mov d2,ax
mov ah,4ch
int 21h
end

Result:
Before Execution 0010 : 06
After Execution 0010: 06 24

33
BMS Institute of Technology and Management | Dept of ECE
Microprocessor Lab Manual 10ECL68

I) TO FIND THE CUBE OF A GIVEN NUMBER.

.model small
.data
d1 db 06h
d2 dw (?)
d3 dw (?)
.code
mov ax,@data
mov ds,ax
mov al,d1
mov cl,al
mul cl
mov ch,00h
mul cx
mov d3,dx
mov d2,ax
mov ah,4ch
int 21h
end

Result:
Before Execution 0010 : 06
After Execution 0010: 06 D8

34
BMS Institute of Technology and Management | Dept of ECE
Microprocessor Lab Manual 10ECL68

J) TO FIND THE GCD OF TWO NUMBERS

.model small
.data
d1 dw 15,4
gcd dw (?)
.code
mov ax,@data
mov ds,ax
mov ax,d1
mov bx,d1+2
cmp ax,bx
ja divide
xchg ax,bx ; Swap AX and BX contents
divide:mov dx,00
div bx ; Divide AX by BX
cmp dx,00
jz last
mov ax,bx
mov bx,dx
jmp divide
last:mov gcd,bx ; Store the GCD number in the memory location.
mov ah,4Ch
int 21h
end

Result:
Before Execution: 1100: 0F 00 04 00
After Execution: 1100: 0F 00 04 00 01 00

35
BMS Institute of Technology and Management | Dept of ECE
Microprocessor Lab Manual 10ECL68

K) TO FIND THE LCM OF TWO NUMBERS.

.model small
.data
d1 dw 47bh
d2 dw 47ch
res dw 02 dup(?)
.code
mov ax,@data
mov ds,ax
mov ax,d1
mov bx,d2
mov dx,00
cmp ax,bx
ja l1 ; Jump to the label if AX is above than BX, else next
xchg ax,bx ; Swap AX and BX contents
l1: mov cx,ax
l2: push ax ; Store AX and DX contents in the stack memory
push dx
div bx
cmp dx,00h
jz last
pop dx ; Retrieve AX and DX contents from the stack memory
pop ax
add ax,cx
jnc l3
inc dx
l3: jmp l2
last: pop dx ; Retrieve AX and DX contents from the stack memory
pop ax
mov res,ax ; Store the LCM of the number in the memory location
mov res+2,dx
mov ah,4ch
int 21h
end

Result:
Before Execution: 0010: 7B 04 7C 04
After Ececution: 0010: 7B 04 7C 04 94 17 14 00

36
BMS Institute of Technology and Management | Dept of ECE
Microprocessor Lab Manual 10ECL68

L) WAP TO CONVERT BINARY TO BCD NUMBER(8 BITS)

.model small
.data
n1 db 63h
res db 03 dup(?),$
.code
mov ax,@data
mov ds,ax
mov al,n1
mov ah,00
mov bl,100
div bl
add al,30h ;
mov res,al
mov al,ah
mov ah,00
mov bl,10
div bl
add al,30h
mov res+1,al
add ah,30h
mov res+2,ah
lea dx,res ; store the BCD no. in DX register to display on the screen
mov ah,09h ; call display interrupt to display the BCD result
int 21h
mov ah,4ch
int 21h
end

Result: 099

37
BMS Institute of Technology and Management | Dept of ECE
Microprocessor Lab Manual 10ECL68

M) TO CONVERT BCD TO BINARY NUMBER(8 BIT)

.model small
.data
bcd db 34d
binary db (?)
.code
mov ax,@data
mov ds,ax
mov al,bcd
mov cl,04h
rol al,cl
and al,0fh
mov bl,10h
mul bl
add binary,al
mov al,bcd
and al,0fh
add binary,al
mov ah,4ch
int 21h
end

Result:
Before Execution: 0004: 34
After Execution:0004: 34 22

38
BMS Institute of Technology and Management | Dept of ECE
Microprocessor Lab Manual 10ECL68

N) TO CONVERT BCD TO ASCII NUMBER (8 BIT)


.model small
.data
bcdip db 56h
askiop dw 0

.code
mov ax,@data
mov ds,ax

xor ax,ax
mov al, bcdip
mov dl,al
and al,0f0h
mov cl,4
ror al,cl
mov bh,al
and dl,0fh
mov bl,dl
add bx,3030h
mov askiop,bx ; Store ASCII output in the memory location

mov ah,4ch
int 21h
end

Result:
Before Execution: askiop[ ]:0000
After Execution: askiop[ ]:3536

39
BMS Institute of Technology and Management | Dept of ECE
Microprocessor Lab Manual 10ECL68

O) TO FIND THE FACTORIAL OF A NUMBER( USING RECURSIVE


PROCEDURE)

.model small
.data
d1 db 05h
res dw 02h dup(?)
.code
mov ax,@data
mov ds,ax
mov bl,d1
mov dx,00
call fact ; Call subroutine - fact
mov res,ax
mov res+2,dx
mov ah,4ch
int 21h
fact proc near ; Subroutine program begins
cmp bx,01h
jb last
push bx ; Store the BX value in stack memory
dec bx
call fact
pop bx ; Retrieve BX from the Stack memory
mul bx
ret ; end of the subroutine and move to the main program
last: mov ax,01h
ret
fact endp
end

Result:
Before Execution:1100: 05 00
After Execution: 1100: 05 78

40
BMS Institute of Technology and Management | Dept of ECE
Microprocessor Lab Manual 10ECL68

P) ASCII ADDITION

.model small
.data
ip1 db '9',0dh,0ah
ip2 db '6',0dh,0ah
res db ?,?

.code
mov ax,@data
mov ds,ax

xor ax,ax
mov al,ip1
add al,ip2
aaa ; ASCII ADJUST ACCUMULATOR
mov res,al
mov res+1,ah

mov ah,4ch
int 21h
end

Result:
Before Execution:res[ ]: 00
After Execution: res[ ]: 0105

Exercise:
1. WAP to subtract byte/word data
2. WAP to perform 16 bit by 8 bit signed and unsigned division
3. WAP to convert ASCII to BCD.
4. WAP to perform ASCII subtraction.

41
BMS Institute of Technology and Management | Dept of ECE
Microprocessor Lab Manual 10ECL68

3. BIT MANIPULATION
PROGRAMS

42
BMS Institute of Technology and Management | Dept of ECE
Microprocessor Lab Manual 10ECL68

A) TO FIND WHETHER GIVEN NUMBER(BYTE) IS ODD OR EVEN

.model small
.data
num db 0Ah
msg1 db given number is odd,$ ; Initialize a string message
msg2 db given number is even,$
.code
mov ax, @data
mov ds,ax
mov al,num
ror al,01h
jc bk
lea dx,msg2 ; Load the string message 2 on to DX register
jmp last
bk: lea dx, msg1
last: mov ah,09h ; Display the string message on the screen
int 21h
mov ah,4ch
int 21h
end

Result:
0Ah-- given number is even
011h-- given number is 0dd

43
BMS Institute of Technology and Management | Dept of ECE
Microprocessor Lab Manual 10ECL68

B) TO FIND WHETHER GIVEN NUMBER(BYTE) IS POSITIVE OR


NEGATIVE

.model small
.data
num db 80h
msg1 db given number is positive,$
msg2 db given number is negative,$
.code
mov ax, @data
mov ds,ax
mov al,num
rol al,01h
jc bk
lea dx,msg1
jmp last
bk: lea dx, msg2
last: mov ah,09h
int 21h
mov ah,4ch
int 21h
end

Result:
0Ah-- given number is positive
80h-- given number is negative

44
BMS Institute of Technology and Management | Dept of ECE
Microprocessor Lab Manual 10ECL68

C) TO COUNT NUMBER OF 0S AND 1S IN A GIVEN BYTE

.model small
.data
X db 09h
d1 db 01 dup(?)
d2 db 01 dup(?)
.code
mov ax,@data
mov ds,ax
mov cx,08h
mov bx,00h
mov al,x
bk: ror al,01h
jc loop1
inc bl
jmp l2
loop1:inc bh
l2: loop bk
mov d1,bl
mov d2,bh
mov ah,4ch
int 21h
end

Result:
Before Execution 000C: 09
After Execution 000C: 09 06 02

45
BMS Institute of Technology and Management | Dept of ECE
Microprocessor Lab Manual 10ECL68

D) TO FIND WHETHER A GIVEN NUMBER IS 2 OUT OF 5 CODE

.model small
.data
num db 0Ah
msg1 db 2 out of 5 code,$
msg1 db not 2 out of 5 code,$
.code
mov ax,@data
mov ds,ax
mov al,num
and al,0E0h
jnz last
mov al,num
mov cl,05h
mov bl,00h
bk: ror al,01h
jnc l1
inc bl
l1: loop bk
cmp bl,02h
jnz last
lea dx,msg1
jmp l2
last:lea dx,msg2
l2: mov ah,09h
int 21h
mov ah,4ch
int 21h
end

Result:
0A--2 out of 5 code
07not 2 out of 5 code

46
BMS Institute of Technology and Management | Dept of ECE
Microprocessor Lab Manual 10ECL68

E) TO CHECK IF A NUMBER(BYTE) IS BITWISE PALINDROME

.model small
.data
d1 db 81h
msg1 db the number is bitwise palindrome,$
msg2 db the number is not a bitwise palindrome,$
.code
mov ax,@data
mov ds,ax
mov al,d1
mov bl,00h
mov cl,08h
bk: ror al,01h
rcl bl,01h
dec cl
jnz bk
cmp bl,d1
jnz l1
lea dx,msg1
jmp last
l1: lea dx,msg2
last: mov ah,09h
int 21h
mov ah,4ch
int 21h
end

Result:81-- the number is bitwise palindrome


35-- the number is not bitwise palindrome

47
BMS Institute of Technology and Management | Dept of ECE
Microprocessor Lab Manual 10ECL68

F) TO CHECK IF A GIVEN NUMBER IS NIBBLE WISE PALINDROME OR


NOT

.model small
.data
S1 dw 1020h
msg1 db the number is nibble wise palindrome,$
msg2 db the number is not nibble wise palindrome,$
.code
mov ax,@data
mov ds,ax
mov ax,d1
mov cl,04h
ror al,cl
cmp ah,al
jnz l2
lea dx,msg1
jmp last
l2: lea dx,msg2
last: mov ah,09h
int 21h
mov ah,4ch
int 21h
end

Result: 8118-- the number is nibble wise palindrome


1020-- the number is not nibble wise palindrome

Exercise:
1. WAP to check if a given number (word) is positive or negative.
2. WAP to check if a given number (word) is odd or even.
3. WAP to whether the given number (word) is bit wise or nibble wise palindrome.
4. WAP to check the number of 1s and 0s in a given data(word).

48
BMS Institute of Technology and Management | Dept of ECE
Microprocessor Lab Manual 10ECL68

4.PROGRAMS ON BRANCH AND


LOOP INSTRUCTIONS

49
BMS Institute of Technology and Management | Dept of ECE
Microprocessor Lab Manual 10ECL68

A) TO ADD MULTIBYTE NUMBER.

.model small
.data
n1 db 23h,43h,66h,47h
n2 db 44h,77h,69h,90h
count equ($-n2)
sum db count+1 dup(?)
.code
mov ax,@data
mov ds,ax
mov cx,count
mov si,00h
mov ax,00h
clc ; Clear carry flag
l1: mov al,n1[si]
adc al,n2[si]
mov sum[si],al
inc si
dec cx
jnz l1
mov al,00h
adc al,00h
mov sum[si],al
mov ah,4ch
int 21h
end

Result:
Before Execution: 109A: 23 43 66 47 44 77 69 90
After Execution: 109A: 23 43 66 47 44 77 69 90 67 BA CF DF 00

50
BMS Institute of Technology and Management | Dept of ECE
Microprocessor Lab Manual 10ECL68

B) TO SUBTRACT MULTIBYTE NUMBER.

.model small
.data
n1 db 44h,77h,69h,90h
n2 db 23h,43h,66h,47h
count equ($-n2)
sum db count+1 dup(?)
.code
mov ax,@data
mov ds,ax
mov cx,count
mov si,00h
mov ax,00h
clc
l1: mov al,n1[si]
sbb al,n2[si]
mov sum[si],al
inc si
dec cx
jnz l1
mov al,00h
adc al,00h
mov sum[si],al
mov ah,4ch
int 21h
end

Result:
Before Execution: 109A: 44 77 69 90 23 43 66 47
After Execution: 109A: 44 77 69 90 23 43 66 47 21 34 03 49

51
BMS Institute of Technology and Management | Dept of ECE
Microprocessor Lab Manual 10ECL68

C) TO FIND THE SMALLEST NUMBER IN AN GIVEN ARRAY

.model small
.data
X db 10h,05h,0FFh,30h
l equ($-x-1)
Smallest db ?
.code
mov ax, @data
mov ds,ax
lea bx,x
mov cx,l
mov al,[bx]
bk: inc bx
cmp al,[bx]
jc last
mov al,[bx]
last: loop bk
mov smallest,al
mov ah,4ch
int 21h
end

Result:
Before Execution 0010 : 10 05 FF 30
After Execution 0010: 10 05 FF 30 05

52
BMS Institute of Technology and Management | Dept of ECE
Microprocessor Lab Manual 10ECL68

D) TO FIND THE LARGEST NUMBER IN AN GIVEN ARRAY

.model small
.data
X db 10h,05h,20h,30h
l equ($-x-1)
largest db ?
.code
mov ax, @data
mov ds,ax
lea bx,x
mov cx,l
mov al,[bx]
bk: inc bx
cmp al,[bx]
jnc last
mov al,[bx]
last: loop bk
mov largest,al
mov ah,4ch
int 21h
end

Result:
Before Execution 0010 : 10 05 20 30
After Execution 0010: 10 05 FF 30 30

53
BMS Institute of Technology and Management | Dept of ECE
Microprocessor Lab Manual 10ECL68

E) TO SORT THE GIVEN ARRAY (BYTE) IN ASCENDING ORDER

.model small
.data
X db 10h,01h,20h,05h
l equ($-x)
.code
mov ax,@data
mov ds,ax
mov cx,l
mov dx,l
l1: lea bx,x
mov cx,dx
bk: mov al,[bx]
inc bx
cmp al,[bx]
jc last
xchg al,[bx]
mov [bx-1],al
last: loop bk
dec dx
jnz l1
mov ah,4ch
int 21h
end

Result:
Before Execution:0010: 10 01 20 05
After Execution:0010: 01 05 10 20

54
BMS Institute of Technology and Management | Dept of ECE
Microprocessor Lab Manual 10ECL68

F) TO SORT THE GIVEN ARRAY(BYTE) IN DESCENDING ORDER

.model small
.data
X db 10h,01h,00h,05h
l equ($-x)
.code
mov ax,@data
mov ds,ax
mov cx,l
mov dx,l
l1: lea bx,x
mov cx,dx
bk: mov al,[bx]
inc bx
cmp al,[bx]
jnc last
xchg al,[bx]
mov [bx-1],al
last: loop bk
dec dx
jnz l1
mov ah,4ch
int 21h
end

Result:
Before Execution:0010: 10 01 00 05
After Execution:0010: 10 05 01 00

55
BMS Institute of Technology and Management | Dept of ECE
Microprocessor Lab Manual 10ECL68

G) PROGRAMS ON CONDITIONAL AND UNCONDITIONAL CALL AND


RETURN.

(i) To read 10 bytes and store it in memory.

CALLED PROGRAM

.model small
.data
Public nums
Nums db 100 dup (?)

.code
mov ax,@data
mov ds,ax
public read_kb
read_kb proc far
mov ah,01h
int 21h
ret
read_kb end proc
mov ah,4ch
int 21hend

CALLING PROGRAM
.model small
.data
extrn nums:byte

.code
Extrn read_kb:far
Mov ax,@data
Mov ds,ax
Mov cx,10
Mov si,00
Nxt:call read_kb
Mov num[si],al
Inc si
Loop nxt
Mov ah,4ch
Int 21h
End

Result:
Before Execution:000A: 00 00 00 00 00 00 00 00 00 00
After Execution:000A: 70 6D 61 78 49 4F 5C 3D 2A 1B

56
BMS Institute of Technology and Management | Dept of ECE
Microprocessor Lab Manual 10ECL68

(ii) To read a key and echo it on monitor

CALLED PROGRAM

.model small
.code
Public rdkey
Rdkey proc far
Mov ah,01h
Int 21h
Ret
Rdkey endp
mov ah,4ch
int 21h
end

CALLING PROGRAM
.model small
.code
Extrn rdkey:far
Call rdkey
Call echo
Mov ah,4ch
Int 21h
Echo proc near
Mov dl,al
Mov al,02h
Int 21h
Ret
Echo endp
End

Result:
Input z
C:\MASM degug <calling pgm.exe>
zz

Exercise:
1. WAP to find the smallest number in the given data(word).
2. WAP to find the largest number in the given data(word).
3. WAP to sort the given array(word) in descending order.
4. WAP to sort the given array(word) in ascending order.

57
BMS Institute of Technology and Management | Dept of ECE
Microprocessor Lab Manual 10ECL68

5. PROGRAMS ON STRING
MANIPULATION

58
BMS Institute of Technology and Management | Dept of ECE
Microprocessor Lab Manual 10ECL68

A) TO TRANSFER THE SOURCE STRING TO DESTINATION STRING.

.model small
.data
S1 db MICRO
count equ($-s1)
S2 db 0Ah dup(?)
.code
mov ax,@data
mov ds,ax
mov es,ax
mov si,offset s1
mov di,offset s2
mov cx,count
cld ; Clear direction flag
rep movsb
mov ah,4ch
int 21h
end

Result:
Before Execution:0008: MICRO
After Execution:0008: MICRO
000E:MICRO

59
BMS Institute of Technology and Management | Dept of ECE
Microprocessor Lab Manual 10ECL68

B) TO PERFORM THE REVERSE OF THE STRING

.model small
.data
String db lab,$
count equ($-string-1)
l equ count/2
.code
mov ax,@data
mov ds,ax
lea si,string
lea di,string+count-1
mov cx,l
bk: mov al,[si]
mov ah,[di]
mov [si],ah
mov [di],al
inc si
dec di
loop bk
lea dx,string
mov ah,09h
int 21h
mov ah,4ch
int 21h
end

Result:
Before Execution: lab
After Execution: bal

60
BMS Institute of Technology and Management | Dept of ECE
Microprocessor Lab Manual 10ECL68

C) TO SEARCH A CHARACTER IN A STRING.

.model small
.data
String db lab,$
Count equ($-string-1)
Search db b
msg1 db The character is found,$
msg2 db The character is not found,$
.code
mov ax,@data
mov ds,ax
lea si,string
lea di,search
mov cx,count
bk: mov al,[si]
cmp al,[di]
jz last
inc si
loop bk
lea dx,msg2
jmp next
last: lea dx,msg1
next: mov ah,09h
int 21h
mov ah,4ch
int 21h
end

Result:
b-- The character is found
e-- The character is not found

61
BMS Institute of Technology and Management | Dept of ECE
Microprocessor Lab Manual 10ECL68

D) TO CHECK WHETHER A STRING IS PALINDROME OR NOT.

.model small
.data
String db madam,$
Count equ($-string-1)
l equ count/2
msg1 db string is palindrome,$
msg2 db string is not palindrome,$
.code
mov ax,@data
mov ds,ax
mov es,ax
lea si,string
lea di,string+count-1
mov cx,l
bk: mov al,[si]
cmp [di],al
jnz last
inc si
dec di
loop bk
lea dx,msg1
jmp l1
last: lea dx,msg2
l1:mov ah,09h
int21h
mov ah,4ch
int 21h
end

Result:
madam-- string is palindrome
Spl-- string is not palindrome

Exercise:
1.WAP to search a word in a given string.
2. WAP to insert a word in a given string.
3. WAP to delete a character in a given string.
4. WAP to insert a letter in a given string.

62
BMS Institute of Technology and Management | Dept of ECE
Microprocessor Lab Manual 10ECL68

6. PROGRAMS INVOLVING
SOFTWARE INTERRUPTS

63
BMS Institute of Technology and Management | Dept of ECE
Microprocessor Lab Manual 10ECL68

A) TO READ A CHARACTR FROM KEYBOARD

.model small
.data
msg1 db 0ah,0dh,'Enter a number: $'
res db 00

.code
mov ax,@data
mov ds,ax

mov ah,09h ; call the dos interrupt to display the message on the screen
LEA dx,msg1
int 21h

mov ah,01h ; call the dos interrupt to accept the input from the keyboard
LEA dx,msg1

int 21h
sub al,30h
mov res,al ; Store the result in the memory location

mov ah,4ch
int 21h

end

Result : Enter a Number : 3


After Execution : res[ ] = 03

64
BMS Institute of Technology and Management | Dept of ECE
Microprocessor Lab Manual 10ECL68

B) TO READ A STRING FROM KEYBOARD

.model small
.data
msg db 'Enter a string:','$'
buff db 80 ;maximum length (passed to the function)
db 0 ;actual length (returned from function)
db 80 dup (?) ;area for storing input string(data returned
;from the function)

.code
mov ax,@data
mov ds,ax

;display message on monitor

mov ah,09h
mov dx,offset msg
int 21h

;read from the keyboard


mov ah,0ah
mov dx,offset buff
int 21h

mov ah,4ch
int 21h

end

Result : Enter a String : <any string>


After Execution : buff[ ] = <ascii values of same string>

65
BMS Institute of Technology and Management | Dept of ECE
Microprocessor Lab Manual 10ECL68

C) TO DISPLAY A CHARACTR ON THE CONSOLE

.model small
.data
char db A

.code
mov ax,@data
mov ds,ax

mov dl,char
mov ah,02h ; call the dos interrupt to display result on the screen.
int 21h

mov ah,4ch
int 21h

end

Result : On the Dos prompt A is Displayed

66
BMS Institute of Technology and Management | Dept of ECE
Microprocessor Lab Manual 10ECL68

D)TO DISPLAY A STRING ON CONSOLE

.model small
.data
msg db welcome to microprocessor lab, $

.code
mov ax,@data
mov ds,ax

mov ah,09h ; call the dos interrupt to display the message on the screen
mov dx,offset msg
int 21h

mov ah,4ch
int 21h

end

Result : On the Dos prompt Welcome to microprocessor lab is Displayed

Exercise:
1.WAP to accept two numbers from the keyboard, add them and display the same.
2. WAP to display the result of multiplication on the console.
3. WAP to input BMS institute of technology from the keyboard and display the
same on the console.

67
BMS Institute of Technology and Management | Dept of ECE
Microprocessor Lab Manual 10ECL68

INTERFACING PROGRAMS

68
BMS Institute of Technology and Management | Dept of ECE
Microprocessor Lab Manual 10ECL68

1. STEPPER MOTOR INTERFACE

Adresses for ports


PORT A-0a800H
PORT B-0a801H
PORT C-0a802H
CWR-0a803H
.model small
.data
pa equ 0a800h
pb equ 0a801h
cwr equ 0a803h
.code
mov ax,@data
mov ds,ax
mov dx,cwr
mov al,80h ; CONTROL WORD IS 80H-PORT A IS OUTPUT
out dx,al
mov cx,64h ; no of steps for rotation
mov al,88h
mov dx,pa
back:out dx,al ; energize one winding at a time
ror al,01h
call delay
loop back
mov ah,4ch
int 21h
delay proc near
push cx
push bx
mov cx,01fffh
l1:mov bx,01fffh ;delay program-multiple delays
l2:dec bx
jnz l2
loop l1
pop bx
pop cx
ret
delay endp
end

69
BMS Institute of Technology and Management | Dept of ECE
Microprocessor Lab Manual 10ECL68

70
BMS Institute of Technology and Management | Dept of ECE
Microprocessor Lab Manual 10ECL68

2. LOGIC CONTROLLER INTERFACE.

(A) COMPLEMENTING THE GIVEN NUMBER

Adresses for ports


PORT A-0a800H
PORT B-0a801H
PORT C-0a802H
CWR-0a803H

.model small
.data
pa equ 0a800h
pb equ 0a801h
cwr equ 0a803h
.code
mov ax,@data
mov ds,ax

mov dx,cwr
mov al,82h ; control word is 82h- port b is input and port A is output
out dx,al

mov dx,pb
in al,dx ; accept the data from port B

not al ; complement the input data

mov dx,pa ; Display the result through portA


out dx,al

mov ah,4ch
int 21h

end

RESULT: INPUT:0Fh
OUTPUT:F0h

71
BMS Institute of Technology and Management | Dept of ECE
Microprocessor Lab Manual 10ECL68

(B) MULTIPLYING THE GIVEN NUMBER BY 2

Adresses for ports


PORT A-0a800H
PORT B-0a801H
PORT C-0a802H
CWR-0a803H
.model small
.data
pa equ 0a800h
pb equ 0a801h
cwr equ 0a803h
.code
mov ax,@data
mov ds,ax

mov dx,cwr
mov al,82h ; control word is 82h-port B is input and port A is output
out dx,al

mov dx,pb
in al,dx ; accept the data from port B

and al,07h ; accept only the 3 LSBS


rol al,01h ; multiply by 2

mov dx,pa ; Display the result through portA


out dx,al

mov ah,4ch
int 21h

end

RESULT: INPUT:24H
OUTPUT:48H

72
BMS Institute of Technology and Management | Dept of ECE
Microprocessor Lab Manual 10ECL68

(C) BINARY COUNTER IMPLEMENTATION

Adresses for ports


PORT A-0a800H
PORT B-0a801H
PORT C-0a802H
CWR-0a803H

.model small
.data
pa equ 0a800h
pb equ 0a801h
cwr equ 0a803h
.code
mov ax,@data
mov ds,ax
mov dx,cwr
mov al,80h ; control word is 80h-port B is input and port A is output
out dx,al

mov al,00h
l:mov dx,pa ; initialize al to 00 and display through port A
out dx,al

inc al ; increment the contents

mov cx,0ffffh ; delay pgm


l1:mov bx,07fffh
l2:dec bx
jnz l2
loop l1

push ax ; check for a key pressed


mov al,00h
mov dl,0ffh
mov ah,06h
int 21h

cmp al,00h ; if key is pressed stop counting else repeat the steps
jnz last
pop ax
jmp l

last:mov ah,4ch
int 21h

end

RESULT: COUNTS FROM TO 00H TO FFH


73
BMS Institute of Technology and Management | Dept of ECE
Microprocessor Lab Manual 10ECL68

(D) RING COUNTER IMPLEMENTATION


Adresses for ports
PORT A-0a800H
PORT B-0a801H
PORT C-0a802H
CWR-0a803H
.model small
.data
pa equ 0a800h
pb equ 0a801h
cwr equ 0a803h
.code
mov ax,@data
mov ds,ax

mov dx,cwr
mov al,80h ; control word is 80h-port B is input and port A is output
out dx,al

mov al,01h ; initialize the data such that 1 bit is high


l:mov dx,pa ; display the contents
out dx,al

rol al ,01h ; shift the bit right or left


call delay

push ax ; check for a key pressed


mov al,00h
mov dl,0ffh
mov ah,06h
int 21h

cmp al,00h
jnz last
pop ax
jmp l
last:mov ah,4ch
int 21h

delay proc near

mov cx,0ffffh ; delay pgm


l1:mov bx,07fffh
l2:dec bx
jnz l2
loop l1
ret
delay endp
end
74
BMS Institute of Technology and Management | Dept of ECE
Microprocessor Lab Manual 10ECL68

75
BMS Institute of Technology and Management | Dept of ECE
Microprocessor Lab Manual 10ECL68

3.KEYBOARD INTERFACE

.model small
.data
disp db '0123456789.+-*/%ACK=MVNP'
msg db 10,13,"key pressesed is:"
codes db ?
db 10,13,"row no is:"
row db ?
db 10,13,"column no is:"
column db ?,'$'

pa equ 0a800h
pc equ 0a802h
cwr equ 0a803h

.code
mov ax,@data
mov ds,ax

mov dx,cwr
mov al,90h ; CW=90h=>pb and pc are o/p ports
out dx,al

bk:mov al,80h
mov cl,01h ; initialize row to 01h
mov ch,01h ; initialize the column to 01h
mov bl,03h ; count is initialized to 03h
lea si,disp ; initialize the look up table
nxt:rol al,01h
mov ah,al
mov dx,pc ; send to row 0 through port C
out dx,al
mov bh,08h
mov dx,pa ; read the status of the columns through port A
in al,dx
cmp al,00 ; check if any column is energised
jz down ; if no go to down
nxt2:ror al,01h ; check every bit of the contents from port A to check the
;column energised
jc display ; if carry is set column is energized go to display
inc ch ; else increment the column count
inc si ; increment the counter
dec bh
jnz nxt2 ; repeat for all 8 columns
down:mov al,ah
inc cl ; repeat the process to next row,increment the row number
add si,08h ; make si point to next row
dec bl
76
BMS Institute of Technology and Management | Dept of ECE
Microprocessor Lab Manual 10ECL68

jnz nxt
jmp exit

display:call delay
mov dl,[si] ; put the character pointed by si into dl
mov codes,dl ; and pit the character into memory
add cx,3030h ; convert the row and column no. to ascii for display
mov row,cl
mov column,ch
lea dx,msg
mov ah,09h
int 21h

exit:mov al,00 ; the program continues to display until the key is pressed
mov ah,06
mov dl,0ffh
int 21h
cmp al,00
jz bk
mov ah,4ch
int 21h

delay proc near


push dx
push ax
mov dx,0fffh
lp1:mov bx,0fffh ; delay program
lp2:dec bx
jnz lp2
dec dx
jnz lp1
pop ax
pop dx
ret
delay endp
end

77
BMS Institute of Technology and Management | Dept of ECE
Microprocessor Lab Manual 10ECL68

78
BMS Institute of Technology and Management | Dept of ECE
Microprocessor Lab Manual 10ECL68

4.DISPLAY INTERFACE

Adresses for ports


PORT A-0a800H
PORT B-0a801H
PORT C-0a802H
CWR-0a803H

.model small
.data
mydata db 0A1h,0A7h,83h,0A0h,8Bh,90h,8Eh,84h
pb equ 0a801h
pc equ 0a802h
cwr equ 0a803h
.code
mov ax,@data
mov ds,ax

mov dx,cwr
mov al,80h ;CW=80h=>pb and pc are o/p ports
out dx,al

strt:lea si,mydata ; si points to the character to be displayed

mov bh,02h ; no of words to be displayed

L2:mov bl,04h ; no of characters per word

L1:mov cx,08h ; no of bits per character

mov al,[si] ; take the 1st char

L:mov dx,pb ; send the data bit by bit into the 32 bit shift regr thro'pb0
; starting from MSB
rol al,01h
out dx,al
push ax

mov al,0ffh ; give clk i/p through pc


mov dx,pc
out dx,al
mov al,00h
out dx,al

pop ax

loop L ; repeat the process for all 8 bits

79
BMS Institute of Technology and Management | Dept of ECE
Microprocessor Lab Manual 10ECL68

inc si ;next char


dec bl
jnz L1

call delay

dec bh ; repeat the steps for the nxt word


jnz L2

mov al,00h
mov dl,0ffh
mov ah,06h
int 21h

jz strt

mov ah,4ch
int 21h

delay proc near


push cx
push bx

mov cx,0ffffh
lp1:mov bx,07fffh ; delay program
lp2:dec bx
jnz lp2
loop lp1
pop bx
pop cx
ret
delay endp

end

RESULT: a b c d
efgh

80
BMS Institute of Technology and Management | Dept of ECE
Microprocessor Lab Manual 10ECL68

81
BMS Institute of Technology and Management | Dept of ECE
Microprocessor Lab Manual 10ECL68

OPEN ENDED EXPERIMENTS (SOFTWARE PART)

1. Write an ALP to move a 5, 8 bit data from memory location


8000H to 9000H

2. Write an ALP to perform ASCII subtraction.

3. Write an ALP to add 8, 8 bit data.

4. Write an ALP to read a character from the keyboard and echo it.

5. Write an ALP to display a character / string at the center of the


console.

OPEN ENDED EXPERIMENTS (HARDWARE PART)

6. Write an ALP to control the speed of a Stepper motor using


keyboard.

7. Write an ALP to perform Elevator operation using 8086


microprocessor.

8. Write an ALP to control the traffic signal using 8086


Microprocessor.

9. Write an 8086 ALP to design 8-bit Hexadecimal counter using 7


segment display interface.

82
BMS Institute of Technology and Management | Dept of ECE
Microprocessor Lab Manual 10ECL68

APPENDIX A
VIVA QUESTIONS
1. Give the highest single digit for each of the number systems: decimal, binary, and hex.
2. Which of the following cannot be a number in base-2? Give the reason.
(a) 11001 (b) 113 (c) 10001
3. What is the highest 8-bit number? (a) In binary: (b) In hex:
4. What is the highest 16-bit number? (a) In binary: (b) In hex:
5. Convert binary 100000 to decimal and hex. (a) Decimal: (b) Hex:
6. Convert hex number BAAD to binary and decimal. (a) Binary: (b) Decimal:
7. Indicate the size (8- or 16-bit) of each of the following registers.
PC = AL= BX=
8. Who generates each of the following files and what is the use of each.
.asm .obj .exe
9. Upon reset, what is the value in the SP register?
10. Upon pushing data onto the stack, the SP register is _____________ (decremented,
incremented).
11. Upon popping data from the stack, the SP register is ___________ (decremented,
incremented).
12. What is an addressing mode?
13. Name the different addressing modes of 8051.
14. What is immediate addressing mode?
15. Give examples of immediate addressing mode.
16. What is register-addressing mode? Give examples.
17. What is direct addressing mode? Give examples.
18. Is PC available in low byte & high byte format?
19. What is an instruction?
20. How is the basic instruction divided into?
21. Which area of memory can be accessed using direct addressing mode?
22. Distinguish between direct & immediate addressing mode.
23. The major use of direct addressing mode is in _____
24. Which addressing mode is allowed for pushing on to the stack?
25. Is the instruction PUSH A valid?
26. What is indirect addressing mode? Give examples.
27. Which registers are used in indirect addressing mode?
28. Distinguish between indirect & register addressing mode.
29. What is indexed addressing mode? Give examples.
30. Why is indexed addressing mode widely used?
31. Which registers are used in indexed addressing mode?
32. What is the major difference between code space and data space?
33. List the steps involved in instruction execution.
34. Name the register involved in all the arithmetic operations.
35. Explain DA A instruction.
36. What is packed BCD?
37. Where and how will the result of multiplication &division be stored?
38. List all the flags affected by the arithmetic operations.
39. Convert the following numbers into their 2's complement using instructions
(a) 84 h (b) 98 h (c)3A h (d)A9 h
83
BMS Institute of Technology and Management | Dept of ECE
Microprocessor Lab Manual 10ECL68

40. List the various logical operators.


41. Explain compare instruction.
42. Explain XLAT instruction.
43. Differentiate ROTATE & SHIFT instruction.
44.Give the application of rotate instruction.
45.Write effect of flags in compare instruction?
46. What is the difference between subtract & compare operation?
47. What actually the jump and call instruction does?
48. What is unconditional jump? Give example.
49. What is the difference between RET & IRET?
50. Explain the action of 8086 when NMI & INTR pins are activated?
51. Give an example to generate the effective address?
52. Is LEA BX,[SI] same as MOV BX,SI?
53. Explain NOT &NEG instructions with examples?
54. Explain with examples the exchange instructions?
55. Give the difference between AAA&DAA?
56. Why AAS is used?
57. Give the difference between mul &imul?
58. Give the difference between div &idiv?
59. Give an overview of TEST instruction? How is it different from AND instruction?
60.When is the auxillary carry flag set?
61. Why WAIT instruction is necessary?
62. Why LOCK instruction is necessary?
63. Explain HALT & ESCAPE instruction?
64. Give the differences for the following
a. MOVS
b. STOS
c. LODS
d. CMPS

65. What is the use of REP prefix in STOS?


66. Give the difference for REPE & REPNE?
67.Which are2 types of jump?
68. When CALL instruction is required?
69. Why RETURN instruction is used?
70. What is the difference between intra and inter segment return instruction?
71. List the various types of interrupt in 8086?
72. Why priority is needed in interrupts?
73. Differentiate between packed and unpacked BCD?
74. How many bits is the data and address bus of 8086?
75. Name the different types of segment register?
76. Name the different types of data register?
77. What is the use of Wbit, Dbit, Sbit?
78. Define procedure?
79. Give the general format of an instruction?
80. Differentiate between PUBLIC & COMMON with example?
81. Define modular programming?
82. Give the difference between programmed input/output and interrupt input/output?
83. The stack memory is addressed by a combination of the _______ segment
plus ______ offset?
84
BMS Institute of Technology and Management | Dept of ECE
Microprocessor Lab Manual 10ECL68

84. In the base pointer(BP) address memory , the _______ segment contains the data?
85. The MOV instruction is placed in what field of a statement?
86. What is wrong with the mov ds,ss instruction?
87. What is near and far jump?
88. Which registers are placed on the stack by the PUSHA instruction? In which order?
89. How many bytes are stored on the stack by push instruction?
90. What does the INT 21H accomplish if AH contains 4ch?
91. Which segment register may not be popped from stack?
92. Which instruction set and clear the direction flag?
93. Describe the purpose of EQU directive?
94. which is more efficient? A MOV with an offset or an LEA instruction?
95. Choose an instruction that adds a 1 to the contents of SP register.
96. Is it possible to add CX to DS with add instruction?
97. When two 8- bit no s are multiplied where is the product found?
98. When 16 bit numbers are divided in which register is the quotient found?
99. Which type of jump is used when jumping to any location within the current code
segment?
100. List the 5 flag bits tested by conditional jump instruction?

*****

85
BMS Institute of Technology and Management | Dept of ECE

You might also like