You are on page 1of 80

Microprocessor Lab Manual

DAYANANDA SAGAR COLLEGE OF ENGINEERING


SHAVIGE MALLESHWARA HILLS,K.S.LAYOUT,BANGALORE-560078

Department of Computer Science and Engineering

Microprocessor Lab Manual


COMPILED BY

Prof. M. R Ravindranath. Prof. Rashmi S R Prof. Venugopal Rao A S

Dept.of CSE, DSCE,Bangalore

page 1

Microprocessor Lab Manual

COURSE OUTLINE

Week No
1.

Programs to be covered Introduction, study of assembler, debugger and simple programsDealt in the classroom. Part I Software programs Programs 1a & 2a & 3a Programs 4a & 5a Programs 6a & 7a Programs 8a & 9a & 10a Theory test week Programs 11a & 12a Programs 13a & 14a & 15a Part II Hardware programs Programs 1b & 2b & 3b Programs 4b & 5b & 6b Theory test week Programs 7b & 8b & 9b Programs 10b & 11b Programs 12b & 13b & 14b Programs 15b

2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15.

Dept.of CSE, DSCE,Bangalore

page 2

Microprocessor Lab Manual

1.a 1.b

2.a

2.b 3.a 3.b 4.a 4.b 5.a 5.b

6.a 6.b 7.a

7.b

Search a key element in a list of n numbers using the Binary Search algorithm. Read the status of eight input bits from the logic controller interface and display FF if it is even parity bits otherwise displays 00. Also display number of 1s in the input data. Write ALP macros: i) To read a character from the keyboard in the module (1)(in a different file) ii) To display a character in module (2)(from different file) iii) Use the above two modules to read a string of characters from the keyboard Terminated by the carriage return and print the string on the display in the next line. Perform the following functions using the Logic Controller interface. i) BCD up-down Counter ii ) Ring Counter. Sort a given set of n numbers in ascending and descending order using Bubble sort algorithm. Read the Status of two 8-bits inputs(X & Y) from the Logic Controller interface and display X*Y Read an alphanumeric character and display its equivalent ASCII code at the center of the screen Display the messages FIRE and HELP alternately with flickering effects on a 7segment display interface for a suitable period of a time. Ensure a flashing rate that makes it easy to read both messages.(Examiner does not specify these delays values nor it is necessary for the student to compute these values. Reverse a given string and check whether it is a Palindrome or not.. 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 a time. Ensure a flashing rate that makes It easy to read both the messages (Examiner does not specify these delay values nor it is necessary for the student to compute these values. Read two strings, store them in locations STR1 and STR2. Check whether they are equal or not display appropriated messages. Also display the length of the stored strings. Convert a 16-bit binary value(assumed to be an unsigned integer) to BCD and display it from left to Right and Right to left for specified number of times on a 7segment display interface. Read your name from the keyboard and display it at a specified location on the screen in front of the message WHAT IS YOUR NAME? You must clear the entire screen before display. Drive a Stepper motor interface to rotate the motor in clockwise direction by N steps. (N is specified from the examiner). Introduce suitable delay between successive steps.(Any arbitrary value for the delay may be assumed by the student).

Dept.of CSE, DSCE,Bangalore

page 3

Microprocessor Lab Manual

8.a 8.b 9.a 9.b 10.a 10.b 11.a 11.b 12.a 12.b 13.a 13.b 14.a 14.b 15.a 15.b

Compute the factorial of a positive integer n using recursive procedure. Drive a Stepper motor interface to rotate the motor in anticlockwise direction by N steps. (N is specified from the examiner). Introduce suitable delay between successive steps.(Any arbitrary value for the delay may be assumed by the student). Compute nCr Using recursive procedure. Assume that n and r are nonnegative integers. Drive a Stepper motor interface to rotate the motor by N steps left direction and N steps Right direction. (N is specified from the examiner). Introduce suitable delay between successive steps. (Any arbitrary value for the delay may be assumed by the student). Find out whether a given sub-string is present or not in a main string of characters.. Scan a 8x3 keypad for key closure and to store the code of the key pressed in a memory location or display on screen. Also display row and column numbers of the key pressed. Generate the first n Fibonacci numbers. Scan a 8x3 keypad for key closure and Simulate ADD and SUBTRACT operations as in a calculator. Read the current time from the system and display it in the standard format on the screen. Generate a sine wave Using DAC interface (The output of the DAC is to be displayed on a CRO) Program to simulate a decimal up-counter to display 00-99 Generate a Half Rectified sine wave from using the DAC interface(The output of the DAC is to be displayed on a CRO) Read a pair of input co-ordinates in BCD and move the cursor to the specified location on the screen Generate a Fully Rectified sine wave form using the DAC interface(The output of the DAC is to be displayed on a CRO) Program to create a file(input file) and to delete an existing file. Drive an elevator interface in the following way to move an elevator from ground to top floor and top to ground floor.

Dept.of CSE, DSCE,Bangalore

page 4

Microprocessor Lab Manual

Guidelines to use the assembler.


The assembly language programming can be done using the Assemblers. There are a number of assemblers available like MASM, TASM and DOS assembler .MASM is one of the popular assemblers used along with a LINK program to structure the codes generated in the form of an executable file. MASM reads the source program as its input and provides an object file. The LINK accepts the object file produced by MASM as input and produces an EXE file. ENTERING A PROGRAM Before starting the process, ensure that all the files namely NE.COM(Nortons Editor), MASM.EXE(Assembler),LINK.EXE(Linker),DEBUG.EXE(Debugger) are available in the same directory in which we are working. STEPS 1. OPEN THE TEXT EDITOR. COMMAND IS: C>TC OR C>NE 2. ENTER THE PROGRAM AND CHECK FOR THE MISTAKES AND SYNTAX ERRORS 3. SAVE THE PROGRAM WITH THE .ASM EXTENSION. COMMAND IS: FILENAME.ASM 4. ASSEMBLE THE PROGRAM. COMMAND IS: C>MASM FILENAME OR C>MASM FILENAME.ASM

Dept.of CSE, DSCE,Bangalore

page 5

Microprocessor Lab Manual After successful assembling, three files are created namely i) ii) The object file with .OBJ extension. The listing file with .LST extension. The listing file contains the total offset map of the source file including labels, offset addresses, opcodes, memory allotment for different labels and directives and relocation information. iii) The cross reference filename with .CRF extension. The cross reference file is used for debugging the source program and contains the statistical information size of the file in bytes, number of labels, list of labels, routines to be called, etc. about the source program. These files are used to link the object modules and generate an executable (.EXE) file from a .OBJ file. 5. Link the object modules of the source program and the function library generate an integrated executable code of the source program. COMMAND IS: C>LINK FILENAME.OBJ The output of the LINK program is an executable file with the entered filename and .EXE extension. 6. DEBUG.COM, a DOS utility can be used for debugging and trouble-shooting . of assembly language programs COMMAND IS: C>DEBUG A -(dash) display signals the successful invoke operation of DEBUG. Some of the DEBUG commands used are as follows: -R -D -g -q Display all registers and flags. Display 128 memory locations of RAM starting from the current display pointer. Execute from current CS: IP. Quit the DEBUG and return to DOS. routines to

-T SEG: OFFSET Trace the program execution by single stepping

Dept.of CSE, DSCE,Bangalore

page 6

Microprocessor Lab Manual

General form of any assembly program.


We can see all the programs will follow some common format. The best way to begin with the programming is to analyze the given problem. Then we can understand that the program needs some inputs. Sometimes the result of the program needs to be stored in the memory. Hence the given program demands for a certain amount of logical space. This is called as DATA SEGMENT. Similarly the program will have the space for the instructions to execute the given problem. This requires a logical space called as CODE SEGMENT. If any program needs stack facility then it must use STACK SEGMENT and one more logical block called EXTRA segment can also be used as an additional destination data segment. Note that all these segments are not compulsory for the program. Only CODE segment is compulsory and rest all can be used depending on the requirement. In our programs we have used DATA SEGMENT and CODE SEGMENT only as other two segments are of no use in these programs. These are represented by .DATA and .CODE. These are also called as assembler directives. Assembler Directives indicate how an operand or section of the program is to be processed by the assembler. Some directives generate and store information in memory while others do not. Most commonly used assembler directives are listed below with their meaning. .small .data---- Defines data segment .code--- defines code segment .stack --- Defines Stack segment .extra--- defines Extra segment BYTE indicates Byte sized data DB --- Defines Byte (8 bits) DD --- Defines Double words ( 32 bits) DUP--- generates duplication DW defines word (16 bits) END ends the program ENDM ends the macro ENDP ends a procedure. EQU equates data to label

Dept.of CSE, DSCE,Bangalore

page 7

Microprocessor Lab Manual

SOFTWARE PROGRAMS

Dept.of CSE, DSCE,Bangalore

page 8

Microprocessor Lab Manual 1a. Search a key element in a list of 'n' 16-bit numbers using the Binary search algorithm. ------------------------------------------------------------------------------------------------------------------------Objective: In this program, students will learn the implementation of the Binary search algorithm. ------------------------------------------------------------------------------------------------------------------------Outcome: Students will learn the usage of simple assembly language instructions and also will implement binary search algorithm to find the given key. If the key is found a message FOUND will be displayed otherwise NOT FOUND will be displayed. ------------------------------------------------------------------------------------------------------------------------ALGORITHM: Step 1. define the sorted array of elements as LIST. Step 2. get the length of the array and store it in LNTH Step 3. Set a pointer SI to zero Step 4: Copy the length of the array to one more pointer DI. Step 5. Subtract one from DI. Step:6 If SI is more that DI conclude that the SKEY is not there else do the following steps. Step 7: Add SI and DI which are nothing but the start and end of the array. Divide this by two to get the mid location of the array. This is done by SHR operation which rotates the sum to the right by one bit position. Now BX contains the MID position of the array. Step 8: Get the element of the location BX of the array LIST to AL. and compare it with SKEY. If they are equal go the last stage and display the message FOUND else go to next step. Step 9: If the key is greater than mid-element of the array, change the low value that is SI value to [mid+1] and repeat the steps 6, 7 and 8. Step10: If the key is smaller than mid-element of the array, change the high value that is DI value to [mid-1] and repeat the steps 7 and 8. ------------------------------------------------------------------------------------------------------------------------Program: .MODEL SMALL .DATA LIST DB 1, 2,3,4,5 LNTH DW $ - LIST SKEY DB 03 MSG1 DB 'FOUND $' MSG2 DB 'NOT FOUND $' .CODE MOV AX,@DATA MOV DS, AX MOV SI,0 MOV DI,LNTH SUB DI,01 BAK: CMP SI,DI JA NF MOV BX,SI Dept.of CSE, DSCE,Bangalore

;To find mid point page 9

Microprocessor Lab Manual ADD BX,DI ;(low+high) SHR BX,01 ;Shift bit to right gives no./2 MOV Al, LIST[BX] CMP Al, SKEY JE YF ;If (key==[mid]) jump to found JB NM ;else if(key>[mid]) jump to NM MOV DI,BX ; else DI=mid-1 SUB DI,01 CMP DI,0 JZ NF JMP BAK NM: MOV SI,BX ;SI=[mid+1] ADD SI,01 JMP BAK NF: LEA DX,MSG2 JMP NEXT YF: LEA DX,MSG1 NEXT: MOV AH,09H ;Func(09h),Display String,DX=offset of msg INT 21H MOV AH,4CH :Func(4ch),Terminate program INT 21H ; Call DOS Service END ------------------------------------------------------------------------------------------------------------------------Output: Found ------------------------------------------------------------------------------------------------------------------------Viva Questions: 1. Explain the logic of Binary search. 2. Why $ symbol is to be used at the end if the string message to be displayed? 3. Explain JA, JE and JB instructions 4. What is data segment? 5. What is code segment?

Dept.of CSE, DSCE,Bangalore

page 10

Microprocessor Lab Manual 2a. Write a ALP macros: i) To read a character from the keyboard in the module (1)(in a different file) ii) To display a character in module (2) (from different file) iii) Use the above 2 modules to read a string of characters from the keyboard terminated by the carriage return and print the string on the display in the next line. ------------------------------------------------------------------------------------------------------------------------Objective : In this program the students will learn to input the data to the processor using standard input device that is keyboard. Also they will display the same on the standard output device. These two operations are done by two separate macros which are external to the main program. The user must write the two macros first as two separate files and then they can write and execute the main program. ------------------------------------------------------------------------------------------------------------------------Outcome: Understanding the use of standard input and output devices also the usage of macros in the assembly language programming, ------------------------------------------------------------------------------------------------------------------------Algorithm: 1. Write the macro for reading a key from keyboard. (m1.inc) Interrupt INT 21 is called with AH having the value 01H.. This will enable the processor to read one character from the keyboard. After reading one character the control will be given to main program. 2. Write the macro for outputting the key being read from keyboard. (m2.inc) Interrupt INT 21 is called with AH having the value 02H. This will enable the processor to write one character to the standard output device. After displaying one character the control will be given to main program. 3. Main program: Define a string of size 10 bytes with name STR to store the key elements being pressed. 4. Call the macro READ, which reads the key from the keyboard. This will read the ASCII value of the key being pressed and store it in AL register. After every key is read increment a counter SI. 5. Compare this with the ACII Value of ENTER key i.e. 0DH If both are matching end the read process else store the data in AL to STR array till ENTER key is being pressed. 6. If the ENTER key is pressed, stop the reading operation and go to DISP macro which displays one character at a time. The counter SI is used to ensure all characters of STR are being displayed. 7: After displaying all the characters terminate the program. ------------------------------------------------------------------------------------------------------------------------Program INCLUDE c:\masm6.0\bin\m1.inc INCLUDE c:\masm6.0\bin\m2.inc .MODEL SMALL .DATA STR DB 10 DUP(?) .CODE MOV AX,@DATA MOV DS,AX MOV SI,0 READ1: READ Dept.of CSE, DSCE,Bangalore ; macro to read a character ; macro to display a character

; To call macro Read page 11

Microprocessor Lab Manual CMP AL,0DH JE HERE MOV STR[SI],AL INC SI JMP READ1 HERE: MOV CX,SI MOV SI,0 MOV DL,10 DISPLAY DISP1: MOV DL,STR[SI] DISPLAY INC SI LOOP DISP1 MOV AH,4CH INT 21H END ; 0dh ascii value for carriage return

; ASCII value for line feed ; To call Macro display

m1.inc ; macro to read a character m2.inc ; macro to display a character READ MACRO DISPLAY MACRO MOV AH, 01H ;Func(01h),Read char MOV AH, 02H ;Func(02h),Write char INT 21H INT 21H ENDM ENDM ------------------------------------------------------------------------------------------------------------------------Input: Dsce Output: Dsce ------------------------------------------------------------------------------------------------------------------------Viva Questions: 1. What is a macro? 2. What do you understand by assembler directives? 3. How can you classify the instruction set of 8086? 4. explain loop instruction. 5. Can we display the string STR without using loop instruction?

Dept.of CSE, DSCE,Bangalore

page 12

Microprocessor Lab Manual 3a. Sort a given set of 'n' numbers in ascending and descending orders using Bubble sort algorithm. ------------------------------------------------------------------------------------------------------------------------Objective: To learn the bubble sort algorithm and implement the same using 8086 assembly language. ------------------------------------------------------------------------------------------------------------------------Out come: Students will learn to check the data in different segments of memory and also will learn the usage of instructions like XCHG. ------------------------------------------------------------------------------------------------------------------------Algorithm. 1. A gives the array elements which need to be sorted. Get the length (say n) of this array and store it in variable L. 2. Initialize two counters BX and CX with values n and n-1. Also initialize counter SI to 0 3. Comparison operation and exchange of elements. Move first element of Db to Al, and compare with next element in the array. If [Al] < A[SI] keep the elements in tact if not exchange contents of Al and A[SI]. Repeat this same till counter CX becomes zero. Hence we get largest element at the first iteration. Repeat this for (n-1) times and you will get the sorted array. Execution procedure: a. Save the program in the folder which has CV. b. while compiling the code type, masm/Zi filename.asm; link/CO filename.obj; CV file name. This will take the user to a window as shown in fig 1. c. Now go to Run in the menu and select start to run the program. User will be prompted with the message saying program terminated normally as shown in fig 2.. d. Now come to the command prompt and type d A as shown in fig 3. Here user can see the sorted array. For first 10 locations of array A.

Dept.of CSE, DSCE,Bangalore

page 13

Microprocessor Lab Manual

Fig 1. Execution of the program

Fig Fig. 2 the successful execution of the program

Dept.of CSE, DSCE,Bangalore

page 14

Microprocessor Lab Manual

Fig 3.

Dept.of CSE, DSCE,Bangalore

page 15

Microprocessor Lab Manual .MODEL SMALL .DATA A Db 85H,95H,25H, 45H, 55H, 15H, 65H, 45H L DW $ - A ;Length of array .CODE MOV AX, @DATA MOV DS, AX MOV BX, L ;BX=No. of iterations DEC BX NP: MOV CX, BX ;CX=No. of comparison in each iteration MOV SI, 0 NI: MOV Al, A[SI] INC SI CMP Al, A[SI] JBE NEXT ;for descending order JAE NEXT XCHG Al, A[SI] ;Exchange If (AL< [SI+1]) MOV A[SI-1],Al NEXT: LOOP NI DEC BX JNZ NP MOV AH, 4CH INT 21H END ------------------------------------------------------------------------------------------------------------------------Output: >d A 15 45 45 55 65 85 95 ------------------------------------------------------------------------------------------------------------------------Viva questions:

Dept.of CSE, DSCE,Bangalore

page 16

Microprocessor Lab Manual 4a. Read Alphanumeric Character & display its equivalent ASCII code at the centre of screen . ------------------------------------------------------------------------------------------------------------------------Objective: In this program, the user will input any alpha numeric character and see the corresponding ASCII value on the standard output device. ------------------------------------------------------------------------------------------------------------------------Outcome: The user will come to know the various kinds of DOS interrupts to clear the screen to select a specific location on the screen to display the data and also to get the ASCII value of the key being pressed. ------------------------------------------------------------------------------------------------------------------------Algorithm. 1. Defining various macros to perform specific tasks like displaying a message to the user to prompt him to enter the alpha numeric data, to clear the screen and to set the location of the screen where the ASCII value of the key pressed to be displayed. These are achieved by various DOS interrupts with suitable values in AX register. 2. PRINT MSG Macro- here the message stored at the address DS: DX will be displayed on the standard output when the interrupt INT21H being called with AH having the value 09H 3. SCR Macro Clears the Screen when the interrupt INT21H being called with AH having the value 00H and AL having the value 03H. 4. POS Macro- This macro sets the cursor location using INT 10 interrupt. INT 10 takes inputs in 3 registers DH- row number, DL column number and BH page number( 0 -7) 5. Inputted character which is stored in AL is first divided by 10. If the reminder is greater than 10 divide again by 10. 6. If AL is less than 10 then go ahead with the following steps. 7. Now we have each digit of the input ASCII code in AX. Now add 3030H to this to adjust to the proper ASCII Value and display it. ------------------------------------------------------------------------------------------------------------------------Program: .MODEL SMALL PRINT MACRO MSG ; Macro to display string MOV AH,09H MOV DX,OFFSET MSG INT 21H ENDM SCR MACRO MOV AH,00H MOV AL,03H INT 10H ENDM POS MACRO MOV AH,02H MOV BH,00H Dept.of CSE, DSCE,Bangalore ;Macro to clear to screen

;Macro to Set the cursor

page 17

Microprocessor Lab Manual MOV DH,0CH MOV DL,23H INT 10H ENDM .DATA TMP DB ? TMP1 DB ? MSG1 DB 10,13, 'Enter the alpha-numeric character:$' .CODE MOV AX,@DATA MOV DS,AX SCR PRINT MSG1 MOV AH,01H ;i/p of char i.e. ASCII equivalent code is stored in AL INT 21H MOV AH,00H ;divide the no. with 10 gives the decimal equivalent of hex no. MOV BL,10 ;converted no. is stored in AX register DIV BL MOV TMP1,AH CMP AL,10D JGE L2 ADD AX,3030H MOV CX,AX POS MOV AH,06H ;display the no. in the centre of the screen MOV DL,CL INT 21H MOV AH,06H MOV DL,CH INT 21H JMP LAST L2: MOV AH,00H DIV BL ADD AX,3030H MOV TMP,AH POS MOV AH, 06H MOV DL, AL INT 21H MOV AH, 06H MOV DL, TMP INT 21H MOV AH, TMP1 ADD AH, 30H Dept.of CSE, DSCE,Bangalore ;if after 1 div the no. is not converted divide it further

page 18

Microprocessor Lab Manual MOV TMP1, AH MOV AH, 06H MOV DL, TMP1 INT 21H LAST: MOV AH,4CH INT 21H END ------------------------------------------------------------------------------------------------------------------------Output: Enter the alpha-numeric character: 7 55 Viva questions 1. What is the difference between AH, 06h and AH, 02H with INT 21H? 2. What is the necessity of adding 3030H.

Dept.of CSE, DSCE,Bangalore

page 19

Microprocessor Lab Manual 5a. Reverse a given string and check whether it is a palindrome or not. ------------------------------------------------------------------------------------------------------------------------Objective: In this program the user will learn to reverse the string and also checks whether it is a palindrome or not. ------------------------------------------------------------------------------------------------------------------------Outcome: The user will get familiar with the string operations like reversing a string, comparing a string etc. ------------------------------------------------------------------------------------------------------------------------Algorithm: 1. Define the string to be checked whether it is palindrome or not and also get the length of the string 2. RSTR is used to store the string after reversing it. 3. Copy the length of the string to CL also store [CL-1] at DI 4. Point STR and RSTR using SI and DI. 5. Copy the first element of STR array to the last element of RSTR array. Repeat this process till all the elements are copied. CX register is used as counter to keep track of copying process. 6. Clear the direction flag using CLD and use CMPSB to compare two strings byte by byte. 7. If comparison gives a positive result then display String is palindrome els display string is not palindrome. .MODEL SMALL .STACK 100 .DATA STR DB 'MALAYALAM' N DB $-STR RSTR DB 10 DUP(0) MSG1 DB 'STRING IS PALINDROME$' MSG2 DB 'NOT PALINDROME$' .CODE MOV AX,@DATA MOV DS,AX MOV ES,AX MOV CL,N DEC CL MOV DI,CX INC CX BAK: MOV AH,STR[DI] MOV RSTR[SI],AH INC SI DEC DI LOOP BAK LEA SI,STR Dept.of CSE, DSCE,Bangalore

;To reverse the string ; To reverse the string

page 20

Microprocessor Lab Manual LEA DI,RSTR CLD MOV CL,N ;CL=Size of string REPE CMPSB ;To compare the 2 strings JE DMSG1 ;Jump on equal to Found LEA DX,MSG2 ;If not equal display not found JMP XIT DMSG1: LEA DX,MSG1 XIT: MOV AH,09H INT 21H MOV AH,4CH INT 21H END ------------------------------------------------------------------------------------------------------------------------Input: MALAYALAM ( This is provided in the program itself, and user can change to any other string before executing the program) Output: STRING IS PALINDROME ------------------------------------------------------------------------------------------------------------------------Viva questions: 1. What is a palindrome? 2. Explain CMPSB instruction 3. What is the function of CLD instruction?

Dept.of CSE, DSCE,Bangalore

page 21

Microprocessor Lab Manual 6a. Read 2 strings, store them in locations STR1 and STR2 check whether they are equal or not and display appropriate messages. Also display the length of the stored strings . ------------------------------------------------------------------------------------------------------------------------Objective: This program will help the user to get familiarized with string compare operations and the user will be able to compare two strings by comparing character by character in the given two strings. ------------------------------------------------------------------------------------------------------------------------Outcome: The user will learn to compare two strings by using this program. Comparison takes place character by character. ------------------------------------------------------------------------------------------------------------------------Algorithm: 1. Declare two arrays STR1 and STR2 in 3 bytes format (1 for maximum number of characters) (2 for length of the string) (3 for string itself) 2. Read the strings from the STD input and store the length of the strings in BL and CL also. 3. Add 3030H to convert it to BCD format to be displayed and display the length of each string. 4. Store the string1 and string2 in 3 bytes format 5. Compare the length of the strings if they are not equal display the message strings are not equal and terminate the program else go to next step. 6. Clear the direction flag and using CMPSB instruction compare STR1 and STR2 7. If they are equal display Strings are equal and terminate the program else display Strings are not equal and terminate the program. ------------------------------------------------------------------------------------------------------------------------.MODEL SMALL .DATA STR1 DB 100 ;To store the length & the string1 DB 0 DB 100 DUP(0) STR2 DB 100 ; To store the length & the string2 DB 0 DB 100 DUP(0) M1 DB 'LENTH OF THE STR1:' L1 DB ?,10,13,'$' ;To print the length of string1 M2 DB 'LENTH OF THE STR2:' L2 DB ?,10,13,'$' ; To print the length of string2 M3 DB 'STR1 IS EQUAL TO STR2$' M4 DB 'STR1 IS NOT EQUAL TO STR2$' .CODE MOV AX,@DATA MOV DS,AX MOV ES,AX LEA DX, STR1 Dept.of CSE, DSCE,Bangalore page 22

Microprocessor Lab Manual MOV AH,0AH ;Func(0AH),Read & Print string1 INT 21H MOV DL, 10 MOV AH, 02H INT 21H LEA DX,STR2 INT 21H ; Func(0AH),Read & Print string2 MOV CL,STR1+1 ;CL=Length of string1 MOV BL,STR2+1 ; BL=Length of string2 ADD CL,30H ADD BL,30H MOV L1,CL MOV L2,BL SUB CL,30H SUB BL,30H LEA DX,M1 ;To Print the length of string1 MOV AH,09H INT 21H LEA DX,M2 ; To Print the length of string2 INT 21H CMP CL,BL ;Compare the length of strings JZ NEXT ;If length of string1=string2,Compare DM4:LEA DX,M4 ;If length of string1!= string2 MOV AH,09H ;Print Not Equal & Exit INT 21H JMP EXIT NEXT: LEA SI,STR1+2 ;Load effective address of string1 LEA DI,STR2+2 ; Load effective address of string2 CLD REPE CMPSB ;Compare two strings JNZ DM4 ; If strings are not equal print not equal LEA DX,M3 ;Else print strings are equal MOV AH,09H INT 21H EXIT:MOV AH,4CH INT 21H END ------------------------------------------------------------------------------------------------------------------------Output: ravi ravi LENTH OF THE STR1: 4 LENTH OF THE STR2: 4 STR1 IS EQUAL TO STR2 Viva Questions: Dept.of CSE, DSCE,Bangalore page 23

Microprocessor Lab Manual 1. What is the size of instruction queue in 8086? 2. What is the size of instruction queue in 8088? 3. Which are the registers present in 8086? 4. What is pipelining in 8086? 5. How many 16 bit registers are available in 8086?

Dept.of CSE, DSCE,Bangalore

page 24

Microprocessor Lab Manual 7a. Read your name from the keyboard and display it at a specified location on the screen in front of the message What is your name? You must clear the entire screen before display. ------------------------------------------------------------------------------------------------------------------------Objective: The user will read a string from the keyboard and then display it along with the predefined text What is your name? ------------------------------------------------------------------------------------------------------------------------Outcome: The user will learn about the properties of the screen and also will learn to clear the screen and to set the cursor location as per his requirement. ------------------------------------------------------------------------------------------------------------------------Algorithm: 1. Read the name from the STD input device and store it in NEM array. 2. Append $ at the end of the name. 3. Clear the screen and set the location of the cursor to print the required message along with the name. 4. Display the name along with the string What is your name? 5. terminate the program. ------------------------------------------------------------------------------------------------------------------------Program: .MODEL SMALL .DATA MSG DB 'WHAT IS YOUR NAME:' NEM DB 50 DUP (0) .CODE MOV AX,@DATA MOV DS,AX MOV SI,0 MOV AH,1 BAK: INT 21H MOV NEM[SI],AL INC SI CMP AL,13 JNE BAK MOV BYTE PTR NEM[SI],'$' CALL CLR CALL SETC LEA DX,MSG MOV AH,9 INT 21H MOV AH,4CH INT 21H CLR:MOV AH,6 MOV AL,0 MOV BH,7 Dept.of CSE, DSCE,Bangalore

;Func(01H),I/p a char with echo from keyboard ;Move each character to the array

;End of the string ;Clear the screen ;Set the cursor to the specified location ;Display message What is your Name?

;Procedure to clear the screen

page 25

Microprocessor Lab Manual MOV CH,0 MOV CL,0 MOV DH,24 ;DH=Position of the row MOV DL,79 ; DL=Position of the col INT 10H RET SETC: MOV AH,2 ;Procedure to set the cursor MOV BH,0 MOV DH,12 ;DH=Position of the row MOV DL,20 ;DL=Position of the col INT 10H RET END ------------------------------------------------------------------------------------------------------------------------Output: Ravi What is your name? Ravi ------------------------------------------------------------------------------------------------------------------------Viva Questions: 1. Specify addressing modes for any instruction? 2. What are assembler directives? 3. What .model small stands for? 4. What is the supply requirement of 8086? 5. What is the relation between 8086 processor frequency & crystal frequency? 6. Functions of Accumulator or AX register?

Dept.of CSE, DSCE,Bangalore

page 26

Microprocessor Lab Manual 8a. Compute the factorial of a positive integer 'n' using the recursive procedure. ------------------------------------------------------------------------------------------------------------------------Objective: The user will implement the computation of factorial of the given 8 bit number using recursive procedure. ------------------------------------------------------------------------------------------------------------------------Outcome: The use of procedures and concept of recursive procedure is dealt with this program. ------------------------------------------------------------------------------------------------------------------------Algorithm: 1. AX is initialized with 01 which is the least possible factorial value (0!= 1). 2. Compare the given number with zero and if it is equal display [AX] as factorial and terminate the program else go to next step. 3. Now call FACT procedure. 4. If the number is 01 return [AX] as the result else go next step. 5. Push the contents of the BX to stack and decrement BX and call FACT recursively till BX becomes 1 6. POP every pushed value of BX from the stack and multiply with [AX] and return to main program. 7. Display AX contents as the factorial of the given number and terminate the program. ------------------------------------------------------------------------------------------------------------------------Program: .MODEL SMALL .DATA NUM DW 5 RESULT DW ? .CODE MOV AX,@DATA MOV DS,AX MOV AX,01 MOV BX,NUM CMP BX,00 ;Compare num with 00 JE NEXT CALL FACT NEXT:MOV RESULT,AX MOV AH,4CH INT 21H FACT PROC NEAR ;Recursive procedure to calculate Factorial CMP BX,01 ;Compare num with 01 JZ RIP PUSH BX DEC BX CALL FACT POP BX MUL BX Dept.of CSE, DSCE,Bangalore page 27

Microprocessor Lab Manual RIP:RET FACT ENDP END ------------------------------------------------------------------------------------------------------------------------Output: >d Result 78 ------------------------------------------------------------------------------------------------------------------------Viva questions: 1. What is recursive function? 2. Specify addressing modes for any instruction? 3. What are assembler directives? 4. What .model small stands for? 5. What is the supply requirement of 8086? 6. What is the relation between 8086 processor frequency & crystal frequency? 7. Functions of Accumulator or AX register?

Dept.of CSE, DSCE,Bangalore

page 28

Microprocessor Lab Manual 9a. Compute nCr using recursive procedure. Assume that 'n' and 'r' are non-negative integers. ------------------------------------------------------------------------------------------------------------------------Objective: The objective of this program is to compute the nCr of the given two 8 bit numbers and display the same. ------------------------------------------------------------------------------------------------------------------------Outcome: The user will learn to implement the mathematical expression for nCr using assembly language programming also use of code-view to see the result of the program. ------------------------------------------------------------------------------------------------------------------------Algorithm: 1. Declare assembler directives 2. Store the values of n in N and r in R(nCr ) in the data segment store 0 in the variable NCR 3. Initialize the DS register. 4. Store the values of N in AX-register and the value of R in BX register. 5. Call the procedure NCRPRO. a. Compare BX and AX register (i.e. N=R),If they are equal then increment NCR and return the value (i.e. 0+1) b. Compare if BX-0(i.e. R=0).If true, then add the contents of AX to NCR and return the values (i.e. NCR=N) c. Compare if BX-1(i.e. R=1).If true, then add the contents of AX to NCR and return the values (i.e. NCR=N) d. If none of steps a, b, c, is true then increment NCR e. Push values of AX&BX. And repeat step 5 6. POP the values of AX and BX .Decrement BX and again Push the values of AX and BX 7. Repeat from step 5 8. Pop the contents of BX and AX and return to display. 9. Terminate the program ======================================================================= Program .MODEL SMALL .DATA N DW 5 R DW 3 NCR DW 0 .CODE MOV AX,@DATA MOV DS,AX MOV AX,N MOV BX,R CALL NCRPRO MOV AH,4CH INT 21H NCRPRO:CMP BX,AX JE RES1 Dept.of CSE, DSCE,Bangalore

:Recursive procedure to calculate NCR ;If BX==AX,NCR=1

page 29

Microprocessor Lab Manual CMP BX,0 ;If BX==0.NCR=1 JE RES1 CMP BX,1 ;If BX==1 ,NCR=N JE RESN DEC AX CMP BX,AX ;Compare BX & AX JE INCR ;If BX==AX,NCR=1 PUSH AX PUSH BX CALL NCRPRO POP BX POP AX DEC BX PUSH AX PUSH BX CALL NCRPRO POP BX POP AX RET RES1:INC NCR RET INCR:INC NCR RESN: ADD NCR,AX RET END ==================================================================== Output: > D ncr 0A ===================================================================== Viva Questions: 1. Functions of BX register? 2. Functions of CX register? 3. Functions of DX register? 4. How Physical address is generated? 5. Which are pointers present in this 8086?

Dept.of CSE, DSCE,Bangalore

page 30

Microprocessor Lab Manual

10a. Find out whether a given sub string is present or not in a main string of characters. ======================================================================= Objective: The objective of this program is to check whether the given substring is present in the main string. If present display Substring is present message at standard output device and if not present display substring is not found msg. ======================================================================= Outcome: The user will learn how to search for the given substring in the main string and also compare two strings using CMPSB instruction. ======================================================================= Algorithm: 1. 1. Declare assembler directives 2. Initialize the main string with the name STR and store the length of the string in L1 3. Initialize the substring with the name SUBS and store the length of the SUBS is L2 4. Define the msg1 as substring is pushed in the main string and msg2 as substring is not present in the main string 5. Initialize the data segment and extra segment 6. Initialize counters by storing the length L1 in CX and l2 in BX 7. Load the effective address of STR in DI and SUBS in SI 8. SCAN byte by byte the main STR and SUBS 9. If it is equal then increment SI and the values of CX in DX 10. Subtract CX and BX i.e. if CX <BX then print msg2 else move the SUBS to CX 11. Now compare byte by byte CX and BX if It is equal then go to step14 12. If it is not equal then jump to NFT 13. Load the SUBS again and jump back to the calling function. 14. Print msg1 and terminate the program ======================================================================= Program .MODEL SMALL .DATA STR DB 'ONEPLUSTWOISEQUALTOTHREE' L1 DW $-STR SUBS DB 'PLUS' L2 DW $-SUBS MSG1 DB 'SUBSTRING IS PRESENT IN MAIN STRING$' MSG2 DB 'SUBSTRING IS NOT PRESENT IN MAIN STRING$' .CODE MOV AX,@DATA MOV DS,AX MOV ES,AX MOV CX,L1 MOV BX,L2 LEA DI,STR LEA SI,SUBS Dept.of CSE, DSCE,Bangalore page 31

Microprocessor Lab Manual CLD RPT:MOV AL,[SI] REPNE SCASB ; Compares AL with every letter of STR INC SI MOV DX,CX DEC BX SUB CX,BX ; if the length of main string is < substring display msg2 JB DMSG2 MOV CX,BX REPZ CMPSB ; else compare the two strings JNZ NFT ; if strings are not equal display msg2 LEA DX,MSG1 ; else display msg1 MOV AH,9 INT 21H JMP EXIT DMSG2: LEA DX,MSG2 MOV AH,9 INT 21H EXIT: MOV AH,4CH INT 21H NFT:MOV CX,DX LEA SI,SUBS MOV BX,L2 JMP RPT END ======================================================================= Output: SUBSTRING IS PRESENT IN MAIN STRING ======================================================================= Viva questions: 1. What is the difference between instructions DIV & IDIV? 2. What is difference between shifts and rotate instructions? 3. Which are strings related instructions? 4. Which are addressing modes and their examples in 8086? 5. What does u mean by directives?

Dept.of CSE, DSCE,Bangalore

page 32

Microprocessor Lab Manual 11a. Generate the first N Fibonacci numbers . ------------------------------------------------------------------------------------------------------------------------Objective: The objective of this program is to generate first N Fibonacci series numbers. The value of N is specified by the user before execution of the program. ------------------------------------------------------------------------------------------------------------------------Outcome: Fibonacci series is the series in which first two numbers are 0 and 1 and next numbers are generated by adding previous two numbers. The user will learn to generate such a series using 8086 assembly language programming. ------------------------------------------------------------------------------------------------------------------------Algorithm: 1. Initialize limit for the series N as 10 and the first two elements of the array FNS as 0 and 1. 2. Set the counter as 8 as first two elements of the series are already stored in the array. 3. Use SI as pointer to FNS array. 4. To compute next element i.e. [SI+ 1]th element, add [SI] to [SI-]] 5. Increment SI and store the sum at [SI]. Decrement the count 6. Repeat step 4 and 5 till counter becomes zero. 7. Terminate the program. ------------------------------------------------------------------------------------------------------------------------Program: .MODEL SMALL .STACK .DATA N DB 10 FNS DB 32 DUP(0) .CODE MOV AX,@DATA MOV DS,AX MOV SI,0 MOV FNS[SI],0 ; copy the first number to the array ADD SI,1 MOV FNS[SI],1 ; copy the second number to the array MOV CL,N SUB CL,2 ; CL= n -2 (for the rest of the length) BAK:MOV AL,FNS[SI-1] ADD AL,FNS[SI] ADD SI,1 MOV FNS[SI],AL LOOP BAK MOV AH,4CH INT 21H END -------------------------------------------------------------------------------------------------------------------------

Dept.of CSE, DSCE,Bangalore

page 33

Microprocessor Lab Manual Output: >D FNS 00 01 01 02 03 05 08 0D 15 22 ------------------------------------------------------------------------------------------------------------------------Viva Questions: 1. What does u mean by Prefix? 2. What .model small means? 3. Difference between small, medium, tiny, huge? 4. What is dd, dw, db? 5. Interrupts in 8086 and there function.

Dept.of CSE, DSCE,Bangalore

page 34

Microprocessor Lab Manual 12a. Read the current time from the system and display it in the standard format on the screen. ------------------------------------------------------------------------------------------------------------------------Objective: The objective of the program is to use the DOS interrupts to display the system time on the standard output device i.e. the monitor. ------------------------------------------------------------------------------------------------------------------------Outcome: The user will learn different DOS interrupts which will display the system time in the standard format. ------------------------------------------------------------------------------------------------------------------------Algorithm: 1. Interrupt INT 21H with AH having the value 2CH, will copy the system time to the registers in the following manner. [CH]- Hrs, [CL]- min, [DH]- sec. 2. Call display procedure to display the contents of CH, CL and DH taking one register contents at a time. This sub routine will convert the contents of the register from HEX value to BCD value by adding 3030H and executing AAM instruction. 3. The program also places : symbol between each numerical value to show the output in the standard format. 4. terminate the program ------------------------------------------------------------------------------------------------------------------------Program: .MODEL SMALL .CODE MOV AH,2CH ; func(2Ch), to get the system time INT 21H ; stores hrs, mins, secs in CH,CL,DH respectively MOV AL,CH CALL DISP MOV DL,':' MOV AH,2 INT 21H MOV AL,CL CALL DISP MOV DL,':' MOV AH,2 INT 21H MOV AL,DH CALL DISP MOV AH,4CH INT 21H DISP PROC NEAR AAM ; Converts HEX values to unpacked BCD format ADD AX,3030H MOV BX,AX MOV DL,AH MOV AH,02 Dept.of CSE, DSCE,Bangalore page 35

Microprocessor Lab Manual INT 21H MOV DL,BL INT 21H RET DISP ENDP END ------------------------------------------------------------------------------------------------------------------------Output: 09:55:45 ------------------------------------------------------------------------------------------------------------------------Viva Questions: 1. What is the function of 01h of Int 21h? 2. What is the function of 02h of Int 21h? 3. What is the function of 09h of Int 21h? 4. What is the function of 0Ah of Int 21h? 5. What is the function of 4ch of Int 21h?

Dept.of CSE, DSCE,Bangalore

page 36

Microprocessor Lab Manual 13a. Program to simulate a decimal up-counter to display 00-99 ------------------------------------------------------------------------------------------------------------------------Objective: The objective of this program is to display the counter starting from 00 to 99. ------------------------------------------------------------------------------------------------------------------------Outcome: The user will learn to write delay programs of the specified amount of delay between each display of the count value. The concept of instruction cycle, machine cycle execution time etc will be well understood while designing the delay subroutine. ------------------------------------------------------------------------------------------------------------------------Algorithm: 1. Set the initial count value as 0 in AX 2. Set the cursor location to display the count values. 3. Push the contents of AX to stack. Display the count value and call some delay before next value gets displayed. 4. Check whether any key is pressed to end the counter by calling interrupt INT 16H which checks the keyboard buffer. 5. If key is pressed stop the counter and terminate the program else go to next step. 6. Pop back contents of AX and increment it by 1. Use DAA to decimal adjusts the count value. 7. If the contents of AL is zero, then terminate the program else repeat steps 3 to 6 till AL becomes zero 8. Terminate the program. ------------------------------------------------------------------------------------------------------------------------Program: .MODEL SMALL .CODE MOV AX,0 NN: PUSH AX CALL SETC ; to set the cursor position CALL DISP ; to display the number CALL DELAY ; delay between numbers MOV AH,01 INT 16H ; check the input buffer to see if any key pressed JNZ EXIT POP AX ADD AL,1 DAA CMP AL,0 JNZ NN EXIT: MOV AH,4CH INT 21H SETC: MOV AH,2 MOV DH,12 MOV DL,35 INT 10H Dept.of CSE, DSCE,Bangalore page 37

Microprocessor Lab Manual RET DISP: MOV BL,AL MOV DL,AL MOV CL,4 SHR DL,CL ADD DL,30H MOV AH,2 INT 21H MOV DL,BL AND DL,0FH ADD DL,30H INT 21H RET DELAY: MOV SI,0FFFH B2: MOV DI,0FFFFH B1: DEC DI JNZ B1 DEC SI JNZ B2 RET END ======================================================================= Output: 99 ======================================================================= Viva Questions: 1. What is the reset address of 8086? 2. What is the size of flag register in 8086? Explain all. 3. What is the difference between 08H and 01H functions of INT 21H? 4. Which is faster- Reading word size data whose starting address is at even or at odd address of memory in 8086? 5. Which are the default segment base: offset pairs?

Dept.of CSE, DSCE,Bangalore

page 38

Microprocessor Lab Manual 14a. Read a pair of input co-ordinates in BCD and move the cursor to the specified location on the screen . ======================================================================= Objective: The objective of the program is to read an input BCD co-ordinate value from the standard input device and locate the cursor the co-ordinate value specified by the user. ======================================================================= Outcome: The user will understand the allocation of standard output device and also will learn how to control the display of any data in the location on the standard output device. This can be demonstrated by giving different BCD values at the input. ======================================================================= Algorithm: 1: Read Row and Column using the read procedure 2: Store the values in Row and Column locations from AH and AL registers respectively 3: Set the cursor position to the point given by Row and Column locations using INT 10H by setting BH and BL registers to Row and Column values respectively. 4: The cursor is now at the position (row, column) specified. 5: Take any character input to exit and return back to dos prompt 6: End the program ======================================================================= Program .MODEL SMALL .DATA MSG1 DB 10,13,"ENTER ROW NO:$" MSG2 DB 10,13,"ENTER COL NO:$" MSG3 DB 10,13,"PRESS ANY KEY TO STOP$" ROW DB ? COL DB ? .CODE MOV AX,@DATA MOV DS,AX LEA DX,MSG1 MOV AH,9 INT 21H CALL READ ; read the input row MOV ROW,AL LEA DX,MSG2 MOV AH,9 INT 21H CALL READ ; read the input col MOV COL,AL LEA DX,MSG3 MOV AH,9 INT 21H MOV AH,2 ; move the cursor to the entered row and col Dept.of CSE, DSCE,Bangalore page 39

Microprocessor Lab Manual MOV DH,ROW MOV DL,COL INT 10H MOV AH,8 ; wait for a key to be pressed to exit INT 21H MOV AH,4CH INT 21H READ:MOV AH,1 ; to read the input of two numbers INT 21H ; and store its equivalent decimal number in al AND AL, 0FH MOV BL,AL MOV AH,1 INT 21H AND AL,0FH MOV AH,BL AAD RET END ======================================================================= Output: ENTER ROW NO: 12 ENTER COL NO: 35 PRESS ANY KEY TO STOP ======================================================================= Viva Questions: 1. Can we use SP as offset address holder with CS? 2. Which are the base registers in 8086? 3. Which is the index registers in 8086? 4. What is segment override prefix? 5. Whether micro reduces memory requirements?

15a. Program to create a file (input file) and to delete an existing file. ------------------------------------------------------------------------------------------------------------------------Objective: Dept.of CSE, DSCE,Bangalore page 40

Microprocessor Lab Manual The objective of this program is to create an input file using DOS interrupts and also to delete an existing file using DOS interrupts. ------------------------------------------------------------------------------------------------------------------------Outcome: The user will come to know the usage of DOS interrupts and 8086 assembly language programming to create a file and to delete the existing file. The name of the file to be created and deleted to be entered by the user during execution of the program. If the file to be deleted is not found in the current directory an error message will appear at the user prompt. ------------------------------------------------------------------------------------------------------------------------Algorithm: 1. Display the message if the user wants to create or delete a file. Read in the input. 2. If the input is 1, execute the instruction to create a file. 3. If the input is 0, execute the instruction to delete a file 4. Any other input is given, display error message. 5. If the input choice is 1, create file module is executed. In this module file to be created is read from Read function. After reading file is created using instructions for create file operation. Program terminates 6. If the input choice is 0, then delete file module is called. File name to be deleted is read using Read module. Then deleted using delete file instructions. Program terminates. 7. While creating and deleting any error occurs, the error message is displayed 8.End the program ------------------------------------------------------------------------------------------------------------------------Program .MODEL SMALL .DATA MSG1 DB 10,13,"ENTER FILE NAME TO BE CREATED:$" MSG2 DB 10,13,"ENTER FILE NAME TO BE DELETED:$" MSG3 DB "1:CREATE",10,13,"0:DELETE$" MSG4 DB 10,13,"ENTER YOUR CHOICE:$" MSG5 DB "ERROR$" F_NAME DB 80 DUP(0) .CODE MOV AX,@DATA MOV DS,AX LEA DX,MSG3 MOV AH,9 INT 21H LEA DX,MSG4 MOV AH,9 INT 21H MOV AH,1 INT 21H CMP AL,'1' JZ C_FILE CMP AL,'0' Dept.of CSE, DSCE,Bangalore page 41

Microprocessor Lab Manual JZ D_FILE ERROR:LEA DX,MSG5 MOV AH,9 INT 21H MOV AH,4CH INT 21H C_FILE: LEA DX,MSG1 MOV AH,9 INT 21H CALL READ MOV CX,0 MOV AH,3CH ; func(3CH),to create a file with the name loaded in DX LEA DX,F_NAME INT 21H JC ERROR ; carry flag is set if error during creation MOV AH,4CH INT 21H D_FILE:LEA DX,MSG2 MOV AH,9 INT 21H CALL READ LEA DX,F_NAME MOV AH,41H ; func(41h), deletes a file with the name loaded in DX INT 21H JC ERROR MOV AH,4CH INT 21H READ:MOV AH,1 ; to store the name of the file LEA SI, F_NAME BAK:INT 21H CMP AL,0DH JZ DONE MOV[SI],AL INC SI JMP BAK DONE:RET END ======================================================================= Output: 1:CREATE 0:DELETE ENTER YOUR CHOICE:1 ENTER FILE NAME TO BE CREATED: Ravi.asm ====================================================================== Viva Questions:

Dept.of CSE, DSCE,Bangalore

page 42

Microprocessor Lab Manual 1. Can we use SP as offset address holder with CS? 2. Which are the base registers in 8086? 3. Which is the index registers in 8086? 4. What is segment override prefix? 5. Whether micro reduces memory requirements?

HARDWARE PROGRAMS
Dept.of CSE, DSCE,Bangalore page 43

Microprocessor Lab Manual

Introduction to 8086 hardware programs.


In the previous section we have seen the usage of 8086 instructions for the execution of simple programs. The strength of 8086 processor lies in its ability to communicate with the real world entities. So it finds various applications in the real world like control of logic controller, open and closing of the door, elevator control etc. This is done by interfacing 8086 processor with the real world entities through some interfacing devices. These devices help processor to take the data from the real world and also control the operation of real world entities based upon the output of 8086 processor. The most commonly used interface is 8255 programmable peripheral interface. The reader is expected to know the architecture and the command format of the 8255 before going ahead with this section. Reader can refer to the user manual given by the respective manufacturer to get the details of the port numbers to be used for different mode of operation. In this section we will demonstrate few example programs using interfacing devices.

Dept.of CSE, DSCE,Bangalore

page 44

Microprocessor Lab Manual 1b. Read the status of eight input bits from the logic controller Interface and display FF it is even parity bits otherwise display 00.Also display number of 1s in the input data. ======================================================================= Objective: Reading the inputs from the external device like Logic controller and counting number of 1s in the inputted data. ======================================================================= Outcome: User will come to know the usage of 8255 to interact with external devices. ======================================================================= Algorithm: 1. Declare assembler directives 2. Initialize the control word register 3. Store 82h in CWR to enable port B as input and port A as output 4. Port B is initialized as input port and input 1s moved to AL 5. Initialize the counter value 8 in CL register 6. Initialize the AH with 0,to store the number of 1s in the applied input 7. Rotate right the given input by 1 position 8. If CF=1,increment the value of AH and decrement the count value in cl 9. Repeat step 7 and 8 till cl=0 10. If CF=0,decrement cl and repeat step 7 until CL=0 11. To check the even parity mov the contents of AH to AL and AND it with 1 12. If AL=0,display 0 for odd parity 13. If AL=1, display OFFH for even parity 14. After the execution of delay of certain amount time display the no. of 1s 15. Terminate the program ======================================================================= Program .MODEL SMALL .CODE MOV DX,0E403H ; to set the control word register MOV AL,82H ; 82h- port A o/p and port B i/p OUT DX,AL MOV DX,0E401H IN AL,DX MOV CL,8 ; CL- stores the no. of bits MOV AH,0 N2:ROR AL,01 ; if the bit in CF is 1 increment no. of 1s JC N1 DEC CL JNZ N2 ; else find the next bit JMP NXT N1:INC AH DEC CL JNZ N2 NXT:MOV AL,AH ; to check if the no. of 1s is even or odd AND AL,1 CMP AL,0 Dept.of CSE, DSCE,Bangalore page 45

Microprocessor Lab Manual JZ DFF ; if even display FF MOV AL,0 JMP NEXT ; else display 00 DFF:MOV AL,0FFH NEXT :MOV DX,0E400H OUT DX,AL MOV SI,4FFFH ; delay to see clear o/p RET2:MOV DI,0FFFFH RET1:DEC DI JNZ RET1 DEC SI JNZ RET2 MOV AL,AH MOV DX,0E400H OUT DX,AL MOV AH,4CH INT 21H END ======================================================================= Output: Logic controller will give the result either by glowing all LEDs or no LED being turned on depending on the whether the input byte is odd parity or even parity.. Also the count of number of ones is being indicated by LEDs ======================================================================= Viva questions: 1. How many TTL inputs and TTL outputs are there in the logic controller? 2. What are the various interrupts in 8086? 3. What are software interrupts and hardware interrupts?? 4. What is meant by Maskable interrupts? 5. What is Non-Maskable interrupts?

Dept.of CSE, DSCE,Bangalore

page 46

Microprocessor Lab Manual 2b. Perform the following function using logic control Interface i. BCD up-down count ======================================================================= Objective: Performing the counter operations ======================================================================= Outcome: The user will learn to implement the counters using logic controller interface. ======================================================================= Algorithm: 1: Start 2: Initialize the control word register 3: Store 80h in CWR to enable port A as output 4: AL is initialized to 0 5: To perform up counter, the contents of AL is displayed and a delay of certain time is executed 6: The contents of AL is added with 1 and converted to BCD using DAA 7: The contents of AX is pushed onto the stack and checked for keyboard buffer for any key pressed, if any, terminate the program otherwise pop contents of AX 8: Now compare contents of AL with 99, if not equal repeat steps 4,5,6 9: If AL=99, perform down counter 10: The contents of AL is displayed and a delay of certain time is executed 11: The contents of AL is added with 99 and converted to BCD using DAA 12: Repeat step6 13: Now compare the contents of AL with 99, If not equal repeat 9,10,11 14: On AL=99 Terminate the program ======================================================================= Program: .MODEL SMALL .CODE MOV DX,0E403H MOV AL,80H ; 80H- all ports o/p OUT DX,AL MOV AL,0 MOV DX,0E400H UP:OUT DX,AL CALL DELAY ADD AL,1 DAA ; convert hex no. to BCD CALL STOP CMP AL,99H JNE UP ; if no. < 99H increment and display DOWN:OUT DX,AL ;else decrement and display CALL DELAY ADD AL,99H DAA CALL STOP CMP AL,99H Dept.of CSE, DSCE,Bangalore page 47

Microprocessor Lab Manual JNE DOWN STOP:PUSH AX MOV AH,1 INT 16H JNE EXIT POP AX RET EXIT:MOV AH,4CH INT 21H DELAY:MOV SI,2FFFH RET2:MOV DI,0FFFFH RET1:DEC DI JNZ RET1 DEC SI JNZ RET2 RET END ======================================================================= ii. Ring counter. ======================================================================= Algorithm: 1: Start 2: Initialize the control word register 3: Store 80h in cwr to enable port A as output 4: AL is initialized to 1 5: The contents of AL is displayed at output port A and a delay of certain time is executed 6: The contents of AX is pushed onto the stack and checked for keyboard buffer for any key pressed, if any, terminate the program otherwise pop contents of AX 7: Rotate the contents of AL by 1 bit to left 8: Go to step 4 9: Terminate the program ======================================================================= Program: .MODEL SMALL .CODE MOV DX, 0E403H MOV AL, 80H OUT DX, AL MOV DX, 0E400H MOV AL, 1 BAK:OUT DX,AL CALL DELAY CALL STOP ROL AL,1 JMP BAK DELAY:MOV SI,05FFF Dept.of CSE, DSCE,Bangalore page 48

Microprocessor Lab Manual RET2:MOV DI,0FFFFH RET1:DEC DI JNZ RET1 DEC SI JNZ RET2 RET STOP:PUSH AX MOV AH,1 INT 16H JNZ XIT POP AX RET XIT: MOV AH,4CH INT 21H END ======================================================================= Output The counter outputs are seen by the periodic on and off of the LEDs. ======================================================================= Viva questions: 1. Give examples for Maskable interrupts. 2. Give example for Non-Maskable interrupts. 3. What is 8255? 4. Give the internal architecture of 8255. 5. How many ports are there in 8255. 6. What is CWR?

Dept.of CSE, DSCE,Bangalore

page 49

Microprocessor Lab Manual 3b. Read the status of two 8-bits inputs(X & Y) from the Logic Controller Interface and display X*Y. ======================================================================= Objective: The user will learn to read the input from external device and to perform the product of these two numbers. ======================================================================= Outcome: The user will learn to operate on the input data taken from the external devices and to transfer the result to the same external device using 8255. ======================================================================= Algorithm: 1: Start 2: Initialize the control word register 3: Store 82H in CWR to enable port A as output and port B as input 4: Enter the 1st operand and display it similarly enter the 2nd operand and display it 5: Multiply two operands 6: Display the product at port A 9: Give certain amount of time delay 10: The contents of AH is moved to AL and display the product at port A if the product is more than 8 bits 11: Terminate the program ======================================================================= Program: .MODEL SMALL .CODE MOV DX,0E403H MOV AL,82H OUT DX,AL MOV DX,0E401H ; take input of X(first no.) from keyboard IN AL,DX MOV BL,AL MOV AH,8 ; wait for a keyboard i/p INT 21H MOV DX,0E401H IN AL,DX ; take input of Y(first no.) from keyboard MUL BL ; multiply the nos. (X*Y) MOV DX,0E400H OUT DX,AL ; display the resultant CALL DELAY MOV AL,AH OUT DX,AL MOV AH,4CH INT 21H DELAY:MOV SI,05FFFH RET2:MOV DI,0FFFFH Dept.of CSE, DSCE,Bangalore page 50

Microprocessor Lab Manual RET1:DEC DI JNZ RET1 DEC SI JNZ RET2 RET END ====================================================================== Result: The product of the two input numbers entered using the logical controller will be displayed by the glowing of LED ======================================================================= Viva questions: 1. What is the action of the IN instruction? 2. What is the action of OUT instruction? 3. Are there any other instructions which can take data from external devices apart from IN, OUT instruction? 4. What do you mean by interrupt service routines?

Dept.of CSE, DSCE,Bangalore

page 51

Microprocessor Lab Manual 4b.Display messages FIRE and HELP alternatively with flickering effects on a 7-segment Display interface for a suitable period of time .Ensure a flashing rate that makes it easy to read both the message(Examiner does not specify these delay values nor it is necessary for the student to compute these values). ======================================================================= Objective: The objective of this program is to display two strings FIRE and HELP using the 7 segment LED display with a suitable delay between display of each string. ======================================================================= Outcome: The user will learn to interface the 7 segment LED interface module with the 8086 processor using 8255 PPI. Also the user will learn to give the input for 7-segment display to display the alpha numeric data. ======================================================================= Algorithm: 1: Start 2: Initialize the control word register 3: Store the 2 messages (ie characters of message) in Data Segment in reverse fashion 4: Assign pointer to the last character of the first message to be displayed 5: Display the character pointed by the pointer and give a trigger pulse for the character to be moved to next LED. Give some delay 6: Increment the pointer. Perform Step5 until all characters of first message is displayed 7: Assign the pointer to point to the second message. Perform Step 5 and Step 6 8: Terminate the program ======================================================================= Program: .MODEL SMALL .DATA DATA1 DB 86H,0AFH,0CFH,8EH ; seven-segment code for E,r,I,F respectively DATA2 DB 8CH,0C7H,86h,89H ; seven-segment code for P,L,E,H respectively .CODE MOV AX,@DATA MOV DS,AX MOV DX,0E403H MOV AL,80H OUT DX,AL BAK: LEA SI,DATA1 ;load the effective address of erif CALL DISPLAY ;display FIrE CALL DELAY ;delay to have flickering effect LEA SI,DATA2 ;load the effective address of PLEH CALL DISPLAY ;display HELP CALL DELAY ;delay to have flickering effect MOV AH,1 ;check for keystroke to stop display INT 16h JZ BAK MOV AH,4CH Dept.of CSE, DSCE,Bangalore page 52

Microprocessor Lab Manual INT 21H DISPLAY: MOV CX,04 ;CL- no. of letters to be displayed BAK2: MOV BL,08 ;BL- no. of segment in each LED MOV AL,[SI] NEXT: ROL AL,01 MOV DX,0E401H ;each segment is outputted at a time OUT DX,AL PUSH AX MOV DX,0E402H ;port C to generate a serial clock pulse MOV AL,0FFH OUT DX,AL MOV AL,00 OUT DX,AL DEC BL POP AX JNZ NEXT INC SI LOOP BAK2 RET DELAY: MOV SI,2FFFH REP2: MOV DI,0FFFFH REP1: DEC DI JNZ REP1 DEC SI JNZ REP2 RET END ======================================================================= Result: The strings FIRE and HELP will be displayed in blinking fashion with an appropriate delay between each display so that the output can be read easily. ======================================================================= Viva Questions: 1. How many types of LED seven segment displays are available and what are they? 2. Which seven segment LED we are using in the lab? 3. Can we display all alphabets in seven segment display?

Dept.of CSE, DSCE,Bangalore

page 53

Microprocessor Lab Manual

5b.Assume any suitable message of 12 characters length and display it in the rolling fashion on a 7-segment display. Interface for suitable period of time. Ensure a flashing rate that makes it easy to read both messages.(Examiner does not specify these delay values nor it is necessary for the student to compute these values). ======================================================================= Objective: The objective of this program is to display a message of 12 characters in clockwise and anticlockwise rolling fashion. ======================================================================= Outcome: The user will learn the usage of 7 segment LED display to display the series of strings. ======================================================================= Algorithm: 1. Get the seven segment display codes for the given message. 2. Initialize the CWR with the suitable control word. 3. Get the length of the message and load CX with this value. 4. Load the first character of the message and call display subroutine. 5. In display sub routine, we will enable one segment at a time using ROL instruction. And then display first character. 6. Now call some delay and then repeat above step till all characters are displayed. ======================================================================= Program .MODEL SMALL .DATA LIST DB 0C7H,0A3H,0A7H,88H,0A1H,0ABH,088H,0ABH,088H,099H,088H,0A1H ; list seven-segment code for L,o,C,A,D,n,A,n,A,Y,A,D respectively .CODE MOV AX,@DATA MOV DS,AX MOV AL,80H MOV DX,0E403H OUT DX,AL RPT:MOV CX,12 ;CX-no. of characters to be displayed LEA SI,LIST NC: MOV AL,[SI] CALL DISP ;Display each character CALL DELAY ;give a delay to display in rolling fashion CALL STOP ;check for keyboard stroke to stop INC SI ;else display next char LOOP NC JMP RPT STOP:MOV AH,1 INT 16H Dept.of CSE, DSCE,Bangalore page 54

Microprocessor Lab Manual JNZ EXIT RET EXIT: MOV AH,4CH INT 21H DISP: MOV BL,08 NBIT: ROL AL,1 MOV DX,0E401H OUT DX,AL PUSH AX MOV DX,0E402H MOV AL,0FFH OUT DX,AL MOV AL,00H OUT DX,AL POP AX DEC BL JNZ NBIT RET DELAY: PUSH SI MOV SI,04FFFH RET2: MOV DI,0FFFFH RET1: DEC DI JNZ RET1 DEC SI JNZ RET2 POP SI RET END ===================================================================== == Output: The given text twill be displayed in the rolling fashion with a suitable delay between each display. ======================================================================= Viva Questions : 1. What is DMA?? 2. How can we change the rotation direction in the above program.

6b.Convert a 16-bit binary value (assume to be an unsigned integer) to BCD and display it from left to right and right to left for specified number of times on a 7-segment display interface. Dept.of CSE, DSCE,Bangalore page 55

Microprocessor Lab Manual ======================================================================= Objective: Objective of this program is to convert 16 bit binary input to BCD and display the same from left to right and right to left for the specified number of times ======================================================================= Outcome: The input binary number will be converted to its BCD equivalent and the user will lean how to program the processor to make the BCD value to display right to left and left to right. ======================================================================= Algorithm: 1. Store the binary values of all the LCD segments values of all the digits in data segment. 2. Load the CWR contents into the respective ports. 3. take the input from the input port referring to the control word register. 4. Store the input values as separate digits in the array BCD and then assign a pointer to this array. 5. Assign another pointer to the starting location of the array where the values of the digits 0 to 9 are stored. 6. Maximum for any 16bit binary value we need 5 decimal places in the BCD array. 7. convert the digits in BCD array to its equivalent code stored in TABLE. 8. similarly store codes for all digits separately. 9. along with Blank places, these codes are displayed separately with some delay between two codes. 10. Above step is repeated twice to display from left to right and right to left. 11. Terminate the program. ======================================================================= .MODEL SMALL .DATA LIST DB 0FFH,0FFH,0FFH,0FFH,?,?,?,?,?,0FFH,0FFH,0FFH,0FFH ;to store BCD equivalent 7-segment code in place of ?,?,?,?,? TABLE DB 0C0H,0F9H,0A4H,0B0H,99H,92H,82H,0F8H,80H,98H ;7-segment code from 0 to 9 BCD DB 5 DUP (?) ;to store converted BCD no. NUM DW 0FH ;binary no. to be converted .CODE MOV AX,@DATA MOV DS,AX MOV AL,80H MOV DX,0E403H OUT DX,AL LEA SI,BCD MOV AX, NUM ;to convert 16-bit binary no. to BCD MOV BX,10000 ;divide the no. by multiples of 10 and CALL CONV ;store each no. in BCD array to get BCD no. MOV BX,1000 CALL CONV MOV BX,100 Dept.of CSE, DSCE,Bangalore page 56

Microprocessor Lab Manual CALL CONV MOV BX,10 CALL CONV MOV [SI],DL LEA SI,BCD LEA DI,LIST+8 LEA BX,TABLE MOV CX,5 NEXT: MOV AL,[SI] XLAT MOV [DI],AL DEC DI INC SI LOOP NEXT JMP START CONV: MOV DX,0 DIV BX MOV [SI],AL MOV AX,DX INC SI RET START: MOV BH,10 LEA DI,LIST BAK1: MOV SI,DI PUSH BX CALL DISP CALL DELAY CALL STOP POP BX INC DI DEC BH JNZ BAK1 MOV BH,9 LEA DI,LIST+8 BAK2:MOV SI,DI PUSH BX CALL DISP CALL DELAY CALL STOP POP BX DEC DI DEC BH JNZ BAK2 JMP START STOP: MOV AH,1 INT 16H Dept.of CSE, DSCE,Bangalore

;CX= no. of BCD digits ;copy the equivalent 7-segment to the LIST

page 57

Microprocessor Lab Manual JNZ EXIT RET EXIT: MOV AH,4CH INT 21H DISP: MOV CX,4 NC: MOV BL,08 MOV AL,[SI] NB: ROL AL,1 MOV DX,0E401H OUT DX,AL PUSH AX MOV DX,0E402H MOV AL,0FFH OUT DX,AL MOV AL,00H OUT DX,AL POP AX DEC BL JNZ NB INC SI LOOP NC RET DELAY:MOV BX,02FFFH RET2: MOV CX,0FFFFH RET1: LOOP RET1 DEC BX JNZ RET2 RET END ========================================================================= Output: The given binary number is converted to BDC number and it is displayed from left to right and right to left. Viva questions: 1. What is BCD number? 2. How to convert HEX to BCD? 3. What is the difference between DAA and AAA instructions??

7b.Drive a stepper motor interface to rotate the motor in clock wise direction by N steps.(N is specified by the examiner).Introduce a delay between successive steps.(Any arbitrary value for the may be assumed by the student). ======================================================================= Objective:

Dept.of CSE, DSCE,Bangalore

page 58

Microprocessor Lab Manual The objective of the program is interface the stepper motor with 8086 and make it rotate clockwise direction. ======================================================================= Outcome: The user can control the speed of the stepper motor by varying the delay between successive steps. Hence user can control the operation of the stepper motor. ======================================================================= Algorithm: 1. Store the number of steps for rotation of the rotor in CX. 2. Store the CWR contents into its respective port. 3. Store the address of the output ports in AL register. 4. Store 88H in AL and Output 88H( initial value for energizing the rotor of the motor) to the output port . 5. Give some delay before next rotation and rotate the content of AL once to the right and give this modified value to output port. 6. Now motor rotates clockwise by one step. Decrement CX by one 7. perform steps 5 and 6 till CX becomes zero. 8. terminate the program. ======================================================================= Program: .MODEL SMALL .CODE MOV CX,30 ;CX-no. of steps MOV DX,0E403H MOV AL,80H OUT DX,AL MOV DX,0E400H MOV AL,88H ;to energize the north pole and south pole of the motor REP1:OUT DX,AL ;10 00 10 00 A & C poles are energized i.e, 10 CALL DELAY ;B & D are not energized ROR AL,1 ; gives clockwise motion DEC CX JNZ REP1 MOV AH,4CH INT 21H DELAY:MOV SI,2FFFH BACK2:MOV DI,0FFFFH BACK1:DEC DI JNZ BACK1 DEC SI JNZ BACK2 RET END ======================================================================= Output: The stepper motor is seen rotating in clockwise direction for the steps specified by the user. Dept.of CSE, DSCE,Bangalore page 59

Microprocessor Lab Manual ======================================================================= Viva Questions 1. What is stepper motor? 2. How does the stepper motor rotation take place?

Dept.of CSE, DSCE,Bangalore

page 60

Microprocessor Lab Manual 8b. Drive a stepper motor interface to rotate the motor in Anti-clockwise direction by N steps.(N is specified by the examiner). Introduce suitable delay between successive steps.(Any arbitrary value for the delay may be assumed by the student). ======================================================================= Objective: The objective of the program is to drive the stepper motor and also make it rotate in anticlockwise manner. ======================================================================= Outcome: The student will learn the working of stepper motor and the methods to control the stepper motor. ======================================================================= Algorithm: 1. Store the number of steps for rotation of the rotor in CX. 2. Store the CWR contents into its respective port. 3. Store the address of the output ports in AL register. 4. Store 88H in AL and Output 88H( initial value for energizing the rotor of the motor) to the output port . 5. Give some delay before next rotation and rotate the content of AL once to the left and give this modified value to output port. 6. Now motor rotates in anti clockwise direction by one step. Decrement CX by one 7. Perform steps 5 and 6 till CX becomes zero. 8. terminate the program ======================================================================= Program: .MODEL SMALL .CODE MOV CX,20 MOV DX,0E403H MOV AL,80H OUT DX,AL MOV DX,0E400H MOV AL,88H REP1:OUT DX,AL CALL DELAY ROL AL,1 ; gives anti-clockwise motion DEC CX JNZ REP1 MOV AH,4CH INT 21H DELAY:MOV SI,2FFFH BACK2:MOV DI,0FFFFH BACK1:DEC DI JNZ BACK1 DEC SI JNZ BACK2 Dept.of CSE, DSCE,Bangalore page 61

Microprocessor Lab Manual RET END ======================================================================= Result: The stepper motor is found rotating in the anti-clockwise direction with a suitable delay between each steps. ======================================================================= Viva questions: 1. Give the applications of stepper motor. 2. What is the step angle rotated by the motor for every step.

Dept.of CSE, DSCE,Bangalore

page 62

Microprocessor Lab Manual 9b.Drive a stepper motor interface to rotate the motor by N steps left direction and N steps right direction (N is specified by the examiner).Introduce a suitable delay between successive steps.(Any arbitrary value for the delay may be assumed by the student). ======================================================================= Objective: Objective of the program is to make stepper motor to rotate both clockwise and anticlockwise manner by N number of steps. ======================================================================= Outcome: The user can see the stepper motor rotating both clockwise and anticlockwise manner. ======================================================================= Algorithm: 1. Store the number of steps the rotor has to rotate in the clockwise direction in CX. 2. Store the CWR value to the respective port address. 3. Store the address of the output port in DX 4. Output the initial value for the rotor say 88H and also store this in AL. 5. Give some delay before energizing the motor again. Meanwhile rotate the contents of AL register once and give this modified value to the output port and then to rotor. 6. This will make rotor to rotate clockwise by one step. Now decrement the counter CX by one. 7. Perform steps 5 and 6 until the register CX becomes zero. 8. Now again load CX with the number of steps it has to go through in the anti clockwise direction. 9. Perform steps 4 to 7 but AL contents to be rotated left by one every time to ensure the anticlockwise rotation. 10. Terminate the program when CX becomes zero. ======================================================================= Program: .MODEL SMALL .CODE MOV CX,30 MOV DX,0E403H MOV AL,80H OUT DX,AL MOV DX,0E400H MOV AL,88H REP1:OUT DX,AL CALL DELAY ROR AL,1 ; gives clockwise motion DEC CX JNZ REP1 MOV CX,30 REP2:OUT DX,AL CALL DELAY ROL AL,1 ; gives anti-clockwise motion DEC CX JNZ REP2 Dept.of CSE, DSCE,Bangalore page 63

Microprocessor Lab Manual MOV AH,4CH INT 21H DELAY: MOV SI,0FFFH BACK2: MOV DI,0FFFFH BACK1: DEC DI JNZ BACK1 DEC SI JNZ BACK2 RET END ======================================================================= Result: The clockwise and the counterclockwise rotation of the stepper motor is verified. ======================================================================= Viva questions: 1.

Dept.of CSE, DSCE,Bangalore

page 64

Microprocessor Lab Manual 10b.Scan 8x3 keypad for keypad closure and to store the code of the key pressed in a memory location or display it on the screen. Also display row and column numbers of the key pressed. ======================================================================= Objective: The objective of the program is to check the keyboard interface module to see whether any key is pressed. If key is pressed, that keys row and column will be scanned and it will be displayed on the display devices. ======================================================================= Outcome: The user will understand the keyboard interface device configuration by giving out different keys as input for each execution of the program. ======================================================================= Algorithm: 1. Declare all 24 characters in an array where each character corresponds to the key in the keyboard interface. These keys include 0-9 integers and alphabets A to N. 2. Move 90H, the control word to the CWR which makes port A as input port and port C as output port. 3. Start scanning process by activating PC0 line. 4. Get the input from the interface using port B and compare it with 00H to check whether any key is pressed or not. If no go to second row. 5. If any key is pressed in the first row, find out in which column the key is pressed by successive rotation of contents of AL. By adding 30H convert row and column numbers to ACII values. 6. The above procedure is repeated for 2nd row and third row of the keyboard matrix when no key is pressed in first row. This is done by activating PC1 and PC2 lines respectively and repeat the step 5. 7. Display the row and column number of the key being pressed. 8. Terminate the program ======================================================================= Program: .MODEL SMALL .DATA KEYS DB '0123456789ABCDEFGHIJKLMN' ;array for 24 keys of keypad KEY DB ? MSG1 DB 10,13, 'THE ROW NO IS =' ROW DB ?,13,10,'$' MSG2 DB 'THE COL NO IS =' COL DB ?,'$' .CODE MOV AX,@DATA MOV DS,AX MOV DX,0E403H MOV AL,90H OUT DX,AL Dept.of CSE, DSCE,Bangalore page 65

Microprocessor Lab Manual REP1:MOV DX,0E402H MOV AL,01 OUT DX,AL MOV DX,0E400H IN AL,DX CMP AL,00 JNZ FR MOV DX,0E402H MOV AL,02 OUT DX,AL MOV DX,0E400H IN AL,DX CMP AL,00 JNZ SR MOV DX,0E402H MOV AL,04 OUT DX,AL MOV DX,0E400H IN AL,DX CMP AL,00 JNZ TR JMP REP1 FR:CALL DELAY LEA SI,KEYS MOV ROW,31H MOV CL,30H NEXT1: INC CL SHR AL,1 JC DISP INC SI JMP NEXT1 SR: CALL DELAY LEA SI,KEYS ADD SI,08 MOV ROW,32H MOV CL,30H NEXT2: INC CL SHR AL,1 JC DISP INC SI JMP NEXT2 TR: CALL DELAY LEA SI,KEYS ADD SI,10H MOV ROW,33H MOV CL,30H Dept.of CSE, DSCE,Bangalore ;to activate pc0 ie, to check row1 ;take input using port B ;if key pressed in row1 ;jump to first row ;else activate pc1 ie, to check row2 ;take input using port B ;if key pressed in row2 ;jump to second row ; else activate pc2 ie, to check row3 ;take input using port B ;if key pressed in row3 ;jump to third row ;repeat the check till any key is pressed ;31=ascii value for 1 ie, first row ;cl=column value ;check for the pressed key which will be 1

;second row starts from 8th key ;32=ascii value for 2 ie, second row

;second row starts from 16th key ;33=ascii value for 3 ie, third row

page 66

Microprocessor Lab Manual NEXT3:INC CL SHR AL,1 JC DISP INC SI JMP NEXT3 DISP: MOV DL,[SI] ;to display the key pressed MOV AH,02H INT 21H LEA DX,MSG1 ;to display the row no. MOV AH,09H INT 21H MOV COL,CL ;to display the col no. LEA DX,MSG2 INT 21H JMP EXIT DELAY: MOV SI,2FFFH BAK2: MOV DI,0FFFFH BAK1: DEC DI JNZ BAK1 DEC SI JNZ BAK2 RET EXIT: MOV AH,4CH INT 21H END ======================================================================= Result: The key pressed is displayed along with its row and column in the keyboard matrix. ======================================================================= Viva questions: 1. Which is the interfacing device to connect 8086 with 8X3 keyboard matrix? 2. Explain the logic of the program.

Dept.of CSE, DSCE,Bangalore

page 67

Microprocessor Lab Manual 11b.Scan a 3x8 keypad for key closure and simulate ADD and SUBTRACT operations as in a calculator .(Limitation: it is a single digit calculator). ======================================================================= Objective: The objective of the program is to take inputs from the keyboard matrix and to perform the addition or subtraction operations on the inputted data and to display the result. ======================================================================= Outcome: The user will learn to use the 3X8 keyboard as a calculator to perform the addition and subtraction operation. ======================================================================= Algorithm: 1. Initialize the directives. 2. Use FK array to store the expression to b e evaluated. 3. ERMSG contains the error message to be displayed in case needed. 4. Set NANS as a flag to indicate whether the answer is negative or not. 5. Define the control word as 90H and output it at CWR. 6. Display the message for prompting the user to enter the expression 7. Initialize the FK array to store the elements of the expression. 8. During the read process KEY will contain the value of the key being pressed. Copy it to FK array. 9. Check the second element of FK is whether + or to decide which operation to be done on the operands of the expression and transfer the control to respective code segment. If the element is neither + nor display the error message. 10. Compare the forth element of the array to see if it is = symbol. If not display the error message 11. If the expression is error free then execute corresponding code segment depending on whether addition or subtraction is to be done. 12. In case of addition simply add FK[1] and FK[3] and give the result 13. In case of subtraction if the result is negative, set the flag NANS to 1. 14. call the display subroutine and display the result and then terminate the program. ======================================================================= Program .MODEL SMALL .DATA FK DB 4 DUP(?) ;array to store the expression KEY DB ? ERMSG DB 10,13,"ERRORS$" EXPN DB 10,13,"ENTER EXPRESSION:$" NANS DB 0 .CODE MOV AX,@DATA MOV DS,AX MOV DX,0E403H MOV AL,90H OUT DX,AL Dept.of CSE, DSCE,Bangalore page 68

Microprocessor Lab Manual LEA DX,EXPN MOV AH,9 INT 21H MOV DI,4 LEA SI,FK BAK:CALL READ CALL DELAY MOV AL,KEY MOV [SI],AL INC SI DEC DI JNZ BAK CMP FK[1],0BH JZ ADDN CMP FK[1],0CH JZ SUBN JMP ERR MOV AH,4CH INT 21H ADDN:MOV AL,FK ADD AL,FK[2] CMP FK[3],13H JNZ ERR CALL DISP MOV AH,4CH INT 21H ERR:LEA DX,ERMSG MOV AH,9 INT 21H MOV AH,4CH INT 21H SUBN:MOV AL,FK SUB AL,FK[2] JNC POSITIVE NEG AL MOV NANS,1 POSITIVE: CMP FK[3],13H JNZ ERR CALL DISP MOV AH,4CH INT 21H READ: MOV AL,80H MOV KEY,0 MOV BL,3 NEXTROW:ROL AL,1 MOV BH,AL Dept.of CSE, DSCE,Bangalore

;expression contains 4 char, eg. 5+6= ;read the input ;store the read input in FK as expression

;compare the second char with + ;if equal jump to addition ;compare the second char with - ;if equal jump to subtraction ;if operator is neither of them jump to error ;to add FK[0] and FK[2] ;compare the third char with = ;if not equal jump to error ;display the answer ;display error

;to subtract FK[0] and FK[2] ;if the result is a positive no. jump to positive ;else find twos complement ;nans=negative answer=1, ie, true ;compare the third char with = ;display the answer

;bl=count for 3 rows ;al=01, check for row1

page 69

Microprocessor Lab Manual MOV DX,0E402H OUT DX,AL MOV CL,8 MOV DX,0E400H IN AL,DX NEXTCOL: ROR AL,1 JC KEYCODE INC KEY DEC CL JNZ NEXTCOL MOV AL,BH DEC BL JNZ NEXTROW JMP READ KEYCODE: MOV DL,KEY CMP DL,0BH JNZ NEXT MOV DL,'+' MOV AH,2 INT 21H RET NEXT:CMP DL,0CH JNZ NEXT1 MOV DL,'-' MOV AH,2 INT 21H RET NEXT1: CMP DL,13H JNZ NEXT2 MOV DL,'=' MOV AH,2 INT 21H RET NEXT2: ADD DL,30H MOV AH,2 INT 21H RET DISP: CMP NANS,1 JNZ SKIP PUSH AX MOV DL,'-' MOV AH,2 INT 21H POP AX SKIP:AAM ADD AX,3030H Dept.of CSE, DSCE,Bangalore

;to find the key pressed

;to compare if the key pressed is +

;to compare if the key pressed is -

;to compare if the key pressed is =

; else the key pressed is a digit

;if negative answer is false ie, 0 jump to skip ;else add - symbol before the no. and display

page 70

Microprocessor Lab Manual MOV BX,AX MOV AH,2 MOV DL,BH INT 21H MOV DL,BL INT 21H RET DELAY:MOV BX,2FFFH B2: MOV CX,0FFFFH B1: LOOP B1 DEC BX JNZ B2 RET END ======================================================================= Result: Given simple expression is simulated using 8X3 keyboard ======================================================================= Viva questions: Explain the working of XLAT instruction. What is debouncing of the key?

Dept.of CSE, DSCE,Bangalore

page 71

Microprocessor Lab Manual 12b.Genarate a sine wave using the DAC interface (The output of the DAC is to be displayed on a CRO). ======================================================================= Objective: The objective is to generate the sine waveform using 8086 and DAC interface module ======================================================================= Outcome: The user will learn to use the DAC to display waveforms like sine wave, cosine wave etc. ======================================================================= Algorithm: 1. Initialize assembler directives 2. declare some points which correspond to the amplitude of the sine wave in an array 3. Move 80H into CWR to enable all the ports as output ports 4. Initialize SI with a large value which indicate the number of wave cycles to be generated. 5. use port B as output port 6. move the first element of the array to AL and add 127 to it. 7. Move the first element of the array again to AL and subtract 127 from it. 8. decrement BX and repeat step 6 until BX becomes zero 9. Subtract 127 from each value of AL and increment BX until it becomes 9. 10. keep on adding 127 to each value of AL and decrement BX until it becomes zero 11. Terminate the program ===================================================================== Program: .MODEL SMALL .DATA A DB 00,22,43,63,81,97,109,119,125,127 ; points to plot .CODE MOV AX,@DATA MOV DS,AX MOV AL,80H MOV DX,0E403H OUT DX,AL MOV SI,0FFFFH ;SI-no. of sine waveforms MOV BX,0 ;BX-count no. of points MOV DX,0E401H ;port B as o/p port B1:MOV AL,A[BX] ADD AL,127 ;0-255 levels possible. Median is 127 OUT DX,AL INC BX CMP BX,9 JB B1 B2:MOV AL,A[BX] ADD AL,127 OUT DX,AL DEC BX CMP BX,0 Dept.of CSE, DSCE,Bangalore page 72

Microprocessor Lab Manual JNZ B2 B3:MOV AL,A[BX] MOV CL,127 SUB CL,AL MOV AL,CL OUT DX,AL INC BX CMP BX,9 JB B3 B4: MOV AL,A[BX] MOV CL,127 SUB CL,AL MOV AL,CL OUT DX,AL DEC BX CMP BX,0 JNZ B4 DEC SI JNZ B1 MOV AH,4CH INT 21H END ======================================================================= Result: Sine wave is generated using DAC and 8086 processor and the same is seen on the CRO ======================================================================= Viva questions: What is DAC? List out the internal components of the DAC. Explain the operation of DAC.

13b.Generate a Half Rectified Sine wave form using the DAC interface.(The output of the DAC is to display on a CRO). Dept.of CSE, DSCE,Bangalore page 73

Microprocessor Lab Manual ======================================================================= Objective: Objective is to generate the half rectified sine waveform using the DAC and 8086 processor ======================================================================= Outcome: The user will be able to generate half rectified sine wave and the same can be visualized using CRO ======================================================================= Algorithm: 1. Initialize assembler directives 2. Declare some points which correspond to the amplitude of the sine wave in an array 3. Move 80H into CWR to enable all the ports as output ports 4. Initialize SI with a large value which indicates the number of wave cycles to be generated. 5. use port A as output port 6. Move the every element of the array to AL one by one and add 127 to each of it and output through port A. Decrement BX by one. 7. Repeat above step until BX becomes zero. 8. Subtract 127 from each value of AL and output this through port A and repeat step 6 until BX becomes zero. 9. Move 14 to SI and 127 to AL. output 127 14 times to give delay between each rectified waveform. 10. Repeat steps 6 7 and 8 until SI becomes zero. 11. Terminate the program. ===================================================================== Program: .MODEL SMALL .DATA A DB 00,22,43,63,81,97,109,119,125,127 .CODE MOV AX,@DATA MOV DS,AX MOV AL,80H MOV DX,0E403H OUT DX,AL MOV CX,0FFFFH MOV BX,0 MOV DX,0E400H ;portA as o/p port B1: MOV AL,A[BX] ADD AL,127 OUT DX,AL INC BX CMP BX,9 JB B1 B2: MOV AL,A[BX] ADD AL,127 OUT DX,AL Dept.of CSE, DSCE,Bangalore page 74

Microprocessor Lab Manual DEC BX CMP BX,0 JNZ B2 MOV SI,14 RPT: MOV AL,127 ;loop for half rectified wave OUT DX,AL DEC SI JNZ RPT LOOP B1 EXIT: MOV AH,4CH INT 21H END ======================================================================= Result: The half rectified waveform is generated using DAC and 8086 and the same is seen on the CRO ======================================================================= Viva questions: What do you understand by resolution of the DAC? How to find the accuracy of the DAC?

Dept.of CSE, DSCE,Bangalore

page 75

Microprocessor Lab Manual 14b. Generate a Fully Rectified Sine wave from using the DAC interface (The output of the DAC is to be displayed on a CRO). ======================================================================= Objective: The objective is to generate fully rectified sine wave using DAC and 8086 processor ======================================================================= Outcome: The user will be able to generate full wave rectified output which can be seen on the CRO. ======================================================================= Algorithm: 1: Declare 10 points in an array up to 127 2: Move 80H in to CWR and enable all ports as output port 3: Initialize SI with large values of which indicates the number of waves to be generated 4: Use port B as output port 5: Add 127 for each value of AL and output this through port A and repeat until BX=9 6: Subtract 127 from each value of AL and output this through port A and repeat until BX=0 7: Repeat steps 5 and 6, SI number of times. 8: Terminate the program ======================================================================= Program: .MODEL SMALL .DATA A DB 00,22,43,64,82,97,110,119,125,127 .CODE MOV AX,@DATA MOV DS,AX MOV AL,80H MOV DX,0E403H OUT DX,AL MOV CX,0FFFFH ;CX-no. of waveforms MOV BX,0 MOV DX,0E401H B1:MOV AL,A[BX] ADD AL,128 OUT DX,AL INC BX CMP BX,9 JB B1 B2:MOV AL,A[BX] ADD AL,128 OUT DX,AL DEC BX CMP BX,0 JNZ B2 LOOP B1 MOV AH,4CH Dept.of CSE, DSCE,Bangalore page 76

Microprocessor Lab Manual INT 21H END ======================================================================= Result: Fully rectified waveform is observed on the CRO ======================================================================= Viva questions: 1. List out few applications of the DAC. 2. How to vary the frequency of the output sine wave??

Dept.of CSE, DSCE,Bangalore

page 77

Microprocessor Lab Manual 15b.Drive Elevator Interface in the following way: 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 some requests occur during going up or coming down they should be ignored. ======================================================================= Objective: The user will be able to control the elevator which runs from ground floor and forth floor. Whenever a request is made elevator must go to that floor and wait there for few seconds and then go to the ground floor. ======================================================================= Outcome: The user can understand the controlling operation of an elevator system by using the elevator module. ======================================================================= Algorithm: 1. Initially elevator is at the ground floor 2. When the elevator reaches any floor it stays in that floor until a request from another floor is made. 3. On request it moves to that floor. 4. The floor requests are scanned in fixed order i.e. floors 0,1, 2 and 3. 5. This will execute in the loop and by pressing ENTER key the program can be terminated. ======================================================================= Program: .MODEL SMALL .CODE MOV DX,0E403H MOV AL,82H ;port B as i/p port OUT DX,AL BAC: MOV AH,01 ;if a key is pressed from the keyboard then exit INT 16H JNE EXIT MOV AL,0 MOV DX,0E400H OUT DX,AL MOV AL,0F0H OUT DX,AL LOOP1:CALL RQCHE ;check if there is a request JZ LOOP1 ;if no request wait SHR AL,1 ;check for gnd floor JNC GND ;if equal go to gnd SHR AL,1 ;check for 1st floor JNC FF ;if equal go to FF SHR AL,1 ;check for 2nd floor JNC SF ;if equal go to 2nd floor Dept.of CSE, DSCE,Bangalore page 78

Microprocessor Lab Manual JMP TF RQCHE:MOV DX,0E401H IN AL,DX OR AL,0F0H CMP AL,0FFH RET GND:CALL DELAY CALL DELAY MOV AL,0F0H JMP BAC FF:MOV AL,0F0H MOV CL,03 CALL MUP CALL DELAY CALL DELAY MOV CL,03 CALL DOWN JMP BAC SF:MOV AL,0F0H MOV CL,06 CALL MUP CALL DELAY CALL DELAY MOV CL,06 CALL GODW JMP BAC TF:MOV AL,0F0H MOV CL,09H CALL MUP CALL DELAY CALL DELAY MOV CL,09H CALL GODW JMP BAC EXIT: MOV AH,4CH INT 21H MUP:MOV DX,0E400H UP: INC AL CALL DELAY OUT DX,AL LOOP UP RET GODW:MOV DX,0E400H DOWN:DEC AL CALL DELAY OUT DX,AL Dept.of CSE, DSCE,Bangalore ;else go to 3rd floor ;take the i/p from the interface ;compare if no key is pressed ;stay in ground floor for few secs ;clear the i/p data and jump for next request ;clear the i/p data ;cl=count for no. of LEDs,for first floor LEDs=3 ;to move upwards ;to move downwards ;go to bac for next request ;cl=count for no. of LEDs, for second floor LEDs=6

;cl=count for no. of LEDs, for third floor LED=9

;send the o/p to port A ;increment the value of AL to move up ;loop till CL=0 ;send the o/p to port A ;decrement the value of AL to come down

page 79

Microprocessor Lab Manual LOOP DOWN ;loop till CL=0 RET DELAY:MOV SI,2FFFH RPT2:MOV DI,0FFFFH RPT1:DEC DI JNZ RPT1 DEC SI JNZ RPT2 RET END ======================================================================= Result: The working of the elevator is observed. ======================================================================= Viva questions: 1. Explain the operation of elevator. 2. Explain the various modules used in the elevator interfacing module.

Dept.of CSE, DSCE,Bangalore

page 80

You might also like