6TH Semester MP Lab Manual 2017 - 3 PDF
6TH Semester MP Lab Manual 2017 - 3 PDF
6TH Semester MP Lab Manual 2017 - 3 PDF
Department Mission
Name:
USN: ..
Batch & Semester: .
Programme:....
1
BMS Institute of Technology and Management | Dept of ECE
Microprocessor Lab Manual 10ECL68
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.
2
BMS Institute of Technology and Management | Dept of ECE
Microprocessor Lab Manual 10ECL68
Programme Outcomes
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.
8. Ethics: Apply ethical principles and commit to professional ethics and responsibilities
and norms of the engineering practice.
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
Course Outcomes
CO4 : Present technical reports of the experiements conducted throughout the course.
Lab In-charges
Lab Insturctor
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
I. Programs involving
II. Experiments on interfacing 8086 with the following interfacing modules through
DIO (Digital Input/Output-PCI bus compatible) card :
7
BMS Institute of Technology and Management | Dept of ECE
Microprocessor Lab Manual 10ECL68
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
9
BMS Institute of Technology and Management | Dept of ECE
Microprocessor Lab Manual 10ECL68
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)
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
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)
11
BMS Institute of Technology and Management | Dept of ECE
Microprocessor Lab Manual 10ECL68
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.
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
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
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
17
BMS Institute of Technology and Management | Dept of ECE
Microprocessor Lab Manual 10ECL68
.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
.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
.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
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
.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
.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
.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
.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
.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
.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
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
.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
.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
.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
.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
.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
.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
.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
.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
.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
.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
.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
.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
.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
.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
.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
.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
.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
.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
.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
47
BMS Institute of Technology and Management | Dept of ECE
Microprocessor Lab Manual 10ECL68
.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
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
49
BMS Institute of Technology and Management | Dept of ECE
Microprocessor Lab Manual 10ECL68
.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
.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
.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
.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
.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
.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
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
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
.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
.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
.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
.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
.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
64
BMS Institute of Technology and Management | Dept of ECE
Microprocessor Lab Manual 10ECL68
.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
mov ah,09h
mov dx,offset msg
int 21h
mov ah,4ch
int 21h
end
65
BMS Institute of Technology and Management | Dept of ECE
Microprocessor Lab Manual 10ECL68
.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
66
BMS Institute of Technology and Management | Dept of ECE
Microprocessor Lab Manual 10ECL68
.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
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
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
.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
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
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
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
.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
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
mov dx,cwr
mov al,80h ; control word is 80h-port B is input and port A is output
out dx,al
cmp al,00h
jnz last
pop ax
jmp l
last:mov ah,4ch
int 21h
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
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
.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
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
pop ax
79
BMS Institute of Technology and Management | Dept of ECE
Microprocessor Lab Manual 10ECL68
call delay
mov al,00h
mov dl,0ffh
mov ah,06h
int 21h
jz strt
mov ah,4ch
int 21h
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
4. Write an ALP to read a character from the keyboard and echo it.
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
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