Académique Documents
Professionnel Documents
Culture Documents
CERTIFICATE
satisfactorily completed the lab exercises prescribed for Microprocessors Lab [CSE 2211]
of Second Year B. Tech. Computer Science and Engineering Degree at MIT, Manipal, in
Date: ……...................................
Signature
Faculty in Charge
CONTENTS
LAB PAGE
TITLE REMARKS
NO. NO.
EVALUATION PLAN ii
5 STRING OPERATIONS 19 – 21
8 DISPLAY INTERFACING 31 – 38
9 KEYBOARD INTERFACING 39 – 42
10 ELEVATOR INTERFACING 43 – 45
Course Outcomes
At the end of this course, students will be able to
Write basic programming model
Write and execute simple 8086 assembly programs.
Apply the instructions of 8086 to solve complex problems and to analyze the
program.
Design and execute interfacing programs.
Evaluation plan
Internal Assessment Marks : 60%
Page i of iv
INSTRUCTIONS TO THE STUDENTS
Pre- Lab Session Instructions
1. Students should carry the Class notes, Lab Manual and the required stationery to
every lab session
2. Be in time and follow the Instructions from Lab Instructors
3. Must Sign in the log register provided
4. Make sure to occupy the allotted seat and answer the attendance
5. Adhere to the rules and maintain the decorum
Page ii of iv
A sample note preparation is given later in the manual as a model for observation.
Page iii of iv
Sample lab observation note preparation
Program:
data segment
a db 07h
b db 05h
c db ?
data ends
code segment
assume cs:code,ds:data
start: mov ax,data
mov ds,ax
mov al,a
mov bl,b
sub al,bl
mov c,al
mov ah,4ch
int 21h
code ends
end start
Sample Output
Page iv of iv
LAB NO: 1
Objectives:
Intel 8086 microprocessor is a 16-bit microprocessor wherein ALU, registers, instructions are designed
to work with 16-bit binary words.
Consists of 16-bit data bus and 20-bit address bus
Data bus allows read/write data from/to memory and ports either 16 bits or 8 bits at a time.
Address bus can address any one of 220 or 1MB memory locations
8086 Internal Architecture
Page 2 of 57
LAB NO: 1
Flag Register
Flip-flop indicates some condition produced because of execution of an instruction or controls
certain operations of EU.
Consists of nine active flags, which can be classified into six conditional flags and three control
flags.
The six conditional flags are CF, PF, ZF, SF, AF and OF and the three control flags are TF, DF
and IF.
Fig 1.3
General Purpose Registers
EU has eight general-purpose registers labelled as AH, AL, BH, BL, CH, CL, DH and DL which
can be used individually for temporary storage of 8-bit data.
These registers can be used together to store 16-bit words and the acceptable register pairs are
AH and AL, BH and BL, CH and CL and DH and DL.
The AH-AL pair is referred to as AX register, BH-BL pair as BX register and DH-DL pair as
DX register.
Pointer and Index Registers
Stack Pointer Register (SP)
Holds the 16-bit offset from the start of stack segment to the memory location where a word
was most recently stored on stack.
Base Pointer Register (BP)
Helps in referencing the parameter variables passed to a subroutine. The address in SS register
is combined with the offset in BP to get the location of the parameter. BP can be combined with
DI and SI as base register for special addressing.
Source Index Register (SI) and Destination Index Register (DI)
16-bit registers used for temporary storage of data. Have special functionality in string
operations.
Page 3 of 57
LAB NO: 1
Ex: ADD
Operands
Contains the data, memory address, port address, or the name of register on which the instruction
is to be performed.
2. ADD
Category : Arithmetic Instruction
Description : Add a number from some source to a number from some destination and put the result in
the specified destination.
Syntax : ADD Destination, Source
3. SUB
Category : Arithmetic Instruction
Description : Subtract a number from some source to a number from some destination and put the
result in the specified destination.
Syntax : SUB Destination, Source
Assembler Directives
Assembler directives are the commands to the assembler that direct the assembly process.
They do not generate any machine code i.e. they do not contribute to the final size of machine code
and they are assembler specific.
Some assembler directives are defined below:
1. SEGMENT AND ENDS DIRECTIVES
Used to identify a group of data items or instructions that we want to put together in a particular
segment.
SEGMENT marks the beginning of logical segment and ENDS denotes the end of logical segment
2. ASSUME
Tell the assembler the name of the logical segment it should use for a specified segment.
3. DB
Used to declare a byte type variable or to store a byte in memory location.
4. DW
Used to define a variable of type word or to reserve storage location of type word in memory.
5. END
Placed after the last statement of a program to tell the assembler that this is the end of the program
module. The assembler will ignore any statement after an END directive.
Page 4 of 57
LAB NO: 1
2. In the MASM command window, type edit filename.asm or edit to open up an Editor window.
Type the assembly language program and select FileSave. If edit is used, select FileSave As
and save the program with .asm extension in the required directory. Then select FileExit.
3. To assemble the source code into an object file, type the command masm filename.asm; and press
Enter.
4. To link the object file with other modules or libraries into an executable program, type the
command link filename.obj; the file will be compiled and errors if any will be displayed.
5. To load the program into memory, type the command td filename and press Enter.
6. To perform line-by-line execution of the program, F7 is used and when each line is being executed,
corresponding changes in the registers and flags can be observed.
7. To view the results, select ViewDump.
Solved Exercise
Write ALP to perform addition of two 8-bit numbers
data segment
a db 02h
.
b db 04h
c db ?
data ends
code segment
assume cs:code,ds:data
start: mov ax,data
mov ds,ax
mov al,a
mov bl,b
add al,bl
mov c,al
mov ah,4ch
int 21h
code ends
end start
Page 5 of 57
LAB NO: 1
Sample Output
Lab Exercises
Additional Exercises
1. Write ALP to perform addition of two 8-bit numbers represented in the following number systems:
a. Binary b. Decimal c. Octal
2. Write ALP to perform the subtraction of an unsigned byte from signed word.
--------------------------------------------------------------------------------------------------------------------------
Page 6 of 57
LAB NO: 2
Objectives:
1. Identify and use the instructions required to perform multiplication and division operations for
signed and unsigned numbers.
2. Perform sign extension of values in Accumulator register to obtain valid results.
2. DIV
Description: divide an unsigned word by a byte or an unsigned double word by a word.
Syntax: DIV source
Source can be a register or memory location
Division of a word by byte.
The word must be in AX register.
After division, AL will contain an 8-bit result (quotient) and AH will have an 8-bit
remainder.
Division of a double word by a word.
The most significant word of double word must be in DX and least significant word in AX.
After division, AX will contain 16-bit result (quotient) and DX will have the 16-bit remainder.
3. IMUL
Performs same operation as MUL instruction but operates only on signed numbers
4. IDIV
Performs same operation as DIV instruction but operates only on signed numbers.
5. CBW
Description: copies the sign bit of a byte in AL to all bits in AH.
Syntax: CBW
6. CWD
Description: copies the sign bit of a word in AX to all bits in DX register.
Page 7 of 57
LAB NO: 2
Syntax: CWD
7. LEA
Solved Exercise
data segment
a dw 0304h
b dw 0101h
c dw ?,?
data ends
code segment
assume cs:code,ds:data
start: mov ax,data
mov ds,ax
mov ax,a
mov bx,b
mul bx
mov c,ax
mov c+2,dx
mov ah,4ch
int 21h
code ends
end start
Sample Output
Lab Exercises
Page 8 of 57
LAB NO: 2
Additional exercises
Page 9 of 57
LAB NO: 3
Objectives:
1. CMP
Category: Arithmetic Subtraction Instruction
Description: compare two specified bytes or two specified words by subtracting the source from
destination and the flags are set to indicate the comparison results. Both source and destination will remain
unchanged.
Syntax: CMP Destination, Source
Destination can be register/memory location
Source can be register/memory location/immediate number
Both destination and source cannot be memory locations in the same instruction.
All the six conditional flags can be affected.
Unconditional JMP
Instruct 8086 to fetch instruction from some new address specified in the instruction without the
occurrence of any condition.
Syntax: JMP label
Conditional JMP
Instruct 8086 to fetch instruction from some new address specified in the instruction with the
occurrence of any condition.
Syntax remains same as that of unconditional jump with different mnemonics according to the
condition.
Page 10 of 57
LAB NO: 3
3. Shift Instructions
Category: Bit Manipulation Instructions
SAL/SHL
Description : Shift operand bits left and put 0 in LSB
Syntax : SAL/SHL Destination, count
Shift operand bits in destination towards left by specified count
Page 11 of 57
LAB NO: 3
Destination can be register/memory location and if the count is greater than 1, it should be
loaded into CL register.
CF--------MSB----------LSB----0
SAR
Description : Shift operand bits right and new MSB= old MSB
Syntax : SAR Destination, Source
Shift operand bits in destination towards right by specified number
Destination can be register/memory location
Source can be immediate number (if it is 1) or Count register CL (if it is >1)
MSB--MSB--------LSB----CF
SHR
Description : Shift operand bits right and put 0 in the MSB
Syntax : SHR Destination, Source
Destination can be register/memory location
Source can be immediate number (if it is 1) or Count register CL (if it is >1)
0MSB--------LSB----CF
4. Rotate Instructions
Category: Bit Manipulation Instructions
ROL
Description : Rotate operand bits in destination towards left by specified number.
Syntax : ROL Destination, Source
Destination can be register/memory location
Source can be immediate number (if it is 1) or Count register CL (if it is >1)
ROR
Description : Rotate operand bits in destination towards right by specified number.
Syntax : ROR Destination, Source
Destination can be register/memory location
Source can be immediate number (if it is 1) or Count register CL (if it is >1)
5. INC
Category : Arithmetic instruction
Description : Adds 1 to a specific register or a memory location
Syntax : INC Destination
Page 12 of 57
LAB NO: 3
6. DEC
Category : Arithmetic instruction
Description : Subtracts1 from a specific register or a memory location
Syntax : DEC Destination
Destination can be a register or a memory location
7. AAA
Category : Arithmetic instruction
Description : Ensures that the result is in correct unpacked BCD format after addition of two
numbers in ASCII.
Syntax : AAA
Works on AL register only
8. AAS
Category : Arithmetic instruction
Description : Ensures that the result is in correct unpacked BCD format after subtraction of two
numbers.
Syntax : AAS
Works on AL register only
9. AAM
Category : Arithmetic instruction
Description : Adjusts the product to two unpacked BCD digits after the multiplication of two
unpacked BCD digits.
Syntax : AAM
Works on AL register only
10. AAD
Category : Arithmetic instruction
Description : Converts two unpacked BCD digits in AH and AL to equivalent binary number in
AL. AAD should be used before division of two unpacked digits in AX by an
unpacked BCD byte.
Syntax : AAD
11. DAA
Category : Arithmetic instruction
Description : Adjusts the result of addition of two packed BCD numbers to be a legal BCD number.
Syntax : DAA
Works on AL register only
12. DAS
Category : Arithmetic instruction
Description : Adjusts the result of subtraction of two packed BCD numbers to be a legal BCD
number.
Syntax : DAS
Page 13 of 57
LAB NO: 3
Solved Exercise
Write ALP to unpack a 2 byte packed BCD number and represent in ASCII format.
data segment
bcd db 18h,15h
asc dw ?,?
count db 02
data ends
code segment
assume cs:code,ds:data
start:
mov ax,data
mov ds,ax
mov cl,4
lea si,bcd
lea di,asc
do:
mov al,[si]
mov ah,00h
rol ax,cl
shr al,cl
add ax,3030h
mov [di],ax
inc si
inc di
inc di
dec count
jnz do
mov ah,4ch
int 21h
code ends
end start
code ends
Page 14 of 57
end start
LAB NO: 3
Sample Output
Lab exercises
Write assembly language programs to do the following:
Additional exercises
Page 15 of 57
LAB NO: 4
Objectives:
1. LOOP
Category : Iteration Control Instruction
Description : Repeats a series of instructions ‘n’ times and the count ‘n’ has to be loaded into CX register.
Syntax : LOOP label
Each time the loop instruction executes, CX is automatically decremented by 1 and if CX≠0, execution
will go back to label given in the instruction.
When CX=0, control goes to next instruction after LOOP instruction.
2. LOOPE/LOOPZ
Category : Iteration Control Instruction
Description : Loop as long as ZF=1 and CX! = 0
Syntax : LOOPE label
3. LOOPNE/LOOPNZ
Category : Iteration Control Instruction
Description : Loop as long as ZF=0 and CX! = 0
Syntax : LOOPNE label
4. XCHG
Category : Data Transfer Instruction
Description : exchange contents of a register or memory location with the contents of another register
or memory location
Syntax : XCHG Destination, Source
Both source and destination cannot be a memory location in one instruction.
Page 16 of 55
LAB NO: 4
Solved exercise:
Write ALP to insert one element into an unsorted list in a given position
data segment
list db 9,4,3,1,7,?
ele db 6
pos db 3
data ends
code segment
assume cs:code,ds:data
start: mov ax, data
mov ds, ax
lea si,list
add si, pos
mov cl,3
mov al, ele
rep1: xchg al,[si]
inc si
dec cl
jnz rep1
code ends
end start
Sample Output
Lab Exercises
Page 17 of 55
LAB NO: 4
Additional Exercises
1. Write an 8086 ALP to perform the following for the list of numbers stored in the memory
a. Count the total number of even and odd numbers in the list
b. Count the total number of elements whose value is greater than 10.
2. Write an ALP to search for an element in an array. The program has to insert the element in the array
there is no match and sort the resultant array.
3. Write an ALP to find the sum of all the elements in the given array
---------------------------------------------------------------------------------------------------------------
Page 18 of 55
LAB NO: 5
STRING OPERATIONS
Objectives:
STRING INSTRUCTIONS
1. MOVS/MOVSB/MOVSW
Description : Copies a byte or a word from a location in the data segment to a location in the extra
segment.
Syntax : MOVS Destination, Source
Offset of the source byte/word in the data segment must be contained in SI register and offset of
the destination byte/word in the extra segment must be in DI register.
After a byte /word move, both SI and DI will be automatically adjusted to point to next source &
destination.
If direction flag DF=0, both SI and DI will be automatically incremented by one or two after a
byte/word move.
If DF=1, both SI and DI will be automatically decremented by one or two after a byte/word move.
2. LODS/LODSB/LODSW
Description : Loads string byte into AL or string word into AX pointed to by SI.
Syntax : LODS source_string
3. STOS/STOSB/STOSW
Description : Copies a byte from AL or a word from AX to a memory location in the extra segment
pointed to by DI
Syntax : STOSB/STOSW
4. CMPS/CMPSB/CMPSW
Description: To compare byte/word in one string with byte/word in another string
Syntax : CMPSB (Compares two strings byte by byte)
SI holds the offset of source string defined in Data segment and DI holds the offset of destination
string defined in Extra segment.
5. SCAS/SCASB/SCASW
Description : Compares a byte in AL or a word in AX with a byte or word pointed to by DI in ES.
Syntax : SCASB (Scans byte by byte)
The String to be scanned must be in extra segment and DI must contain the offset of byte or word
to be compared
Page 19 of 55
LAB NO: 5
6. LOCATION COUNTER
Description: To calculate length of the string. ‘$’ location counter symbol represents the current value of
the location counter (for example please refer the below program)
Solved Exercise
Write ALP to reverse the given string
data segment
str db "manipal#"
len equ $-str-1
str1 db 10 dup(0)
data ends
code segment
assume cs:code,ds:data,es:data
start:
mov ax,data
mov ds,ax
mov es,ax
mov cx,len
lea si,str+len-1
lea di,str1
again:mov al,[si]
mov [di],al
inc di
dec si
jnz again
mov al,[si]
mov [di],al
exit: mov ah,4ch
int 21h
code ends
end start
Sample Output
Page 20 of 55
LAB NO: 5
Lab Exercises
Write 8086 programs to:
1. Search for the occurrence of a character in a string and find its count.
2. Check if the given string is a palindrome or not.
3. Concatenate two strings, which are stored in non-consecutive memory locations.
4. Find the substring in the main string
5. Reverse the case of each character in a given string.
Additional Exercises
Page 21 of 55
LAB NO: 6
DOS INTERRUPTS
Objectives:
INTRODUCTION TO INTERRUPTS
An 8086 interrupt can come from any three sources:
Hardware interrupt: An interrupt caused by a signal applied to either NMI or INTR pin
Software interrupt: Execution of INT instruction
Some error condition produced as a result of execution of an instruction (divide-by-zero)
At the end of each instruction cycle, 8086 checks for interrupt request and if so, it does series of major
actions as shown in the figure 6.1
2. INT 21H/AH=09H
Writes a string pointed by DX, terminated with $ to standard output device.
Expects
AH=09H
DS: DX = segment: offset of string terminated by ‘$’.
Returns
String to the standard output device.
Page 22 of 55
LAB NO: 6
3. INT 21H/AH=0AH
Get a String Input from the keyboard and store in a buffer pointed by DX in DS.
User has to define the buffer as Byte db max_length, actual_ length, space for storing the string
Ex: buffer db 15, 14 dup (0)
Expects
AH=0AH
DS: DX = segment: offset of buffer
Returns: Stores the read string in buffer.
Note: The last byte in the buffer will be for enter key. Hence, the size is always one less than the
maximum size.
4. INT 21H/AH=3CH
Create a new file given an ASCIIZ file specification.
If the specified file already exists, it is truncated to zero length.
Expects
AH=3CH
CX=0 (file attribute)
DS: DX = segment: offset of ASCIIZ file specification
Returns
If no error: CF=clear, AX=file handle
If error : CF=set, AX=error code
5. INT 21H/AH=3DH
Open a specified file in the designated or default directory and a file handle (16-bit token) will be
returned for further access of the file.
Expects
AH=3DH
DS: DX = segment: offset of ASCIIZ file specification
AL= access and file sharing modes
00H=read only
01H=write only
02H=read/write
Returns
If no error : CF=clear, AX=file handle
If error : CF=set, AX=error code
6. INT 21H/AH=3EH
Close a file specified by file handle
Expects
AH=3EH
BX = file handle
Returns
If no error : CF=clear
If error : CF=set, AX=error code
7. INT 21H/AH=3FH
Read a file specified by file handle and stores in designated file buffer and updates file pointer to
point to next record.
Page 23 of 55
LAB NO: 6
Expects
AH=3FH
BX = file handle
CX=no. of bytes to read
DS:DX = segment: offset of buffer space.
Returns
If no error : CF=clear, AX=Actual no. of bytes read
If error : CF=set, AX=error code
If AX=0 : reading from EOF
8. INT 21H/AH=40H
Write the contents of designated buffer to a file specified by file handle and updates file pointer to
point to next record.
Expects
AH=40H
BX = file handle
CX=no. of bytes to write
DS:DX=segment: offset of buffer space.
Returns
If no error : CF=clear, AX=no. of bytes actually written
If error : CF=set, AX=error code
9. INT 21H/AH=42H
Move the file pointer to desired address i.e., sets the file pointer location relative to start of a file,
end of a file or the current file position.
Expects
AH=42H
BX = file handle
CX:DX=contains a 32-bit unsigned long integer that specifies how many bytes to move the
file pointer from the position specified in AL.
AL= 0 for byte offset from start of the file
1 for byte offset from current location
2 for byte offset from end of file
Returns
If no error : CF=clear, DX:AX=new position of file read/write pointer
If error : CF=set, AX=error code
Page 24 of 55
LAB NO: 6
Solved Exercise
Write ALP to read a string from the user and count the number of words in the string. Display the
result on the screen. [If the count is greater than 9 , display the count in decimal. Hint: Divide the
count value by 10 to extract the digits]
data segment
str1 db 'enter string:$'
msg1 db 0dh,0ah,'No. of words are:', 0dh, 0ah, '$'
str11 db 15,?,14 dup(0)
count db 1
data ends
code segment
assume cs:code, ds:data, es:data
start: mov ax,data
mov ds,ax
mov es,ax
mov ah,09h
mov dx,offset str1
int 21h
mov dx,offset str11
mov ah,0ah
int 21h
mov al,' '
mov cl, str11+1
lea si,str11+2
back: cmp [si],al
je space
inc si
dec cl
jnz back
jmp last
space: inc si
dec cl
cmp [si],al
jz space
inc count
jmp back
last: lea dx, msg1
mov ah, 09
int 21h
mov dl, count
add dl, 30h
mov ah, 02
int 21h
mov ah, 4ch Page 25 of 55
int 21h
code ends
end start
LAB NO: 6
Sample Output
Lab Exercises
1. Read a string from the keyboard, toggle all lowercase alphabets, and display it on the screen.
2. Read a multi digit number from the keyboard. Calculate the sum of the digits of that number
and display the sum in decimal form.
3. Create a file and write into it.
4. Read a string from the keyboard, append it to the contents of an existing file and display the
contents of the file on the screen.
Additional Exercises
Write assembly language programs to do the following
1. Read a file and write the contents into another file.
2. Read a string from the keyboard, reverse the string and display it on the screen.
---------------------------------------------------------------------------------------------------------------
Page 26 of 55
LAB NO: 7
Objectives:
In this lab, student will be able to:
Page 27 of 55
LAB NO: 7
Page 28 of 55
LAB NO: 7
Solved Exercise
Write a procedure to convert a BCD number to binary where the operands will be passed using
pointers. Write a program that uses this procedure.
data segment
bcd db 25h
binary db ?
data ends
stack_seg segment stack
dw 100 dup(0)
top_stack label word
stack_seg ends
code segment
assume cs:code, ds:data, ss:stack_seg
start: mov ax, data
mov ds,ax
mov ax,stack_seg
mov ss,ax
mov sp, offset top_stack
mov si, offset bcd
mov di, offset binary
call bcd_bin
mov ah,4ch
int 21h
bcd_bin proc near
push ax
push bx
push cx
mov al, [si]
mov bl, al
and bl,0fh
and al ,0f0h
mov cl, 04
ror al, cl
mov bh,0ah
mul bh
add al,bl
mov [di], al
pop cx
pop bx
pop ax
ret
bcd_bin endp
code ends
end start
Page 29 of 55
LAB NO: 7
Sample Output
Lab Exercises:
1. Write a macro to display the string on the screen. Use this macro to display the file contents in the
console.
2. Write a recursive procedure to calculate factorial of a number.
3. Write a procedure named multiply that computes the product of two unsigned 16-bit operands. The
operands will be passed through the stack. The procedure should return the result in AX and DX.
Write a program that uses the multiply procedure.
4. Write a procedure to generate Fibonacci series for a given value of n. Write a program to use this
procedure.
5. Define two macros to add and subtract two 8-bit numbers. Pass the input values as parameters to
the Macro. With the help of macros, evaluate the expression x+y-z.
Additional exercises:
1. Write a procedure to sort elements in an array. Use this procedure to sort an array input from the user.
2. Write a procedure to find the cube of a single digit number. Use this procedure to find the sum of the
Cubes of the digits of a multi-digit number.
------------------------------------------------------------------------------------------------------------------
Page 30 of 55
LAB NO: 8
DISPLAY INTERFACING
Objectives:
In this lab, student will be able to:
INTRODUCTION TO 8255A:
What is 8255A?
It is a Programmable Peripheral Interface used with 8086 microprocessors to control peripheral I/O devices.
It contains three 8-bit ports which can be programmed. Ports if programmed, can operate in different modes
and hence can do different types of parallel data transfer.
Page 31 of 55
LAB NO: 8
RESET input--- When the system is reset, all port lines were initialized as input lines to prevent
circuitry damage
Mode 0:
A port must be initialized in this mode if we want to use it for simple input/output operations.
If ports A and B are initialized in Mode 0, then port C can be used as 8-bit port or two 4-bit ports
2 halves of port C are independent.
For example, let us say that the thermostat is connected to port A and we want to read
temperature 24/7. In this case, port A will be initialized in mode 0 and will be used as 8-bit input
port.
Page 32 of 55
LAB NO: 8
Page 33 of 55
LAB NO: 8
Example code snippet to send 10001110 (binary) mode definition control word to control register at
address e0c3h is shown below
Page 34 of 55
LAB NO: 8
Port lines PC2, PC1, PC0 are connected to the seven segment displays in such a manner that they can be
used to turn on the desired seven segment display. Table 8.3 lists the possible port line combinations and
seven segment display enabled
Table 8.3 Connection of 8255A Port C Lines to Individual Units of Seven Segment Display[2]
In short, Port C lines are used to select or turn ON the desired seven segment display and Port A lines are
used to display something on the turned ON seven segment display. Normally for a 6-digit display, this is
done for about 2msec. For the next 2msec, the data for the next seven segment is sent to Port A and the
corresponding code to Port C. This is repeated till all the seven segment displays on the display interface
are serviced, at which time the whole sequence is again restarted.
Page 35 of 55
LAB NO: 8
How to generate binary pattern for a character to be displayed on a seven segment display?
Not all the characters can be displayed on seven segment display. For instance, characters like M, V, W, X
and so on cannot be displayed. This is a major drawback of seven segment display. Yet, we will see how
to generate binary pattern for some of the displayable characters.
Referring Fig 8.6, first write the segment labels in the descending order as shown below
Second, for the character, whichever segments need to be turned on, go to those segment labels in Fig 8.6
and put binary value ‘1’. For example, if ‘S’ is the character to be displayed on seven segment display, then
binary value ‘1’ will be put in segment labels ‘A’, ‘F’, ‘G’, ‘C’, ‘D’ and hence the binary pattern would be
01101101b or 6Dh.Table 8.4 tells seven segment code for some of the displayable characters.
Connections details:
Connect the bus from 8255A to the display interface.
Page 36 of 55
LAB NO: 8
data segment
base_address equ 0a400h
control equ base_address + 03h
porta equ base_address+00h
portb equ base_address+01h
portc equ base_address+02h
fire DB 0,0,79H,50H,06H,71H
data ends
The above data segment definition format can be used to write data segment definition for any interfacing
experiment. It is advisable to use EQU directive to equate the values to variables. An 8255A will have a
base address. In Fig 8.7, it is a400H and is equated to variable base_address. The ports of 8255A can be
selectively accessed as shown in Table 8.1.
It is to be noted that in the above definition porta, portb, portc are used to refer to ports Port A, Port B, Port
C of 8255A respectively. In the data segment definition, the absolute addresses of ports are to be written.
Absolute address is the sum of base address and offset. For example, base_address+00h is the absolute
address of Port A of 8255A and hence equated to variable porta. This is applicable for other ports and
control register as well.
mov dx,portc
mov al,06h
out dx,al
Page 37 of 55
LAB NO: 8
Lab Exercises
With the brief introduction of display interface and knowledge on 8255A,
Write 8086 ALP for the following:
1. Display a 4-digit BCD number on the display interface.
2. Display messages FIRE and HELP alternately with flickering effects on the display
interface for a given duration. Ensure a flashing rate that makes both the messages readable.
Additional Exercises
1. Convert a 16-bit binary number (assumed an unsigned integer) to BCD and display it on the
display interface.
2. Define a string of six characters in the memory. Display the string and its reversed string
alternately with flickering effects on the display interface for a given duration.
-------------------------------------------------------------------------------------------------------------
Page 38 of 55
LAB NO: 9
KEYBOARD INTERFACING
Objectives:
In this lab, student will be able to:
In Fig 9.1,the keyboard consists of 24 keys having calculator type keycaps. It consists of numerals 0 to 9,
the special characters +, -, *, ÷, %, C, CE, and five blank keys. The keys are organized as three rows of
eight keys each in a sense matrix of three rows and eight columns. Hence matrix keyboard.
The three rows of matrix keyboard are connected to port lines PC0, PC1 and PC2 and the eight columns
are connected to port lines PA0 to PA7 of 8255. The key code corresponding to each key may be assigned
as shown in the following Table 9.1
Table 9.1 Key codes corresponding to each key in the keyboard interface[2]
Key Code Key Code
0 00 * 0C
1 01 ÷ 0D
2 02 = 0E
3 03 % 0F
4 04 C 10
5 05 CE 11
6 06 BLANK 12
Page 39 of 55
LAB NO: 9
7 07 BLANK 13
8 08 BLANK 14
9 09 BLANK 15
+ 0A BLANK 16
- 0B BLANK 17
So PC0, PC1 and PC2 can be used to select a row. Refer Table 9.2 for port C lines combinations and row
selections.
Port A lines act as data lines since they can be used to read the selected row.
Connection Details
Connect the master/slave bus cable to the keyboard
Page 40 of 55
LAB NO: 9
l:
mov ah,0
mov cx,3
mov bl,1
l1:
mov al,bl
mov dx,portc
out dx,al
mov dx,porta
in al,dx
cmp al,0
jnz l2
add ah,8
rol bl,1
loop l1
jmp l
l2:
ror al,1
jc l3
inc ah
jmp l2
3. The following snippet may be used to pass row number to disp procedure for display (where bl has row
number)
cmp bl,04h
jne l5a
dec bl
l5a:
mov res,bl
4. The following snippet (disp procedure) may be used to display row value, column value, and key value
of the key pressed on screen (where dl has the value). M1 is a macro that prints the ASCII character for
the ASCII code passed, M2 is a macro that prints a blank character.
Page 41 of 55
LAB NO: 9
cmp dl,0ah
jnae l6
cmp dl,10h
jnc l7
M2
add dl,37h
M1 dl
ret
Lab Exercises
With the brief introduction of matrix keyboard and knowledge on 8255A,
Write 8086 ALP for the following:
1. Scan the keyboard for a key press and store the code of the key pressed in a memory location. Display
the same on the screen.
2. Scan the keyboard for a key closure. Get the row number and column number of the key pressed and store
it in some memory locations and display the same.
Additional Exercises
1. Simulate matrix keyboard for a calculator with the basic operations addition, subtraction.
multiplication and division.
---------------------------------------------------------------------------------------------------------------
Page 42 of 55
LAB NO: 11
Objectives:
In this lab, students will be able to,
A four line to ten-line decoder is used to specify the location of the elevator within the shaft. When the four
inputs to the decoder are sequenced through the binary codes corresponding to 0 to 9 with a time interval
between transitions, the elevator is seen to move. Two D flip-flops are used to sense requests and output
the status. A request is cleared because of servicing through the clear inputs of the flip-flops.
The Green LED’s goes ON, indicating the floor, while the Amber LED’s goes ON, indicating the elevator
to be in between 2 floors. The Red LED’s and Push button switch (SW0 to SW3) are used as floor request
status indicators and floor request buttons respectively.
Page 43 of 55
LAB NO: 11
elevator, the higher order port lines (PA7-PA4) being used to clear a request via the corresponding D flip
flop. Port B of 8255A is to be configured as input port, the lower order port lines (PB3-PB0) being used to
read the output from D flip flop so as to serve the current request (moving the elevator up or down), the
higher order port lines are left unused. A decoder is a combinational circuit with n inputs and 2 n outputs.
The BCD to Decimal decoder in Fig 10.1 has 4 inputs and 16 outputs of which only 10 outputs are used.
The other 6 outputs are left unused. It accepts inputs in the range 0000b to 1001b. Only one among the 10
outputs is active at a given point of time. A D flip flop is a sequential circuit with one input ‘D’ and two
outputs ‘Q and Q+’. If D is 1, Q+ is 1, else Q+ is 0.
Connection details:
Connect the bus from 8255A to the elevator interface.
Sample code snippet:
1. The following code snippet may be used for upward, downward movement of the elevator
Page 44 of 55
LAB NO: 11
2. The following code snippet may be used to generate the required delay
DELAY:
MOV DX, 0FFFH
LP05:
MOV CX, 0FFFFH
HERE: LOOP HERE
DEC DX
JNZ LP05
Lab Exercises
With brief introduction of elevator interface and knowledge on 8255A,
Write 8086 ALP for the following:
1. Simulate the elevator motion by interfacing the elevator kit
i. Initially the elevator should be in the ground floor, with all requests in OFF state.
ii. When a request is made from a floor, the elevator should move to that floor, wait there
for a couple of seconds, and then come down to ground floor and stop. If any requests
occur during going up or coming down, they should be ignored.
Additional Exercises
1. Repeat the above exercise including the following additives
i. A particular request is cleared as soon as the elevator reaches the desired floor
ii. Change the speed of the movement of the elevator
---------------------------------------------------------------------------------------------------------------
Page 45 of 55
LAB NO: 11
Objectives:
In this lab, students will be able to
i) Write 8086 ALP to interface DAC Kit , ADC Kit with 8086
ii) Learn and generate digital waveform patterns.
iii) Infer the applications of Digital-to-Analog converter, Analog-to-Digital converter
Data flow:
Connection details:
1. Connect the power supply
2. Connect the bus from 8255A to the DAC interface.
3. From DAC interface to CRO:
(i) Connect the 2 wires of OUT (DAC) to the hook end of the connector to the probe that comes with
CRO.
PORTA: black wire
PORTB: orange wire
(ii) Connect the 2 wires of GND (DAC) to the opposite end of the hook of the connector of the cable
that comes with CRO.
Page 46 of 55
LAB NO: 11
UP1: DEC AL
OUT DX, AL
CMP AL, 00H
JNZ UP1
Resolution—8bits
Conversion time—100 micro sec
Single supply—5V dc
8 channel multiplexer
0 to 5V analog input voltage range with single 5V supply
Low power consumption—15mW
Latched tristate output
Page 47 of 55
LAB NO: 11
In ADC interface, channel selection is done using port lines PC0, PC1 and PC2, START (conversion) and
ALE (Address Latch Enable) is controlled by port line PC7. Converted digital output is read by ADC
through Port A lines PA0-PA7 by enabling OE (Output Enable). Table 11.1 summarizes it.
Table 11.1
Port lines Description
PA0-PA7 Connected to data line D0-D7
PC0-PC2 Channel selection
PC7 Start & ALE
PC6 OE
Applications of ADC:
Operation of ADC:
The required channel is selected by sending the channel number on PC0-PC2 lines. When ALE is toggled
through port line PC7, the channel number is latched on to ADC and since PA7 line is connected to START
pin, conversion will begin at the same time. After conversion, EOC (End Of Conversion) of ADC will go
high. Now that EOC can be realized via one of the operating modes of ADC.
i. Polled mode: In this mode, 8086 continuously monitors or polls EOC line. When this line goes
high, OE should be made high and then low. This will put the digital equivalent of analog voltage
of the given channel on data lines of ADC. The digital data through port lines PA0-PA7 is read
and is displayed on data field of seven segment display.
ii. Interrupt mode: In this mode, connect JP6 pin1 to interrupt pin. When EOC goes high processor
is interrupted. In the ISR (Interrupt Service Routine), the digital output is read through port lines
PA0-PA7 after OE is toggled. The data is displayed on data field of seven segment display.
Connection details:
Connect the bus from 8255A to the ADC interface.
Page 48 of 55
LAB NO: 11
; start conversion
; PC7 (START/ALE) set
MOV AL, 0FH
MOV DX, CONTROL
OUT DX, AL
MOV CX, 20H
CALL DELAY
; PC7 reset
MOV AL, 0EH
MOV DX, CONTROL
OUT DX, AL
Page 49 of 55
LAB NO: 11
Lab Exercises
With brief introduction of DAC interface, ADC interface and knowledge on 8255A,
Write 8086 ALP for the following:
1. To generate the waveform in Fig 11.2 using the DAC interface. The output of the DAC is to be
displayed on the CRO.
Fig 11.2
2. To generate
(i) Square wave
(ii) Triangular wave
3. To store the converted ADC value in a memory location
Additional Exercises
1. Generate rectangular wave using DAC interface
2. Generate saw-tooth wave using DAC interface
--------------------------------------------------------------------------------------------------------------------------
Page 50 of 55
LAB NO: 12
Objectives:
In this lab, students will be able to
(i) Understand the different parts of stepper motor and the working of the same
(ii) Write 8086 ALP to interface stepper motor, logic controller with 8086
(iii) Infer the applications of stepper motor, logic controller
Like a typical motor, a stepper motor also has 2 essential parts (i) stator (ii) rotor. Stator does not move
whereas rotor moves. For the rotor to move stator is essential. Stator usually has electromagnets and the
number of electromagnets is variable. Likewise rotor usually has teeth and the number of teeth is variable.
In fact the angle by which the rotor rotates depends on the number of teeth in the rotor determined by the
formula
Angle of rotation= 360/number of teeth in the rotor
As shown in Fig 12.2, our stepper motor has four electromagnets in its stator and six teeth in its rotor. So
the angle by which rotor rotates is 60 degrees. Practically speaking real time stepper motors will have lots
of teeth.
Working:
Stepper motor works based on the concept of electromagnetic force. When current passes through an
electromagnet it becomes a magnet. Hence it will have two poles north and south poles. Each teeth in the
rotor is a permanent magnet. Hence each teeth will have two poles north and south poles. By the principle
“Opposite poles attract each other” the rotor rotates.
Connection details:
Connect the bus from 8255A to the stepper motor interface. It is to be noted that stepper motor is different
from stepper motor interface. Stepper motor is operated via the stepper motor interface.
How to generate binary patterns to rotate the motor clockwise and anticlockwise?
For clockwise or anticlockwise motion we need to excite the electromagnets in proper order
Clockwise motion:
For clockwise motion Table 12.1 or Table 12.2 may be followed to excite the electromagnets in order
Table 12.1 Truth Table for clockwise rotation in active high representation[2]
A B C D Code
1 0 0 0 08h
0 1 0 0 04h
0 0 1 0 02h
0 0 0 1 01h
Table 12.2 Truth Table for clockwise rotation in active low representation[2]
D C B A Code
1 1 1 0 0eh
1 1 0 1 0dh
1 0 1 1 0bh
0 1 1 1 07h
Anti-clockwise motion:
For anti-clockwise motion Table 12.3 or Table 12.4 may be followed to excite the electromagnets in order
Table 12.3 Truth Table for anti-clockwise rotation in active high representation[2]
A B C D Code
0 0 0 1 01h
0 0 1 0 02h
0 1 0 0 04h
1 0 0 0 08h
Table 12.4 Truth Table for anti-clockwise rotation in active low representation[2]
D C B A Code
0 1 1 1 07h
1 0 1 1 0bh
1 1 0 1 0dh
1 1 1 0 0eh
Page 52 of 55
LAB NO: 12
1. The following delay procedure may be used to create delay between the rotations. It is to be noted that
Port C of 8255A drives the stepper motor.
Logic controller is used in industry to exercise programmed control over a process. The nature of control
could range from a simple ON/OFF type of control to complex systems implementing sophisticated control
algorithms while accepting multiple inputs and actuating multiple outputs. The logic controller interface
consists of three 8-bit ports viz., port A, port B and port C wherein Port A is Output port , Port B is Input
port, Port C lower half is Output port and Port C upper half is Input port. The input and output lines of the
interface are hardwired accordingly. The input lines are connected to Port B and Port C upper half. The
output lines are connected to Port A and Port C lower half. Hence, there are 12 input and 12 output lines in
the interface. The inputs are connected to 12 DIP switches. The three ports are represented by means of
LEDs in the interface. 12 LEDs are reserved for inputs and the remaining 12 LEDs are reserved for outputs.
Connections details:
Connect the bus from 8255A to the logic controller interface.
Page 53 of 55
LAB NO: 12
Lab Exercises
With brief introduction of stepper motor, logic controller and knowledge on 8255A,
Write 8086 ALP for the following:
Additional Exercises
1. To rotate stepper motor anti-clockwise..
2. Read the status of 3 inputs from the logic controller interface. Assuming that these three inputs
represent a binary number X ( 0«X«7), display 2*X using the same interface.
3. Using logic controller interface, simulate Johnson counter.
Page 54 of 55
LAB NO: 12
REFERENCES
1. Douglas V.Hall, “Microprocessors and Interfacing”, Tata McGraw Hill Publications Ltd., Revised
Third edition.
2. Respective user manual for interfacing kit.
Page 55 of 55
[OBSERVATION SPACE]