Documente Academic
Documente Profesional
Documente Cultură
1 D/F
MICROPROCESSOR LAB
B.E - IV Semester
Lab Manual 2016-17
Name : ____________________________________
USN : ____________________________________
MICROPROCESSOR LAB
Version 1.0
February 2017
Approved by:
Dr. Suresh D S
Professor & Head,
Dept. of ECE
SYLLABUS
MICROPROCESSOR LABORATORY
SEMESTER – IV (EC/TC)
Laboratory Code 15ECL47 IA Marks 20M
Number of Lecture 01 Hr Tutorial (Instructions) + Exam Marks 80M
Hours/Week 02 Hrs Laboratory
Exam Hours 03Hrs
Bloom’s Taxonomy
Laboratory Experiments:
Level
1. Programs involving:
Data transfer instructions like:
i) Byte and word data transfer in different addressing Modes L2, L3, L4
ii) Block move (with and without overlap)
iii)Block interchange
2. Programs involving:
Arithmetic & logical operations like:
i) Addition and Subtraction of multi precision nos.
ii) Multiplication and Division of signed and unsigned L1, L2, L3
Hexadecimal nos.
iii) ASCII adjustment instructions
iv) Code conversions
3. Programs involving:
Bit manipulation instructions like checking:
i) Whether given data is positive or negative
ii) Whether given data is odd or even L4, L5
iii) Logical 1‟s and 0‟s in a given data
iv) 2 out 5 code
v) Bit wise and nibble wise palindrome
4. Programs involving:
Branch/ Loop instructions like
i) Arrays: addition/subtraction of N nos., Finding largest and L4, L5
smallest nos., Ascending and descending order
ii) Two application programs using Procedures and Macros
i
5. Programs involving
String manipulation like string transfer, string reversing, L2, L3, L4
7. Interfacing Experiments:
Experiments on interfacing 8086 with the following
interfacing modules through DIO (Digital Input/output - PCI
bus compatible card / 8086 Trainer )
1. Matrix keyboard interfacing
2. Seven segment display interface L3, L4, L5
3. Logical controller interface
4. Stepper motor interface
5. Analog to Digital Converter Interface (8 bit)
6. Light dependent resistor ( LDR ), Relay and Buzzer
Interface to make light operated switches
ii
COURSE OBJECTIVE AND OUTCOMES
calls.
Course outcomes: On the completion of this laboratory course, the students will be
able to:
Program a microprocessor to perform arithmetic, logical and data transfer
applications.
iii
Channabasaveshwara Institute of Technology
(An ISO 9001:2008 certified Institution)
NH 26 (B.H. Road), Gubbi, Tumkur – 572 216. Karnataka
---------------------------------------------------------------------------------------------
VISION
MISSION
Quality Policy
---------------------------------------------------------------------------------------------
Department Vision
Department Mission
o To orient the student and faculty community towards the higher education
and research in electronics and other related areas.
Channabasaveshwara Institute of Technology
(An ISO 9001:2008 certified Institution)
NH 26 (B.H. Road), Gubbi, Tumkur – 572 216. Karnataka
---------------------------------------------------------------------------------------------
Department of Electronics & Communication Engineering
------------------------------------------------------------------------------------------------------------------------------------------
Program Educational Objectives (PEOs)
• Acquire and follow best professional and ethical practices in Industry and
Society.
• Communicate effectively and have the ability to work in team and to lead the
team.
• Conduct test and validate the electronic systems to meet desired needs
considering environmental, social, ethical, economical, health and safety issues.
• Use advanced tools for designing and analysing the performance of electronic
and communication systems
• Develop Algorithms, low cost Embedded System based Prototypes to solve real
time issues.
INTRODUCTION
Object module PROG.OBJ can be linked to other object modules with LINK
program. It produces a run module in file PROG.EXE and a map file called
PROG.MAP as outputs. Map file PROG.MAP is supplied as support for the
debugging operation by providing additional information such as where the
program will be located, when loaded into the microcomputers memory.
MASM COMMANDS:
C :/> cd foldername
C:/foldername>edit filename.asm
Structure of Program:
.model small/tiny/medium/large
.data
; Initialization of Data which is used in program.
; Variable declaration goes here.
.code
; Initialization of data segment,
; Program logic goes here.
end
After this command is executed, if there are no syntax errors, the assembler
will generate an object module.
C:/foldername>debug filename.exe
After generating .EXE file by the assembler, it’s time to check the output.
For this the above command is executed. The execution of the program can
be done in different ways as shown below:
__ t ; Stepwise execution.
.model small
.stack 20
.data
src db 31h,32h,33h,34h,35h,36h,37h,38h
dst db 41h,42h,43h,44h,45h,46h,47h,48h
count db 08h
.code
mov ax,@data ; Initialization of
mov ds, ax ;data segment
mov es, ax ;extra segment
mov cx, count ;Initialize cx reg with count
mov bx, 0000h
repeat: mov al,src[bx] ; move the contents at location 0 to al
xchg al,dst[bx] ; exchange the contents of al with dst
mov src[bx], al ; copy the contents of al to src
inc bx ; Increment bx by 1
loop repeat ; go to the label repeat if cx != 0
int 3 ; Terminate the program
align 16
end
.code
mov ax,@data
mov ds, ax ; initializes Data Segment
mov cx, len ; sets counter for 4-bit byte addition
lea si, num1 ; points SI to 1st multibyte no num1
lea di, num2 ; points DI to 2nd multibyte no num2
lea bx, res ; points BX to the result memory location
clc ; clears carry flag CF
back :mov al,[si]
sbb al, [di] ;adds two multibyte no’s with carry
mov [bx], al
inc si
inc di
inc bx
loop back ; go to label back if cx != 0
jnc zero ; checks for CF = 0
inc cl
zero: mov [bx], cl ; stores carry
int 3 ; Terminate the program
align 16
end
.model small
.data
num1 dw 0abcdh
num2 dw 0bbbbh
res dw 5 dup(0)
.code
mov ax,@data ; initializes DS
mov ds, ax
mov ax, num1 ; copy ax with first number
mul num2 ; multiply ax with num2
mov res, ax ; store the result in ax and dx
mov res+2, dx
int 3 ; Terminate the program
align 16
end
.model small
.code
start: mov ax,@data
mov ds, ax ; Initialization of data segment
mov ah,00h
mov al,’5’ ;Get ASCII value of 5
add al,’7’ ;add al with ascii value of 7
aaa ;Ascii adjustment
add ax,3030h
int 3 ; Terminate the program
end start
.model small
.code
start: mov ax,@data
mov ds, ax ; Initialization of data segment
mov al,’9’ ;Get ASCII value of 9
mov ah,’5’ ;Get ASCII value of 5
sub ax,3030h
aam ; Ascii adjustment
add ax,3030h
int 3 ; Terminate the program
end start
.model small
.data
bcd dw 1234h
bin dw 0
.code
mov ax,@data ; initializes DS
mov ds, ax
mov es, ax
mov bx, 0001h
call bcd2bin
mov bx, 000ah
call bcd2bin
mov bx, 0064h
call bcd2bin
mov bx,03e8h
call bcd2bin
int 3 ; Terminate the program
mov res,'Y'
mov res+1,'E'
mov res+2,'S'
jmp ovr
no: mov res,'N'
mov res+1,'O'
ovr: int 3 ; Terminate the program
end
.model small
.data
num db 84h
msg1 db 0ah,0dh,"it is a palindrome$"
msg2 db 0ah,0dh,"it is not a palindrome$"
.code
mov ax,@data ; Initialize data segment
mov ds,ax
mov al, num ; Move number to ax
mov cl, 04 ; Move 04 to cl
mov bl, al ; Move ax to bx
clc ; Clear carry
up: ror bl,01 ; Rotate right bl once, through carry
dec cl ; Decrement cl
jnz up ; Repeat the loop if cl!=0,
cmp al,bl ; if cl=0, compare bh with bl
jz pali ; if bh=bl, jump to label pali
mov ah, 09 ;Display it as a not palindrome.
lea dx, msg2
int 21h
jmp stop ;Jump to label stop
pali: mov ah,09h ;Display it is a palindrome.
lea dx, msg1
int 21h
stop: int 3 ;Terminate the program
end
.model small
.data
arr1 db 5h, 89h, 3h, 56h, 1h
len1 equ $-arr1
arr2 db 29h, 12h, 45h, 89h, 34h
len2 equ $-arr2
.code
start: mov ax, @data
mov ds, ax
; Ascending Sort
mov ch, len1-1 ;no of itterations
agn1: mov cl, ch ;no of comparisions
mov si, offset arr1
rept1: mov al, [si]
inc si
cmp al, [si]
jbe next1
xchg al, [si]
mov [si-1], al
next1: dec cl
jnz rept1
dec ch
jnz agn1
; Descending Sort
mov ch, len2-1 ; no of itterations
agn2: mov cl, ch ; no of comparisions
mov si, offset arr2
rept2: mov al, [si]
inc si
cmp al, [si]
jae next2
xchg al, [si]
mov [si-1], al
next2: dec cl
jnz rept2
dec ch
jnz agn2
int 3
end start
5. STRING MANIPULATION
a) An alp to Program to move a string from source to destination
.model small
.stack 50
.data
src db 'believe in yourself'
n equ ($-src)
space db 5 dup( )
dst db n dup(0)
.code
start: mov ax,@data
mov ds, ax
mov es, ax
mov cx,n
lea si,src
lea di,dst
rep Movsb
int 3; Terminate the program
align 16
end start
7. INTERFACING EXPERIMENTS
Circuit diagram of interfacing devices for 8x3 Matrix keypad:
.model small
.stack 100
.data
pa equ 0d800h
pb equ 0d801h
pc equ 0d802h
ctrl equ 0d803h
ASCIICODE db "0123456789.+-*/%ack=MRmn"
str db 13,10,"press any key on the matrix keyboard$"
str1 db 13,10,"Press y to repeat and any key to exit $"
msg db 13, 10,"the code of the key pressed is :"
key db ?
msg1 db 13,10,"the row is "
row db ?
msg2 db 13,10,"the column is "
col db ?,13,10,’$’
.code
disp macro x
mov dx, offset x
mov ah, 09
int 21h
endm
start: mov ax,@data
mov ds,ax
mov al,90h
mov dx,ctrl
out dx,al
again1: disp str
mov si,0h
again: call scan
mov al,bh ; Row number
add al,31h
mov row,al
mov al,ah ; Column number
add al,31h
mov col,al
cmp si,00
je again
mov cl,03
rol bh,cl
mov cl,bh
mov al,ah
lea bx,ASCIICODE
add bl,cl
xlat
mov key,al
disp msg
disp str1
mov ah, 01
int 21h
cmp al,'y'
je again1
int 3
scan proc
mov cx,03
mov bh,0
mov al,80h
nxtrow: rol al,1
mov bl,al
mov dx,pc
out dx,al
mov dx,pa
in al,dx
cmp al,0
jne keyid
mov al,bl
inc bh
loop nxtrow
ret
keyid: mov si,1
mov cx,8
mov ah,0
agn: ror al,1
jc skip
inc ah
loop agn
skip: ret
scan endp
end start
.model small
.stack 100
.data
pa equ 0d800h
pb equ 0d801h
pc equ 0d802h
ctrl equ 0d803h
str1 db 8eh, 0f9h, 88h, 86h
str2 db 89h, 86h, 0c7h, 8ch
.code
mov ax, @data
mov ds, ax
mov al, 80h
mov dx, ctrl
out dx, al
display proc
mov si, 03h
clock proc
mov dx, pc
mov al, 01h
out dx, al
mov al, 0
out dx, al
mov dx, pb
ret
clock endp
delay proc
push cx
push bx
mov cx, 0ffffh
d2: mov bx, 8fffh
d1: dec bx
jnz d1
loop d2
pop bx
pop cx
ret
delay endp
end
Circuit diagram :
.model small
.data
pa equ 0d800h
pb equ 0d801h
pc equ 0d802h
ctrl equ 0d803h
.code
start: mov ax, @data ; Initialization of
mov ds, ax ; data segment
test bl,01h
jnz oddp ; If ZF = 1, jump to label oddp
mov al,0ffh ; If ZF = 0, load AL with 0FFh
jmp next ; An unconditional jump to label next.
oddp: mov al,00h ; Load AL with 00h
next: mov dx,pa ; Display 00/FF on port A as input
out dx,al ; contains Odd/Even number of ones.
call delay ; Call delay procedure
mov al, bl ; Load AL with contents of BL
mov dx, pa ; SEnd it to port A
out dx, al
int 3
delay proc ; delay procedure
mov ax,0ffffh ; Just waste the time
up2: mov dx,4fffh ; by executing instructions
up1: dec dx ; which won’t affect the logic
jnz up1 ; of the program.
dec ax
jnz up2
ret
delay endp
end start
The power circuit for one winding of the stepper motor is as shown in figure above. It is
connected to the port A (PA0) of 82C55A. Similar circuits are connected to the remaining
lower bits of port A (PA1, PA2, PA3). One windingg is energized at a time. The coils are turned
ON/OFF one at a time successively.
.model small
.data
pa equ 0d800h
pb equ 0d801h
pc equ 0d802h
ctrl equ 0d803h
nstep db 2
.code
start: mov ax, @data
mov ds, ax
mov al, 80h
mov dx, ctrl
out dx, al
mov bh, nstep
again: mov al, 88h
mov bl, 04
again1:call step
ror al, 1
dec bl
jnz again1
dec bh
jnz again
int 3
step proc
mov dx, pa
out dx, al
mov cx, 0ffffh
d2: mov di, 8fffh
d1: dec di
jnz d1
loop d2
ret
step endp
end start
Note: To rotate stepper motor in anti clockwise direction use rol instruction.
.model small
.stack 5000h
.data
chamsg db 13,10,'channel no:-',00,00,'$'
digmsg db 13,10,'digital value:-',00,00,'$'
cr equ 0d803h
pa equ 0d800h
pb equ 0d801h
pc equ 0d802h
.code
mov ax,8bh ; initialize control register.
mov dx,cr
out dx,al
mov cl,00h
mov al,00h ;initialise
mov dx,pa
out dx,al
mov al,20h ;assert start
or al,cl ;signal to adc
out dx,al
mov al,00h ;start pulse over
out dx,al
mov dx,pc ;wait for end of conversion
wait1: in al,dx
and al,01h
jnz wait1
mov dx,pa
out dx,al
pop ax
push ax ;routine to display
mov ax,@data
mov ds,ax
mov ah,09h
mov dx,offset chamsg ;display the channel number
int 21h
mov bh,ch
call ha
mov ah,02h
mov dl,al
int 21h
mov ah,02h
mov dl,bl
int 21h
mov ax,@data
mov ds,ax
mov ah,09h
mov dx,offset digmsg ;display the digital value
int 21h
pop ax
mov bh,al
call ha
mov ah,02h
mov dl,al
int 21h
mov ah,02h
mov dl,bl
int 21h
jmp exitp
end
.code
again: mov ax,@data ; Initialization df data segment
mov ds,ax
mov ah,06h ; To come out of the execution mode
mov dl,0ffh
int 21h
cmp al,'q"
je stop
mov dx,ctrl ; configure 8255 to mode 0
mov al,82h ; configure port A as output & port B as input by sending
control word to control register
out dx,al
mov dx,pb ; Read data from port B of 82c55A
in al,dx
clc
rcl al,1 ; Rotate left AL by one bit along with carry
jnc down ; Jump to label down if CF=1
mov al,03h
mov dx,pa ; send it to port A
out dx,al
jmp again
down: mov al,00h
mov dx,pa
out dx,al
jmp again
stop: int 3
end
Additional Programs
1. Program to Generate a SINE wave using DAC
.model small
.data
pa equ 0c400h
pb equ 0c401h
pc equ 0c402h
ctrl equ 0c403h
table db 128,132,137,141,146,150,154,159,163,167,171,176,180,184,188
db 192,196,199,203,206,210,213,217,220,223,226,229,231,234,236
db 239,241,243,245,247,248,250,251,252,253,254,255
db 255,254,253,252,251,250,248,247,245,243,241,239,236,234,231
db 229,226,223,220,217,213,210,206,203,199,196,192,188,184,180
db 176,171,167,163,159,154,150,146,141,137,132,128
db 123,119,114,110,105,101,97,93,88,84,80,76,72,68,64,60,56,52,49
db 45,42,39,36,33,30,27,24,22,19,17,15,11,9,7,6,5,4,3,2,1,0
db 0,1,2,3,4,5,6,7,9,11,15,17,19,22,24,27,30,33,36,39,42,45,49,52,56
db 60,64,68,72,76,80,84,88,93,97,101,105,110,114,119,123
.code
start: mov ax,@data
mov ds,ax
dec bx
cmp bx,00
jne up
2. Assume any suitable message of 12 characters length and display it in the rolling fashion
on a 7-segment display Interface for a suitable period of time. Ensure a flashing rate that
makes it easy to read the message.
.model small
.stack 100
.data
pa equ 0d800h
pb equ 0d801h
pc equ 0d802h
ctrl equ 0d803h
str1 db 0c0h,0f9h,0a4h,0b0h,99h,92h,83h,0f8h,80h,98h,0c0h,0f9h
.code
start: Mov dx, @data
Mov ds, dx
display proc
Mov si, 0bh
Dec si
cmp si, -1
Jne up1
ret
display Endp
clock proc
Mov dx, pc
Mov al, 01h
out dx, al
Mov al, 0
out dx, al
Mov dx, pb
ret
clock Endp
delay proc
push cx
push bx
pop bx
pop cx
ret
delay Endp
End start
Viva Questions
1. What is a Microprocessor?
10. Which Segment is used to store Interrupt and subroutine return address register?
12. What is the size of data bus and address bus in 8086?
15. Which Flags can be set or reset by the programmer and also used to control the operation
of the processor?
17. What is the difference between min mode and max mode of 8086?
21. What is the position of the Stack PoInter after the PUSH instruction
22. What is the position of the Stack PoInter after the POP instruction?
Instruction Set:
Unconditional Jump.
JMP Label Transfers control to another part of the program. 4-byte address
may be entered in this form: 1234h: 5678h, first value is a
segment second value is an offset.
JA Label Short Jump if first operand is Above second operand (as set by
CMP instruction). Unsigned.
if CF = 0 then jump
Jump If Below.
JB Label Short Jump if first operand is Below second operand (as set by
Algorithm:
if CF = 1 then jump
Jump If Below Or Equal
JBE Label Short Jump if first operand is Below second operand (as set by
CMP instruction). Unsigned.
Algorithm:
if CF = 1 then jump
Jump If Carry
Algorithm:
if CF = 1 then jump
Jump If Equal.
JE Label Short Jump if first operand is Equal to second operand (as set
by CMP instruction). Signed/Unsigned.
Algorithm:
if ZF = 1 then jump
Jump If Greater
JG Label Short Jump if first operand is Greater then second operand (as
set by CMP instruction). Signed.
Algorithm:
Algorithm:
if SF = OF then jump
Jump If Less than.
JL Label Short Jump if first operand is Less then second operand (as set
by CMP instruction). Signed.
Algorithm:
JLE Label Short Jump if first operand is Less or Equal to second operand
(as set by CMP instruction). Signed.
Algorithm:
JNZ Label Short Jump if Not Zero (not equal). Set by CMP, SUB, ADD,
TEST, AND, OR, XOR instructions.
Algorithm:
if ZF = 0 then jump
Jump If Zero.
JZ Label Short Jump if Zero (equal). Set by CMP, SUB, ADD, TEST,
AND, OR, XOR instructions.
Algorithm:
if ZF = 1 then jump
Load Effective Address.
Algorithm:
LOOP Label
• CX = CX - 1
• if CX <> 0 then
o jump
else
o no jump, continue
Add.
REG, memory
ADD memory, REG Algorithm:
REG, REG
memory, immediate operand1 = operand1 + operand2
REG, immediate
Subtract.
REG, memory
memory, REG Algorithm:
SUB REG, REG
memory, immediate operand1 = operand1 - operand2
REG, immediate
• CF = 1
Decimal adjust After Subtraction.
Corrects the result of subtraction of two packed BCD values.
• CF = 1
Increment.
REG Algorithm:
DIV Memory
when operand is a byte:
AL = AX / operand
AH = remainder (modulus)
when operand is a word:
AX = (DX AX) / operand
DX = remainder (modulus)
Shift Left.
memory, immediate
SHL REG, immediate Shift operand1 Left. The number of shifts is set by operand2.
memory, CL Algorithm:
REG, CL
• Shift all bits left, the bit that goes off is set to CF.
• Zero bit is inserted to the right-most position.
Shift Right.
memory, immediate
SHR REG, immediate Shift operand1 Right. The number of shifts is set by operand2.
memory, CL Algorithm:
REG, CL
• Shift all bits right, the bit that goes off is set to CF.
• Zero bit is inserted to the left-most position.
Rotate Left.
memory, immediate
REG, immediate Rotate operand1 left. The number of rotates is set by operand2.
ROL
memory, CL Algorithm:
REG, CL
Shift all bits left, the bit that goes off is set to CF and
the same bit is inserted to the right-most position.
Rotate Right.
memory, immediate
REG, immediate Rotate operand1 right. The number of rotates is set by
ROR operand2.
memory, CL
REG, CL Algorithm:
Shift all bits right, the bit that goes off is set to CF and
the same bit is inserted to the left-most position.
procedure name Transfers control to procedure, return address is (IP) pushed to
CALL label stack.
REG Algorithm:
PUSH SREG
memory • SP = SP - 2
Algorithm:
AAA No Operands
else
• AF = 0
• CF = 0
in both cases:
cLear the high nibble of AL.
Example:
MOV AX, 15 ; AH = 00, AL = 0Fh
AAA ; AH = 01, AL = 05
ASCII Adjust after Subtraction.
Corrects result in AH and AL after subtraction when working
with BCD values.
Algorithm:
else
• AF = 0
• CF = 0
in both cases:
cLear the high nibble of AL.
Example:
MOV AX, 02FFh ; AH = 02, AL = 0FFh
AAS ; AH = 01, AL = 09
Algorithm:
• AH = AL / 10
AAM No Operands • AL = remainder
Example:
MOV AL, 15 ; AL = 0Fh
AAM ; AH = 01, AL = 05
QUESTION BANK
1. a) Write an ALP to Move data from source to destination without overlap.
b) Write an ALP to scan a 8x3 keypad for key closure and to store the code
of the key pressed in a memory location and display on screen. Also
display row and column numbers of the key pressed.
10.a) Write an ALP to Move a block of data from source to destination with
overlap in either direction.
b) Write an ALP to Interface a stepper motor to rotate in clockwise /anticlock-
wise direction.
12. a) Write an ALP to count logical 1’s and 0’s in a given data.
b) Write an ALP to Interface seven-segment display that displays ‘FIRE’ and
‘HELP’.
14. a) Write an ALP to check whether the given number is 2 out of 5 code or not.
b) Write an ALP Interface a stepper motor to rotate in clockwise/anticlock-
wise direction.
15. a) Write an ALP to Interchange two blocks of data stored in memory location.
b) Write an ALP to interface LDR ,relay and buzzer to make light operated
switch
16. a) Write an ALP to check whether the given 8-bit data is bit wise palindrome
b) Write an ALP to Interface seven-segment display that displays ‘FIRE’ and
‘HELP’.
22. a) Write an ALP to check whether the given 8-bit data is nibble wise
palindrome or not.
b) Write an ALP to Interface a logic controller to check the parity (even/odd)
and to display number of 1’s in the given data.
ENDP - ENDP directive is used along with the name of the procedure
to indicate the end of a procedure to the assembler
Example: SQUARE_NUM PROC ; It start the procedure ;Some steps to
find the square root of a number SQUARE_NUM ENDP ;Hear it is the
End for the procedure
.DATA Directive
• The .DATA directive creates a near data segment.
• This segment contains the frequently used data for your program.
• Data segment can occupy
o up to 64K in MS-DOS
o or up to 512 megabytes under flat model in Windows NT.
.CODE Directive
• The .CODE directive in your program instructs the assembler to
start a code segment.
• The next segment directive closes the previous segment;
the END directive at the end of your program closes remaining
segments.
.STACK Directive
• The stack is the section of memory used for pushing or popping
registers and storing the return address when a subroutine is
called.
• The stack often holds temporary and local variables.
• Use the .STACK directive only when writing a main module in
assembly language.
• The .STACK directive creates a stack segment.
• By default, the assembler allocates 1K of memory for the stack.
This size is sufficient for most small programs.
REFERENCES: