Microprocessor Lab IV Sem



Comments



Description

Microprocessor Lab ManualDAYANANDA 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 1’s 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 MASM. STEPS 1.COM(Norton’s Editor).DEBUG. COMMAND IS: FILENAME.Bangalore page 5 . ensure that all the files namely NE.EXE(Linker).of CSE.ASM 4. DSCE.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.LINK. COMMAND IS: C>MASM FILENAME OR C>MASM FILENAME.ASM Dept. ENTERING A PROGRAM Before starting the process. There are a number of assemblers available like MASM.EXE(Assembler).EXE(Debugger) are available in the same directory in which we are working. COMMAND IS: C>TC OR C>NE 2.Microprocessor Lab Manual Guidelines to use the assembler. OPEN THE TEXT EDITOR. MASM reads the source program as its input and provides an object file. TASM and DOS assembler . SAVE THE PROGRAM WITH THE . ENTER THE PROGRAM AND CHECK FOR THE MISTAKES AND SYNTAX ERRORS 3.ASM EXTENSION. ASSEMBLE THE PROGRAM. The LINK accepts the object file produced by MASM as input and produces an EXE file. The assembly language programming can be done using the Assemblers. Bangalore page 6 . Quit the DEBUG and return to DOS.Microprocessor Lab Manual After successful assembling. routines to -T SEG: OFFSET Trace the program execution by single stepping Dept. Some of the DEBUG commands used are as follows: -R -D -g -q Display all registers and flags.COM.OBJ extension. DEBUG. COMMAND IS: C>LINK FILENAME. number of labels. Link the object modules of the source program and the function library generate an integrated executable code of the source program.LST extension. opcodes.of CSE. Display 128 memory locations of RAM starting from the current display pointer.EXE extension. 6. three files are created namely i) ii) The object file with . The listing file with . The listing file contains the total offset map of the source file including labels. Execute from current CS: IP. about the source program.OBJ The output of the LINK program is an executable file with the entered filename and . a DOS utility can be used for debugging and trouble-shooting . routines to be called. offset addresses. iii) The cross reference filename with . list of labels.CRF extension. memory allotment for different labels and directives and relocation information. The cross reference file is used for debugging the source program and contains the statistical information size of the file in bytes. These files are used to link the object modules and generate an executable (. 5.OBJ file.EXE) file from a . etc. of assembly language programs COMMAND IS: C>DEBUG A ‘-‘(dash) display signals the successful invoke operation of DEBUG. DSCE. 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.defines code segment .Defines Double words ( 32 bits) DUP--.of CSE. Assembler Directives indicate how an operand or section of the program is to be processed by the assembler. Most commonly used assembler directives are listed below with their meaning.extra--.Bangalore page 7 . Only CODE segment is compulsory and rest all can be used depending on the requirement.generates duplication DW – defines word (16 bits) END – ends the program ENDM – ends the macro ENDP – ends a procedure. .Defines Byte (8 bits) DD --. DSCE. This requires a logical space called as CODE SEGMENT.Defines data segment .DATA” and .code--. Similarly the program will have the space for the instructions to execute the given problem.Defines Stack segment . We can see all the programs will follow some common format. These are represented by “. Note that all these segments are not compulsory for the program. Hence the given program demands for a certain amount of logical space. The best way to begin with the programming is to analyze the given problem. Then we can understand that the program needs some inputs.small – .defines Extra segment BYTE – indicates Byte sized data DB --. In our programs we have used DATA SEGMENT and CODE SEGMENT only as other two segments are of no use in these programs.data---. These are also called as assembler directives.Microprocessor Lab Manual General form of any assembly program. Sometimes the result of the program needs to be stored in the memory. This is called as DATA SEGMENT.CODE.stack --. EQU – equates data to label Dept. Some directives generate and store information in memory while others do not. of CSE.Bangalore page 8 .Microprocessor Lab Manual SOFTWARE PROGRAMS Dept. DSCE. Subtract one from DI.CODE MOV AX. Step 2.To find mid point page 9 .LIST SKEY DB 03 MSG1 DB 'FOUND $' MSG2 DB 'NOT FOUND $' . and compare it with SKEY. Divide this by two to get the mid location of the array.01 BAK: CMP SI.5 LNTH DW $ . students will learn the implementation of the Binary search algorithm. Set a pointer SI to zero Step 4: Copy the length of the array to one more pointer DI. If the key is found a message “FOUND” will be displayed otherwise “NOT FOUND” will be displayed.Bangalore . 2. Step 5.MODEL SMALL .@DATA MOV DS. change the high value that is DI value to [mid-1] and repeat the steps 7 and 8.DATA LIST DB 1. Step10: If the key is smaller than mid-element of the array. Now BX contains the MID position of the array. Search a key element in a list of 'n' 16-bit numbers using the Binary search algorithm. Step:6 If SI is more that DI conclude that the SKEY is not there else do the following steps. ------------------------------------------------------------------------------------------------------------------------Program: . get the length of the array and store it in “LNTH” Step 3.4. If they are equal go the last stage and display the message FOUND else go to next step. change the low value that is SI value to [mid+1] and repeat the steps 6. AX MOV SI. Step 9: If the key is greater than mid-element of the array. ------------------------------------------------------------------------------------------------------------------------ALGORITHM: Step 1. This is done by SHR operation which rotates the sum to the right by one bit position.3.Microprocessor Lab Manual 1a. ------------------------------------------------------------------------------------------------------------------------Objective: In this program. define the sorted array of elements as “LIST”.SI Dept. 7 and 8. Step 8: Get the element of the location BX of the array LIST to AL. DSCE.0 MOV DI.LNTH SUB DI.of CSE.DI JA NF MOV BX. Step 7: Add SI and DI which are nothing but the start and end of the array. ------------------------------------------------------------------------------------------------------------------------Outcome: Students will learn the usage of simple assembly language instructions and also will implement binary search algorithm to find the given key. /2 MOV Al.4CH :Func(4ch). JE and JB instructions 4.Microprocessor Lab Manual ADD BX.Bangalore page 10 .DI .(low+high) SHR BX.Display String. SKEY JE YF .01 JMP BAK NF: LEA DX. else DI=mid-1 SUB DI.Shift bit to right gives no.BX .0 JZ NF JMP BAK NM: MOV SI. What is data segment? 5. LIST[BX] CMP Al.09H .If (key==[mid]) jump to found JB NM . Call DOS Service END ------------------------------------------------------------------------------------------------------------------------Output: Found ------------------------------------------------------------------------------------------------------------------------Viva Questions: 1. DSCE.SI=[mid+1] ADD SI. What is code segment? Dept.Terminate program INT 21H . 2. Explain JA.else if(key>[mid]) jump to NM MOV DI.01 .of CSE.Func(09h).01 CMP DI. Explain the logic of Binary search.MSG1 NEXT: MOV AH. Why ‘$’ symbol is to be used at the end if the string message to be displayed? 3.BX .MSG2 JMP NEXT YF: LEA DX.DX=offset of msg INT 21H MOV AH. Call the macro READ.inc) Interrupt INT 21 is called with AH having the value 01H. macro to read a character .inc INCLUDE c:\masm6. 7: After displaying all the characters terminate the program.Bangalore . This will read the ASCII value of the key being pressed and store it in AL register. (m1.. After displaying one character the control will be given to main program. Compare this with the ACII Value of ‘ENTER’ key i.e.DATA STR DB 10 DUP(?) . To call macro Read page 11 .MODEL SMALL .0 READ1: READ Dept. 6.inc) Interrupt INT 21 is called with AH having the value 02H.CODE MOV AX. After every key is read increment a counter SI. 4. The user must write the two macros first as two separate files and then they can write and execute the main program. After reading one character the control will be given to main program. Main program: Define a string of size 10 bytes with name STR to store the key elements being pressed. (m2.AX MOV SI. These two operations are done by two separate macros which are external to the main program. ------------------------------------------------------------------------------------------------------------------------Program INCLUDE c:\masm6. DSCE. The counter SI is used to ensure all characters of STR are being displayed. 5. ------------------------------------------------------------------------------------------------------------------------Algorithm: 1. This will enable the processor to write one character to the standard output device. ------------------------------------------------------------------------------------------------------------------------Objective : In this program the students will learn to input the data to the processor using standard input device that is keyboard. Write the macro for outputting the key being read from keyboard. 2. Write the macro for reading a key from keyboard. Also they will display the same on the standard output device. which reads the key from the keyboard. This will enable the processor to read one character from the keyboard. ‘0DH’ If both are matching end the read process else store the data in AL to STR array till ‘ENTER’ key is being pressed. If the ENTER key is pressed. macro to display a character .of CSE.0\bin\m1. stop the reading operation and go to DISP macro which displays one character at a time. 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.0\bin\m2.inc .Microprocessor Lab Manual 2a. ------------------------------------------------------------------------------------------------------------------------Outcome: Understanding the use of standard input and output devices also the usage of macros in the assembly language programming.@DATA MOV DS. 3. 0 MOV DL. 02H . What is a macro? 2.inc .4CH INT 21H END .0DH JE HERE MOV STR[SI]. explain loop instruction. How can you classify the instruction set of 8086? 4.Bangalore page 12 . To call Macro display m1. What do you understand by assembler directives? 3.Read char MOV AH. Can we display the string STR without using loop instruction? Dept.10 DISPLAY DISP1: MOV DL.Func(02h). ASCII value for line feed . DSCE. macro to display a character READ MACRO DISPLAY MACRO MOV AH.inc .Microprocessor Lab Manual CMP AL.SI MOV SI.AL INC SI JMP READ1 HERE: MOV CX.STR[SI] DISPLAY INC SI LOOP DISP1 MOV AH. 0dh ascii value for carriage return . 01H .Write char INT 21H INT 21H ENDM ENDM ------------------------------------------------------------------------------------------------------------------------Input: Dsce Output: Dsce ------------------------------------------------------------------------------------------------------------------------Viva Questions: 1.of CSE.Func(01h). macro to read a character m2. 5. 1. Sort a given set of 'n' numbers in ascending and descending orders using Bubble sort algorithm. DSCE. link/CO filename. ------------------------------------------------------------------------------------------------------------------------Objective: To learn the bubble sort algorithm and implement the same using 8086 assembly language. Move first element of Db to Al. For first 10 locations of array A. b. Now come to the command prompt and type “ d A” as shown in fig 3. ‘A’ gives the array elements which need to be sorted.Bangalore page 13 . Repeat this for (n-1) times and you will get the sorted array. This will take the user to a window as shown in fig 1.of CSE. Here user can see the sorted array. while compiling the code type. ------------------------------------------------------------------------------------------------------------------------Out come: Students will learn to check the data in different segments of memory and also will learn the usage of instructions like XCHG. masm/Zi filename. Initialize two counters BX and CX with values ‘n’ and ‘n-1’. ------------------------------------------------------------------------------------------------------------------------Algorithm..asm.obj. Now go to Run in the menu and select start to run the program. Comparison operation and exchange of elements. CV file name. If [Al] < A[SI] keep the elements in tact if not exchange contents of Al and A[SI]. User will be prompted with the message saying program terminated normally as shown in fig 2. Also initialize counter SI to ‘0’ 3. Execution procedure: a.Microprocessor Lab Manual 3a. Repeat this same till counter CX becomes zero. c. 2. Dept. Save the program in the folder which has CV. and compare with next element in the array. Hence we get largest element at the first iteration. d. Get the length (say ‘n’) of this array and store it in variable L. 2 the successful execution of the program Dept.of CSE.Microprocessor Lab Manual Fig 1. DSCE. Execution of the program Fig Fig.Bangalore page 14 . of CSE.Bangalore page 15 .Microprocessor Lab Manual Fig 3. DSCE. Dept. 4CH INT 21H END ------------------------------------------------------------------------------------------------------------------------Output: >d A 15 45 45 55 65 85 95 ------------------------------------------------------------------------------------------------------------------------Viva questions: Dept. @DATA MOV DS. 45H L DW $ . 65H. A[SI] INC SI CMP Al.DATA A Db 85H. 55H. DSCE.Exchange If (AL< [SI+1]) MOV A[SI-1]. AX MOV BX. 15H.of CSE.95H.Length of array .for descending order JAE NEXT XCHG Al. 45H.Bangalore page 16 . BX .Al NEXT: LOOP NI DEC BX JNZ NP MOV AH.CX=No.MODEL SMALL . of comparison in each iteration MOV SI.BX=No.Microprocessor Lab Manual .CODE MOV AX. A[SI] .25H. A[SI] JBE NEXT . of iterations DEC BX NP: MOV CX. 0 NI: MOV Al.A . L . DSCE.Bangalore .row number. the user will input any alpha numeric character and see the corresponding ASCII value on the standard output device.OFFSET MSG INT 21H ENDM SCR MACRO MOV AH.09H MOV DX.00H Dept.of CSE. ------------------------------------------------------------------------------------------------------------------------Objective: In this program. Inputted character which is stored in AL is first divided by 10. If AL is less than 10 then go ahead with the following steps. 2. INT 10 takes inputs in 3 registers DH. PRINT MSG Macro. POS Macro. 6. ------------------------------------------------------------------------------------------------------------------------Program: . 4. Read Alphanumeric Character & display its equivalent ASCII code at the centre of screen . These are achieved by various DOS interrupts with suitable values in AX register. Macro to display string MOV AH. SCR Macro – Clears the Screen when the interrupt INT21H being called with AH having the value 00H and AL having the value 03H. Defining various macros to perform specific tasks like displaying a message to the user to prompt him to enter the alpha numeric data.Macro to clear to screen . If the reminder is greater than 10 divide again by 10. ------------------------------------------------------------------------------------------------------------------------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.03H INT 10H ENDM POS MACRO MOV AH.00H MOV AL.This macro sets the cursor location using INT 10 interrupt. DL column number and BH page number( 0 -7) 5.MODEL SMALL PRINT MACRO MSG .Macro to Set the cursor page 17 . 1. Now we have each digit of the input ASCII code in AX. to clear the screen and to set the location of the screen where the ASCII value of the key pressed to be displayed.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.02H MOV BH.Microprocessor Lab Manual 4a. ------------------------------------------------------------------------------------------------------------------------Algorithm. Now add 3030H to this to adjust to the proper ASCII Value and display it. 7. 00H DIV BL ADD AX.AX SCR PRINT MSG1 MOV AH.Microprocessor Lab Manual MOV DH. ASCII equivalent code is stored in AL INT 21H MOV AH. in the centre of the screen MOV DL.Bangalore .CL INT 21H MOV AH.10D JGE L2 ADD AX.00H .DATA TMP DB ? TMP1 DB ? MSG1 DB 10. 30H Dept.display the no.0CH MOV DL. MOV BL.13. with 10 gives the decimal equivalent of hex no. 06H MOV DL.06H .3030H MOV CX.23H INT 10H ENDM .i/p of char i.AH POS MOV AH.divide the no. TMP1 ADD AH. AL INT 21H MOV AH.06H MOV DL.01H . DSCE. is stored in AX register DIV BL MOV TMP1.AH CMP AL. 06H MOV DL.AX POS MOV AH. 'Enter the alpha-numeric character:$' .3030H MOV TMP.CODE MOV AX.CH INT 21H JMP LAST L2: MOV AH.of CSE.10 .e. TMP INT 21H MOV AH.if after 1 div the no.converted no.@DATA MOV DS. is not converted divide it further page 18 . What is the necessity of adding 3030H. 02H with INT 21H? 2.of CSE.Microprocessor Lab Manual MOV TMP1.Bangalore page 19 . 06H MOV DL. What is the difference between AH. TMP1 INT 21H LAST: MOV AH. AH MOV AH.4CH INT 21H END ------------------------------------------------------------------------------------------------------------------------Output: Enter the alpha-numeric character: 7 55 Viva questions 1. DSCE. Dept. 06h and AH. 6. DSCE.To reverse the string . Copy the length of the string to CL also store [CL-1] at DI 4. Define the string to be checked whether it is palindrome or not and also get the length of the string 2.CODE MOV AX. Copy the first element of STR array to the last element of RSTR array. 7. RSTR is used to store the string after reversing it. ------------------------------------------------------------------------------------------------------------------------Algorithm: 1. 5. Point STR and RSTR using SI and DI.MODEL SMALL . To reverse the string page 20 .AX MOV ES.AX MOV CL.STACK 100 . comparing a string etc. CX register is used as counter to keep track of copying process.STR[DI] MOV RSTR[SI]. 3.@DATA MOV DS.CX INC CX BAK: MOV AH.Microprocessor Lab Manual 5a. Repeat this process till all the elements are copied. ------------------------------------------------------------------------------------------------------------------------Objective: In this program the user will learn to reverse the string and also checks whether it is a palindrome or not. .STR Dept.Bangalore . Clear the direction flag using CLD and use CMPSB to compare two strings byte by byte.AH INC SI DEC DI LOOP BAK LEA SI.N DEC CL MOV DI. ------------------------------------------------------------------------------------------------------------------------Outcome: The user will get familiar with the string operations like reversing a string. Reverse a given string and check whether it is a palindrome or not.of CSE.DATA STR DB 'MALAYALAM' N DB $-STR RSTR DB 10 DUP(0) MSG1 DB 'STRING IS PALINDROME$' MSG2 DB 'NOT PALINDROME$' . If comparison gives a positive result then display ‘ String is palindrome’ els display string is ‘not palindrome’. and user can change to any other string before executing the program) Output: STRING IS PALINDROME ------------------------------------------------------------------------------------------------------------------------Viva questions: 1. Explain CMPSB instruction 3.of CSE. What is a palindrome? 2.RSTR CLD MOV CL.N .To compare the 2 strings JE DMSG1 .MSG2 .CL=Size of string REPE CMPSB .Jump on equal to Found LEA DX. What is the function of CLD instruction? Dept.4CH INT 21H END ------------------------------------------------------------------------------------------------------------------------Input: ‘MALAYALAM’ ( This is provided in the program itself.Microprocessor Lab Manual LEA DI.Bangalore page 21 .09H INT 21H MOV AH. DSCE.MSG1 XIT: MOV AH.If not equal display not found JMP XIT DMSG1: LEA DX. To print the length of string1 M2 DB 'LENTH OF THE STR2:' L2 DB ?. 6.of CSE. ------------------------------------------------------------------------------------------------------------------------Algorithm: 1. Comparison takes place character by character. Clear the direction flag and using CMPSB instruction compare STR1 and STR2 7.DATA STR1 DB 100 .@DATA MOV DS. ------------------------------------------------------------------------------------------------------------------------.13.13.'$' .Microprocessor Lab Manual 6a. Read 2 strings.'$' . ------------------------------------------------------------------------------------------------------------------------Outcome: The user will learn to compare two strings by using this program.To store the length & the string1 DB 0 DB 100 DUP(0) STR2 DB 100 .Bangalore page 22 . 3. 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.CODE MOV AX. To store the length & the string2 DB 0 DB 100 DUP(0) M1 DB 'LENTH OF THE STR1:' L1 DB ?.AX MOV ES. Read the strings from the STD input and store the length of the strings in BL and CL also.10. 4.10. Add 3030H to convert it to BCD format to be displayed and display the length of each string. ------------------------------------------------------------------------------------------------------------------------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.AX LEA DX. Store the string1 and string2 in 3 bytes format 5. Also display the length of the stored strings .MODEL SMALL . If they are equal display ‘ Strings are equal and terminate the program else display ‘Strings are not equal’ and terminate the program. 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. STR1 Dept. DSCE. To print the length of string2 M3 DB 'STR1 IS EQUAL TO STR2$' M4 DB 'STR1 IS NOT EQUAL TO STR2$' . store them in locations STR1 and STR2 check whether they are equal or not and display appropriate messages. 30H ADD BL.Microprocessor Lab Manual MOV AH. To Print the length of string2 INT 21H CMP CL.BL SUB CL. DSCE. 10 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.STR2+2 .CL MOV L2.Read & Print string1 INT 21H MOV DL.M4 .Compare DM4:LEA DX.Load effective address of string1 LEA DI. Load effective address of string2 CLD REPE CMPSB .M2 .To Print the length of string1 MOV AH.M1 .STR1+1 .09H .Else print strings are equal MOV AH.Read & Print string2 MOV CL. BL=Length of string2 ADD CL.STR1+2 . 02H INT 21H LEA DX.Compare the length of strings JZ NEXT .Bangalore page 23 .BL .0AH .STR2+1 .Func(0AH).Print Not Equal & Exit INT 21H JMP EXIT NEXT: LEA SI.30H MOV L1. Func(0AH).CL=Length of string1 MOV BL.of CSE.30H SUB BL.If length of string1!= string2 MOV AH.If length of string1=string2.M3 .09H INT 21H EXIT:MOV AH.30H LEA DX.09H INT 21H LEA DX. If strings are not equal print not equal LEA DX.STR2 INT 21H .Compare two strings JNZ DM4 . What is pipelining in 8086? 5. What is the size of instruction queue in 8088? 3. Which are the registers present in 8086? 4. How many 16 bit registers are available in 8086? Dept.Microprocessor Lab Manual 1.Bangalore page 24 .of CSE. DSCE. What is the size of instruction queue in 8086? 2. DATA MSG DB 'WHAT IS YOUR NAME:' NEM DB 50 DUP (0) .AL INC SI CMP AL. Append ‘$’ at the end of the name. ------------------------------------------------------------------------------------------------------------------------Algorithm: 1.@DATA MOV DS. 2.0 MOV BH.End of the string .Microprocessor Lab Manual 7a.13 JNE BAK MOV BYTE PTR NEM[SI].9 INT 21H MOV AH.Procedure to clear the screen page 25 . terminate the program. Clear the screen and set the location of the cursor to print the required message along with the name.I/p a char with echo from keyboard .CODE MOV AX.Bangalore . 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.MSG MOV AH.Set the cursor to the specified location . 4.4CH INT 21H CLR:MOV AH. Read the name from the STD input device and store it in NEM array. Display the name along with the string ‘What is your name?’ 5.Move each character to the array .0 MOV AH.AX MOV SI.of CSE.MODEL SMALL . ------------------------------------------------------------------------------------------------------------------------Program: . DSCE.Func(01H).Clear the screen .Display message What is your Name? .'$' CALL CLR CALL SETC LEA DX.7 Dept.1 BAK: INT 21H MOV NEM[SI]. 3.6 MOV AL. ------------------------------------------------------------------------------------------------------------------------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. Bangalore page 26 .DH=Position of the row MOV DL.DH=Position of the row MOV DL.20 . DSCE. Functions of Accumulator or AX register? Dept.Microprocessor Lab Manual MOV CH.model small stands for? 4.12 .79 .24 .0 MOV DH.0 MOV CL.DL=Position of the col INT 10H RET END ------------------------------------------------------------------------------------------------------------------------Output: Ravi What is your name? Ravi ------------------------------------------------------------------------------------------------------------------------Viva Questions: 1.2 .0 MOV DH. What . Specify addressing modes for any instruction? 2.Procedure to set the cursor MOV BH. What are assembler directives? 3. What is the supply requirement of 8086? 5. What is the relation between 8086 processor frequency & crystal frequency? 6.of CSE. DL=Position of the col INT 10H RET SETC: MOV AH. ------------------------------------------------------------------------------------------------------------------------Objective: The user will implement the computation of factorial of the given 8 bit number using recursive procedure.NUM CMP BX. Push the contents of the BX to stack and decrement BX and call FACT recursively till BX becomes 1 6. DSCE.AX MOV AH.01 MOV BX. Compare the given number with zero and if it is equal display [AX] as factorial and terminate the program else go to next step.AX MOV AX. Compute the factorial of a positive integer 'n' using the recursive procedure. 4.00 . 7.Compare num with 01 JZ RIP PUSH BX DEC BX CALL FACT POP BX MUL BX Dept. 2. POP every pushed value of BX from the stack and multiply with [AX] and return to main program.4CH INT 21H FACT PROC NEAR . Now call FACT procedure.Bangalore page 27 .Recursive procedure to calculate Factorial CMP BX. If the number is 01 return [AX] as the result else go next step.MODEL SMALL . AX is initialized with 01 which is the least possible factorial value (0!= 1).Microprocessor Lab Manual 8a. 5.@DATA MOV DS.DATA NUM DW 5 RESULT DW ? . ------------------------------------------------------------------------------------------------------------------------Outcome: The use of procedures and concept of recursive procedure is dealt with this program. ------------------------------------------------------------------------------------------------------------------------Program: .of CSE. Display AX contents as the factorial of the given number and terminate the program.Compare num with 00 JE NEXT CALL FACT NEXT:MOV RESULT. ------------------------------------------------------------------------------------------------------------------------Algorithm: 1.CODE MOV AX.01 . 3. What is the supply requirement of 8086? 6.model small stands for? 5. What is the relation between 8086 processor frequency & crystal frequency? 7.of CSE. Functions of Accumulator or AX register? Dept. What is recursive function? 2.Microprocessor Lab Manual RIP:RET FACT ENDP END ------------------------------------------------------------------------------------------------------------------------Output: >d Result 78 ------------------------------------------------------------------------------------------------------------------------Viva questions: 1. What .Bangalore page 28 . DSCE. Specify addressing modes for any instruction? 3. What are assembler directives? 4. ------------------------------------------------------------------------------------------------------------------------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.If true. Compare if BX-1(i. Store the values of N in AX-register and the value of R in BX register.CODE MOV AX. 5.Microprocessor Lab Manual 9a.NCR=1 page 29 . Push values of AX&BX.e. is true then increment NCR e. 0+1) b. POP the values of AX and BX . then add the contents of AX to NCR and return the values (i. Terminate the program ======================================================================= Program . b. NCR=N) c. Compute nCr using recursive procedure. If none of steps a. Repeat from step 5 8.If BX==AX.@DATA MOV DS. a. Compare if BX-0(i. Assume that 'n' and 'r' are non-negative integers. NCR=N) d. And repeat step 5 6. R=1). c.N MOV BX. ------------------------------------------------------------------------------------------------------------------------Algorithm: 1.Decrement BX and again Push the values of AX and BX 7.e.4CH INT 21H NCRPRO:CMP BX. R=0). Declare assembler directives 2.If true. DSCE.AX MOV AX. 4.AX JE RES1 Dept. then add the contents of AX to NCR and return the values (i. Store the values of n in N and r in R(nCr ) in the data segment store 0 in the variable NCR 3. ------------------------------------------------------------------------------------------------------------------------Objective: The objective of this program is to compute the nCr of the given two 8 bit numbers and display the same. 9.MODEL SMALL . Call the procedure NCRPRO.of CSE.e.Bangalore :Recursive procedure to calculate NCR .R CALL NCRPRO MOV AH.If they are equal then increment NCR and return the value (i. Initialize the DS register.e. N=R).e.e. Compare BX and AX register (i. Pop the contents of BX and AX and return to display.DATA N DW 5 R DW 3 NCR DW 0 . Compare BX & AX JE INCR .AX . How Physical address is generated? 5. Functions of DX register? 4.NCR=1 JE RES1 CMP BX. DSCE. Which are pointers present in this 8086? Dept.If BX==1 .If BX==0.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.If BX==AX.of CSE.1 .Microprocessor Lab Manual CMP BX. Functions of BX register? 2. Functions of CX register? 3.NCR=N JE RESN DEC AX CMP BX.0 .Bangalore page 30 . ======================================================================= Outcome: The user will learn how to search for the given substring in the main string and also compare two strings using CMPSB instruction. Initialize the main string with the name STR and store the length of the string in L1 3.CODE MOV AX. Declare assembler directives 2.L2 LEA DI.AX MOV CX. Now compare byte by byte CX and BX if It is equal then go to step14 12. if CX <BX then print msg2 else move the SUBS to CX 11. Find out whether a given sub string is present or not in a main string of characters.MODEL SMALL . Print msg1 and terminate the program ======================================================================= Program . If it is not equal then jump to NFT 13.SUBS Dept.Microprocessor Lab Manual 10a. SCAN byte by byte the main STR and SUBS 9.AX MOV ES.of CSE.Bangalore page 31 . ======================================================================= Objective: The objective of this program is to check whether the given substring is present in the main string.L1 MOV BX. 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. 1.STR LEA SI. 14. If present display ‘ Substring is present’ message at standard output device and if not present display ‘ substring is not found’ msg. Initialize the substring with the name SUBS and store the length of the SUBS is L2 4. If it is equal then increment SI and the values of CX in DX 10.e.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$' . Initialize the data segment and extra segment 6. Define the msg1 as substring is pushed in the main string and msg2 as substring is not present in the main string 5. DSCE. ======================================================================= Algorithm: 1.@DATA MOV DS. Subtract CX and BX i. Load the SUBS again and jump back to the calling function. else compare the two strings JNZ NFT . DSCE.[SI] REPNE SCASB .Microprocessor Lab Manual CLD RPT:MOV AL.L2 JMP RPT END ======================================================================= Output: SUBSTRING IS PRESENT IN MAIN STRING ======================================================================= Viva questions: 1. if strings are not equal display msg2 LEA DX. Which are strings related instructions? 4.MSG2 MOV AH. else display msg1 MOV AH.Bangalore page 32 . if the length of main string is < substring display msg2 JB DMSG2 MOV CX.4CH INT 21H NFT:MOV CX.CX DEC BX SUB CX.of CSE. Which are addressing modes and their examples in 8086? 5.9 INT 21H EXIT: MOV AH.BX . What does u mean by directives? Dept. Compares AL with every letter of STR INC SI MOV DX.BX REPZ CMPSB .DX LEA SI.9 INT 21H JMP EXIT DMSG2: LEA DX. What is the difference between instructions DIV & IDIV? 2.SUBS MOV BX. What is difference between shifts and rotate instructions? 3.MSG1 . Increment SI and store the sum at [SI].0 .MODEL SMALL .of CSE.1 MOV FNS[SI].1 MOV FNS[SI]. The value of N is specified by the user before execution of the program.Microprocessor Lab Manual 11a.N SUB CL.AX MOV SI. 2.0 MOV FNS[SI]. CL= n -2 (for the rest of the length) BAK:MOV AL. 4.@DATA MOV DS. 3.AL LOOP BAK MOV AH. ------------------------------------------------------------------------------------------------------------------------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. To compute next element i. ------------------------------------------------------------------------------------------------------------------------Objective: The objective of this program is to generate first N Fibonacci series numbers. 7. Terminate the program.DATA N DB 10 FNS DB 32 DUP(0) . copy the second number to the array MOV CL.CODE MOV AX. Generate the first ‘N’ Fibonacci numbers . Use SI as pointer to FNS array. The user will learn to generate such a series using 8086 assembly language programming.e.STACK . Repeat step 4 and 5 till counter becomes zero. [SI+ 1]th element. DSCE. ------------------------------------------------------------------------------------------------------------------------Program: . Decrement the count 6.2 .Bangalore page 33 . copy the first number to the array ADD SI.FNS[SI-1] ADD AL. add [SI] to [SI-]] 5.FNS[SI] ADD SI. Set the counter as 8 as first two elements of the series are already stored in the array. Initialize limit for the series N as 10 and the first two elements of the array FNS as 0 and 1. ------------------------------------------------------------------------------------------------------------------------Algorithm: 1.4CH INT 21H END ------------------------------------------------------------------------------------------------------------------------- Dept.1 . What .model small means? 3. db? 5.of CSE. medium. huge? 4. What does u mean by Prefix? 2. Dept. Difference between small. DSCE.Bangalore page 34 . dw. Interrupts in 8086 and there function. tiny.Microprocessor Lab Manual Output: >D FNS 00 01 01 02 03 05 08 0D 15 22 ------------------------------------------------------------------------------------------------------------------------Viva Questions: 1. What is dd. 2 INT 21H MOV AL. The program also places ‘:’ symbol between each numerical value to show the output in the standard format.min. 3. stores hrs. This sub routine will convert the contents of the register from HEX value to BCD value by adding 3030H and executing AAM instruction.AH MOV AH. to get the system time INT 21H . Interrupt INT 21H with AH having the value 2CH. terminate the program ------------------------------------------------------------------------------------------------------------------------Program: . ------------------------------------------------------------------------------------------------------------------------Objective: The objective of the program is to use the DOS interrupts to display the system time on the standard output device i. func(2Ch).DH respectively MOV AL.Bangalore page 35 . the monitor. CL and DH taking one register contents at a time. ------------------------------------------------------------------------------------------------------------------------Outcome: The user will learn different DOS interrupts which will display the system time in the standard format.of CSE. secs in CH. [DH].CL.CODE MOV AH.AX MOV DL. mins.':' MOV AH.Microprocessor Lab Manual 12a.CL CALL DISP MOV DL. Converts HEX values to unpacked BCD format ADD AX.2CH .02 Dept.CH CALL DISP MOV DL.3030H MOV BX. Call display procedure to display the contents of CH.':' MOV AH.4CH INT 21H DISP PROC NEAR AAM .e.2 INT 21H MOV AL. 4. DSCE.sec. 2.MODEL SMALL . ------------------------------------------------------------------------------------------------------------------------Algorithm: 1. will copy the system time to the registers in the following manner.DH CALL DISP MOV AH.Hrs. [CL]. Read the current time from the system and display it in the standard format on the screen. [CH]. What is the function of 02h of Int 21h? 3. What is the function of 0Ah of Int 21h? 5. What is the function of 09h of Int 21h? 4. DSCE. What is the function of 4ch of Int 21h? Dept.Bangalore page 36 .of CSE.BL INT 21H RET DISP ENDP END ------------------------------------------------------------------------------------------------------------------------Output: 09:55:45 ------------------------------------------------------------------------------------------------------------------------Viva Questions: 1. What is the function of 01h of Int 21h? 2.Microprocessor Lab Manual INT 21H MOV DL. Microprocessor Lab Manual 13a. Use DAA to decimal adjusts the count value. ------------------------------------------------------------------------------------------------------------------------Outcome: The user will learn to write delay programs of the specified amount of delay between each display of the count value.0 JNZ NN EXIT: MOV AH. 6.2 MOV DH. machine cycle execution time etc will be well understood while designing the delay subroutine.01 INT 16H . 3.0 NN: PUSH AX CALL SETC . Set the cursor location to display the count values. to set the cursor position CALL DISP . Pop back contents of AX and increment it by 1. Terminate the program.CODE MOV AX. DSCE. Display the count value and call some delay before next value gets displayed. 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.Bangalore page 37 . to display the number CALL DELAY .MODEL SMALL . The concept of instruction cycle. Push the contents of AX to stack. 4.1 DAA CMP AL. then terminate the program else repeat steps 3 to 6 till AL becomes zero 8. Set the initial count value as 0 in AX 2.35 INT 10H Dept. 7. ------------------------------------------------------------------------------------------------------------------------Algorithm: 1.of CSE. Check whether any key is pressed to end the counter by calling interrupt INT 16H which checks the keyboard buffer. check the input buffer to see if any key pressed JNZ EXIT POP AX ADD AL. delay between numbers MOV AH.12 MOV DL. 5. ------------------------------------------------------------------------------------------------------------------------Program: . If the contents of AL is zero. If key is pressed stop the counter and terminate the program else go to next step.4CH INT 21H SETC: MOV AH. BL AND DL.0FFFFH B1: DEC DI JNZ B1 DEC SI JNZ B2 RET END ======================================================================= Output: 99 ======================================================================= Viva Questions: 1.4 SHR DL. DSCE.AL MOV CL.2 INT 21H MOV DL.30H MOV AH.CL ADD DL. Which is faster.Reading word size data whose starting address is at even or at odd address of memory in 8086? 5.0FFFH B2: MOV DI. What is the difference between 08H and 01H functions of INT 21H? 4.30H INT 21H RET DELAY: MOV SI. 3. What is the size of flag register in 8086? Explain all.Microprocessor Lab Manual RET DISP: MOV BL. What is the reset address of 8086? 2.Bangalore page 38 .of CSE.AL MOV DL. Which are the default segment base: offset pairs? Dept.0FH ADD DL. DATA MSG1 DB 10."ENTER ROW NO:$" MSG2 DB 10. Read a pair of input co-ordinates in BCD and move the cursor to the specified location on the screen . move the cursor to the entered row and col Dept. DSCE. ======================================================================= 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.MSG3 MOV AH.2 .9 INT 21H MOV AH. ======================================================================= 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.9 INT 21H CALL READ .Bangalore page 39 .Microprocessor Lab Manual 14a.13.MSG2 MOV AH.of CSE.@DATA MOV DS."PRESS ANY KEY TO STOP$" ROW DB ? COL DB ? .AL LEA DX.AX LEA DX. ======================================================================= 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. 5: Take any character input to exit and return back to dos prompt 6: End the program ======================================================================= Program . 4: The cursor is now at the position (row.9 INT 21H CALL READ .MSG1 MOV AH.13.MODEL SMALL . read the input col MOV COL.CODE MOV AX.13.AL LEA DX. read the input row MOV ROW. column) specified."ENTER COL NO:$" MSG3 DB 10. This can be demonstrated by giving different BCD values at the input. 1 .0FH MOV AH.AL MOV AH. Program to create a file (input file) and to delete an existing file. Whether micro reduces memory requirements? 15a.of CSE.COL INT 10H MOV AH. What is segment override prefix? 5.BL AAD RET END ======================================================================= Output: ENTER ROW NO: 12 ENTER COL NO: 35 PRESS ANY KEY TO STOP ======================================================================= Viva Questions: 1. and store its equivalent decimal number in al AND AL.ROW MOV DL. ------------------------------------------------------------------------------------------------------------------------Objective: Dept.Microprocessor Lab Manual MOV DH. Which is the index registers in 8086? 4.4CH INT 21H READ:MOV AH. wait for a key to be pressed to exit INT 21H MOV AH. DSCE.1 INT 21H AND AL.Bangalore page 40 . Which are the base registers in 8086? 3.8 . Can we use SP as offset address holder with CS? 2. to read the input of two numbers INT 21H . 0FH MOV BL. In this module file to be created is read from Read function. ------------------------------------------------------------------------------------------------------------------------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.AX LEA DX.MSG3 MOV AH. If the input is 0. Then deleted using delete file instructions. Read in the input.@DATA MOV DS. If the input choice is 0."0:DELETE$" MSG4 DB 10. the error message is displayed 8."ENTER FILE NAME TO BE CREATED:$" MSG2 DB 10.9 INT 21H MOV AH.Bangalore page 41 .13. display error message. After reading file is created using instructions for create file operation.CODE MOV AX. DSCE. 3. Program terminates 6. create file module is executed. ------------------------------------------------------------------------------------------------------------------------Algorithm: 1.MSG4 MOV AH.MODEL SMALL .End the program ------------------------------------------------------------------------------------------------------------------------Program . then delete file module is called. Display the message if the user wants to create or delete a file.'0' Dept. 2. Any other input is given.of CSE. execute the instruction to delete a file 4.9 INT 21H LEA DX. If the file to be deleted is not found in the current directory an error message will appear at the user prompt. 7. The name of the file to be created and deleted to be entered by the user during execution of the program.DATA MSG1 DB 10. If the input is 1."ENTER FILE NAME TO BE DELETED:$" MSG3 DB "1:CREATE"."ENTER YOUR CHOICE:$" MSG5 DB "ERROR$" F_NAME DB 80 DUP(0) .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. Program terminates. While creating and deleting any error occurs.13. 5.13.'1' JZ C_FILE CMP AL. File name to be deleted is read using Read module. If the input choice is 1. execute the instruction to create a file.10.1 INT 21H CMP AL.13. MSG5 MOV AH.4CH INT 21H READ:MOV AH.4CH INT 21H C_FILE: LEA DX.asm ====================================================================== Viva Questions: Dept. DSCE.9 INT 21H MOV AH.0 MOV AH. carry flag is set if error during creation MOV AH. func(41h). to store the name of the file LEA SI. func(3CH).4CH INT 21H D_FILE:LEA DX.9 INT 21H CALL READ MOV CX.Microprocessor Lab Manual JZ D_FILE ERROR:LEA DX.Bangalore page 42 .3CH .of CSE. deletes a file with the name loaded in DX INT 21H JC ERROR MOV AH.0DH JZ DONE MOV[SI].41H .AL INC SI JMP BAK DONE:RET END ======================================================================= Output: 1:CREATE 0:DELETE ENTER YOUR CHOICE:1 ENTER FILE NAME TO BE CREATED: Ravi.9 INT 21H CALL READ LEA DX.1 . F_NAME BAK:INT 21H CMP AL.to create a file with the name loaded in DX LEA DX.F_NAME MOV AH.MSG2 MOV AH.F_NAME INT 21H JC ERROR .MSG1 MOV AH. Which is the index registers in 8086? 4. Can we use SP as offset address holder with CS? 2.of CSE. Which are the base registers in 8086? 3.Microprocessor Lab Manual 1.Bangalore page 43 . DSCE. Whether micro reduces memory requirements? HARDWARE PROGRAMS Dept. What is segment override prefix? 5. The strength of 8086 processor lies in its ability to communicate with the real world entities. In the previous section we have seen the usage of 8086 instructions for the execution of simple programs. So it finds various applications in the real world like control of logic controller. Dept. The reader is expected to know the architecture and the command format of the 8255 before going ahead with this section. elevator control etc.Bangalore page 44 .of CSE. In this section we will demonstrate few example programs using interfacing devices. 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. The most commonly used interface is 8255 programmable peripheral interface. 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. open and closing of the door. DSCE.Microprocessor Lab Manual Introduction to 8086 hardware programs. Microprocessor Lab Manual 1b. to check if the no. Repeat step 7 and 8 till cl=0 10. If CF=1. Terminate the program ======================================================================= Program .increment the value of AH and decrement the count value in cl 9. 82h. After the execution of delay of certain amount time display the no. Declare assembler directives 2. If AL=0.0E403H .82H .8 .Also display number of 1’s in the input data. Initialize the AH with 0. of 1’s JC N1 DEC CL JNZ N2 .AL MOV DX. DSCE. display OFFH for even parity 14.Bangalore page 45 . Rotate right the given input by 1 position 8.CODE MOV DX.0 N2:ROR AL. of bits MOV AH.to store the number of 1’s in the applied input 7. to set the control word register MOV AL. ======================================================================= Algorithm: 1.0E401H IN AL. Store 82h in CWR to enable port B as input and port A as output 4.DX MOV CL. Read the status of eight input bits from the logic controller Interface and display ‘FF’ it is even parity bits otherwise display 00.stores the no.decrement cl and repeat step 7 until CL=0 11. of 1’s 15. Initialize the counter value 8 in CL register 6.of CSE.port A o/p and port B i/p OUT DX. else find the next bit JMP NXT N1:INC AH DEC CL JNZ N2 NXT:MOV AL. ======================================================================= Outcome: User will come to know the usage of 8255 to interact with external devices.AH . If AL=1. If CF=0.MODEL SMALL .display 0 for odd parity 13. ======================================================================= Objective: Reading the inputs from the external device like Logic controller and counting number of 1’s in the inputted data. CL.1 CMP AL.01 . To check the even parity mov the contents of AH to AL and AND it with 1 12. of 1’s is even or odd AND AL. if the bit in CF is 1 increment no. Initialize the control word register 3.0 Dept. Port B is initialized as input port and input 1’s moved to AL 5. 0E400H OUT DX. How many TTL inputs and TTL outputs are there in the logic controller? 2.AL MOV AH. DSCE.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.4FFFH ..Microprocessor Lab Manual JZ DFF . What are software interrupts and hardware interrupts?? 4.of CSE. What is Non-Maskable interrupts? Dept.AH MOV DX. Also the count of number of one’s is being indicated by LEDs ======================================================================= Viva questions: 1. if even display FF MOV AL. else display 00 DFF:MOV AL.Bangalore page 46 .AL MOV SI.0E400H OUT DX. What is meant by Maskable interrupts? 5.0 JMP NEXT . What are the various interrupts in 8086? 3.0FFH NEXT :MOV DX.0FFFFH RET1:DEC DI JNZ RET1 DEC SI JNZ RET2 MOV AL. delay to see clear o/p RET2:MOV DI. 10. DSCE.else decrement and display CALL DELAY ADD AL.1 DAA . Perform the following function using logic control Interface i.AL .0E403H MOV AL. 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. 80H.6 9: If AL=99.0E400H UP:OUT DX.CODE MOV DX. if not equal repeat steps 4. terminate the program otherwise pop contents of AX 8: Now compare contents of AL with 99.of CSE.Bangalore page 47 . BCD up-down count ======================================================================= Objective: Performing the counter operations ======================================================================= Outcome: The user will learn to implement the counters using logic controller interface.AL CALL DELAY ADD AL. to BCD CALL STOP CMP AL. if no.MODEL SMALL .all ports o/p OUT DX.99H DAA CALL STOP CMP AL.0 MOV DX.80H .11 14: On AL=99 Terminate the program ======================================================================= Program: . if any.5.Microprocessor Lab Manual 2b.AL MOV AL. 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.99H JNE UP . ======================================================================= 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. If not equal repeat 9.99H Dept. convert hex no. < 99H increment and display DOWN:OUT DX. 05FFF Dept.4CH INT 21H DELAY:MOV SI. 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: .of CSE. 1 BAK:OUT DX. if any.CODE MOV DX. Ring counter.Microprocessor Lab Manual JNE DOWN STOP:PUSH AX MOV AH. AL MOV DX. DSCE. 0E403H MOV AL.1 INT 16H JNE EXIT POP AX RET EXIT:MOV AH.Bangalore page 48 .2FFFH RET2:MOV DI.AL CALL DELAY CALL STOP ROL AL. ======================================================================= 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.MODEL SMALL . 0E400H MOV AL.1 JMP BAK DELAY:MOV SI. 80H OUT DX.0FFFFH RET1:DEC DI JNZ RET1 DEC SI JNZ RET2 RET END ======================================================================= ii. Give examples for Maskable interrupts.4CH INT 21H END ======================================================================= Output The counter outputs are seen by the periodic on and off of the LEDs. What is 8255? 4.Bangalore page 49 .of CSE. 2. Give the internal architecture of 8255. Give example for Non-Maskable interrupts. What is CWR? Dept. 3.0FFFFH RET1:DEC DI JNZ RET1 DEC SI JNZ RET2 RET STOP:PUSH AX MOV AH. How many ports are there in 8255. ======================================================================= Viva questions: 1. 6.1 INT 16H JNZ XIT POP AX RET XIT: MOV AH. 5.Microprocessor Lab Manual RET2:MOV DI. DSCE. 0E401H . (X*Y) MOV DX.0FFFFH Dept. ======================================================================= 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.) from keyboard MUL BL . wait for a keyboard i/p INT 21H MOV DX. DSCE.MODEL SMALL .Microprocessor Lab Manual 3b.AL MOV AH. display the resultant CALL DELAY MOV AL.0E400H OUT DX.4CH INT 21H DELAY:MOV SI.AL .of CSE.AL MOV AH.CODE MOV DX.DX MOV BL. multiply the nos.0E401H IN AL. take input of X(first no. ======================================================================= Objective: The user will learn to read the input from external device and to perform the product of these two numbers.05FFFH RET2:MOV DI.0E403H MOV AL.8 .AH OUT DX.) from keyboard IN AL. ======================================================================= 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: .DX .Bangalore page 50 . Read the status of two 8-bits inputs(X & Y) from the Logic Controller Interface and display X*Y.AL MOV DX. take input of Y(first no.82H OUT DX. 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 OUT instruction? 3. DSCE. Are there any other instructions which can take data from external devices apart from IN. What do you mean by interrupt service routines? Dept.Bangalore page 51 . OUT instruction? 4. What is the action of the IN instruction? 2.of CSE. 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 similarly store codes for all digits separately.?.?. by multiples of 10 and CALL CONV .?. 11.0FFH.0FFH.0FFH. take the input from the input port referring to the control word register. ======================================================================= .7-segment code from 0 to 9 BCD DB 5 DUP (?) .to convert 16-bit binary no. 9.?.to store BCD equivalent 7-segment code in place of ?.BCD MOV AX.0FFH.82H.1000 CALL CONV MOV BX. 4.DATA LIST DB 0FFH.of CSE. ======================================================================= Algorithm: 1.0FFH .divide the no. to BCD MOV BX.CODE MOV AX.0FFH.store each no. Load the CWR contents into the respective ports.0A4H.to store converted BCD no. Store the input values as separate digits in the array BCD and then assign a pointer to this array.?. along with Blank places.MODEL SMALL . these codes are displayed separately with some delay between two codes. 10. Maximum for any 16bit binary value we need 5 decimal places in the BCD array.?.0B0H.98H .80H MOV DX.? TABLE DB 0C0H. MOV BX. 2.Bangalore page 56 . NUM DW 0FH .0FFH.binary no.0F9H.0F8H. convert the digits in BCD array to its equivalent code stored in TABLE. DSCE.80H. Store the binary values of all the LCD segments values of all the digits in data segment. Above step is repeated twice to display from left to right and right to left.AL LEA SI. Terminate the program. 5. 8. in BCD array to get BCD no.@DATA MOV DS. 3.100 Dept.92H. to be converted .99H.?. Assign another pointer to the starting location of the array where the values of the digits 0 to 9 are stored. NUM .AX MOV AL. 6.10000 .0E403H OUT DX.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. 7.?. AL MOV AX. DSCE.DI PUSH BX CALL DISP CALL DELAY CALL STOP POP BX INC DI DEC BH JNZ BAK1 MOV BH.[SI] XLAT MOV [DI].Bangalore .5 NEXT: MOV AL.DL LEA SI.DI PUSH BX CALL DISP CALL DELAY CALL STOP POP BX DEC DI DEC BH JNZ BAK2 JMP START STOP: MOV AH.Microprocessor Lab Manual CALL CONV MOV BX.LIST BAK1: MOV SI.9 LEA DI.CX= no.BCD LEA DI. of BCD digits .of CSE.LIST+8 BAK2:MOV SI.0 DIV BX MOV [SI].TABLE MOV CX.1 INT 16H Dept.AL DEC DI INC SI LOOP NEXT JMP START CONV: MOV DX.DX INC SI RET START: MOV BH.copy the equivalent 7-segment to the LIST page 57 .10 LEA DI.10 CALL CONV MOV [SI].LIST+8 LEA BX. DSCE.AL PUSH AX MOV DX. What is BCD number? 2.08 MOV AL.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. What is the difference between DAA and AAA instructions?? 7b.4 NC: MOV BL.Bangalore page 58 .4CH INT 21H DISP: MOV CX.0E401H OUT DX.Introduce a delay between successive steps.of CSE.0FFH OUT DX. ======================================================================= Objective: Dept.0E402H MOV AL.(Any arbitrary value for the may be assumed by the student). Viva questions: 1.AL MOV AL.[SI] NB: ROL AL.Drive a stepper motor interface to rotate the motor in clock wise direction by N steps.AL POP AX DEC BL JNZ NB INC SI LOOP NC RET DELAY:MOV BX. How to convert HEX to BCD? 3.02FFFH RET2: MOV CX.00H OUT DX.(N is specified by the examiner).Microprocessor Lab Manual JNZ EXIT RET EXIT: MOV AH.1 MOV DX. ======================================================================= Algorithm: 1.0E400H MOV AL.e.CX-no. terminate the program.1 .30 . ======================================================================= Program: . 5. Store the CWR contents into its respective port.10 00 10 00 A & C poles are energized i.of CSE. Dept.CODE MOV CX.Bangalore page 59 .80H OUT DX. perform steps 5 and 6 till CX becomes zero.B & D are not energized ROR AL. Store 88H in AL and Output 88H( initial value for energizing the rotor of the motor) to the output port .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.Microprocessor Lab Manual The objective of the program is interface the stepper motor with 8086 and make it rotate clockwise direction. of steps MOV DX. DSCE.0E403H MOV AL. Hence user can control the operation of the stepper motor. Give some delay before next rotation and rotate the content of AL once to the right and give this modified value to output port. gives clockwise motion DEC CX JNZ REP1 MOV AH.MODEL SMALL . 8. Now motor rotates clockwise by one step.AL MOV DX. 4.2FFFH BACK2:MOV DI. 6. Store the address of the output ports in AL register.to energize the north pole and south pole of the motor REP1:OUT DX. 2. 3. 10 CALL DELAY . Store the number of steps for rotation of the rotor in CX.AL .4CH INT 21H DELAY:MOV SI. Decrement CX by one 7.88H . ======================================================================= Outcome: The user can control the speed of the stepper motor by varying the delay between successive steps. What is stepper motor? 2. DSCE. How does the stepper motor rotation take place? Dept.Microprocessor Lab Manual ======================================================================= Viva Questions 1.of CSE.Bangalore page 60 . Bangalore page 61 .4CH INT 21H DELAY:MOV SI. 2.1 . gives anti-clockwise motion DEC CX JNZ REP1 MOV AH. 6.0E400H MOV AL.Microprocessor Lab Manual 8b. Introduce suitable delay between successive steps. Decrement CX by one 7. ======================================================================= Outcome: The student will learn the working of stepper motor and the methods to control the stepper motor.of CSE.0E403H MOV AL. Store 88H in AL and Output 88H( initial value for energizing the rotor of the motor) to the output port . 5.0FFFFH BACK1:DEC DI JNZ BACK1 DEC SI JNZ BACK2 Dept. Now motor rotates in anti clockwise direction by one step.CODE MOV CX.20 MOV DX.AL CALL DELAY ROL AL. Store the address of the output ports in AL register. Perform steps 5 and 6 till CX becomes zero. ======================================================================= Objective: The objective of the program is to drive the stepper motor and also make it rotate in anticlockwise manner. terminate the program ======================================================================= Program: .MODEL SMALL . Drive a stepper motor interface to rotate the motor in Anti-clockwise direction by N steps. 4.(N is specified by the examiner). ======================================================================= Algorithm: 1. 3.80H OUT DX. Store the number of steps for rotation of the rotor in CX. Give some delay before next rotation and rotate the content of AL once to the left and give this modified value to output port.88H REP1:OUT DX.(Any arbitrary value for the delay may be assumed by the student). DSCE. 8.2FFFH BACK2:MOV DI. Store the CWR contents into its respective port.AL MOV DX. Dept. DSCE.Bangalore page 62 .Microprocessor Lab Manual RET END ======================================================================= Result: The stepper motor is found rotating in the anti-clockwise direction with a suitable delay between each steps. 2.of CSE. What is the step angle rotated by the motor for every step. ======================================================================= Viva questions: 1. Give the applications of stepper motor. 2.Bangalore page 63 . Terminate the program when CX becomes zero. Store the CWR value to the respective port address.of CSE. ======================================================================= Objective: Objective of the program is to make stepper motor to rotate both clockwise and anticlockwise manner by N number of steps.AL MOV DX. Output the initial value for the rotor say 88H and also store this in AL.Microprocessor Lab Manual 9b. 6.CODE MOV CX.1 . This will make rotor to rotate clockwise by one step.1 . ======================================================================= Algorithm: 1.(Any arbitrary value for the delay may be assumed by the student). Now again load CX with the number of steps it has to go through in the anti clockwise direction.80H OUT DX. Perform steps 4 to 7 but AL contents to be rotated left by one every time to ensure the anticlockwise rotation. 7. ======================================================================= Program: . Meanwhile rotate the contents of AL register once and give this modified value to the output port and then to rotor.MODEL SMALL .0E403H MOV AL.Introduce a suitable delay between successive steps.AL CALL DELAY ROR AL. 3. Store the address of the output port in DX 4. gives anti-clockwise motion DEC CX JNZ REP2 Dept.AL CALL DELAY ROL AL.88H REP1:OUT DX.30 REP2:OUT DX. 10.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). Give some delay before energizing the motor again. gives clockwise motion DEC CX JNZ REP1 MOV CX. Now decrement the counter CX by one. 8. ======================================================================= Outcome: The user can see the stepper motor rotating both clockwise and anticlockwise manner. Store the number of steps the rotor has to rotate in the clockwise direction in CX. 9. Perform steps 5 and 6 until the register CX becomes zero.30 MOV DX. DSCE. 5.0E400H MOV AL. ======================================================================= Viva questions: 1. DSCE.of CSE.Bangalore page 64 .Microprocessor Lab Manual MOV AH. Dept.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.4CH INT 21H DELAY: MOV SI.0FFFH BACK2: MOV DI. If any key is pressed in the first row.DATA KEYS DB '0123456789ABCDEFGHIJKLMN' . that key’s row and column will be scanned and it will be displayed on the display devices.10.0E403H MOV AL. Start scanning process by activating PC0 line. Also display row and column numbers of the key pressed. ======================================================================= Algorithm: 1. DSCE. 4.MODEL SMALL . Get the input from the interface using port B and compare it with 00H to check whether any key is pressed or not.of CSE.'$' . The above procedure is repeated for 2nd row and third row of the keyboard matrix when no key is pressed in first row. the control word to the CWR which makes port A as input port and port C as output port.13.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.array for 24 keys of keypad KEY DB ? MSG1 DB 10. Terminate the program ======================================================================= Program: .13. Display the row and column number of the key being pressed. 2. If no go to second row. ======================================================================= Objective: The objective of the program is to check the keyboard interface module to see whether any key is pressed. These keys include 0-9 integers and alphabets A to N. 6.@DATA MOV DS. ======================================================================= Outcome: The user will understand the keyboard interface device configuration by giving out different keys as input for each execution of the program. 8. If key is pressed. Move 90H.Microprocessor Lab Manual 10b. By adding 30H convert row and column numbers to ACII values.AL Dept. 7.Bangalore page 65 . find out in which column the key is pressed by successive rotation of contents of AL.CODE MOV AX.90H OUT DX. This is done by activating PC1 and PC2 lines respectively and repeat the step 5. 'THE ROW NO IS =' ROW DB ?. 3. Declare all 24 characters in an array where each character corresponds to the key in the keyboard interface. 5.'$' MSG2 DB 'THE COL NO IS =' COL DB ?.AX MOV DX. check for the pressed key which will be 1 .AL MOV DX.31H MOV CL.1 JC DISP INC SI JMP NEXT1 SR: CALL DELAY LEA SI. first row .33=ascii value for 3 ie.0E402H MOV AL.33H MOV CL.04 OUT DX.30H Dept.10H MOV ROW.of CSE. third row page 66 .1 JC DISP INC SI JMP NEXT2 TR: CALL DELAY LEA SI.32H MOV CL.KEYS ADD SI.second row starts from 16th key .31=ascii value for 1 ie.0E402H MOV AL.take input using port B .02 OUT DX.0E400H IN AL.0E402H MOV AL. DSCE.Bangalore .AL MOV DX.DX CMP AL.else activate pc1 ie.second row starts from 8th key .cl=column value .AL MOV DX.00 JNZ TR JMP REP1 FR:CALL DELAY LEA SI. else activate pc2 ie. to check row1 .take input using port B .if key pressed in row1 .30H NEXT2: INC CL SHR AL.DX CMP AL.jump to second row .32=ascii value for 2 ie.jump to first row .0E400H IN AL.0E400H IN AL. to check row2 .repeat the check till any key is pressed .KEYS ADD SI.take input using port B . second row . to check row3 .KEYS MOV ROW.00 JNZ SR MOV DX.01 OUT DX.30H NEXT1: INC CL SHR AL.00 JNZ FR MOV DX.08 MOV ROW.if key pressed in row2 .if key pressed in row3 .DX CMP AL.to activate pc0 ie.Microprocessor Lab Manual REP1:MOV DX.jump to third row . 1 JC DISP INC SI JMP NEXT3 DISP: MOV DL.of CSE.CL . ======================================================================= Viva questions: 1. LEA DX.MSG1 . DSCE. Explain the logic of the program.to display the key pressed MOV AH.[SI] .0FFFFH BAK1: DEC DI JNZ BAK1 DEC SI JNZ BAK2 RET EXIT: MOV AH.MSG2 INT 21H JMP EXIT DELAY: MOV SI.to display the col no.4CH INT 21H END ======================================================================= Result: The key pressed is displayed along with its row and column in the keyboard matrix. Which is the interfacing device to connect 8086 with 8X3 keyboard matrix? 2.09H INT 21H MOV COL.Microprocessor Lab Manual NEXT3:INC CL SHR AL.2FFFH BAK2: MOV DI.to display the row no.02H INT 21H LEA DX. MOV AH. Dept.Bangalore page 67 . DSCE.Microprocessor Lab Manual 11b. During the read process KEY will contain the value of the key being pressed. In case of addition simply add FK[1] and FK[3] and give the result 13. 9. 10. ======================================================================= Outcome: The user will learn to use the 3X8 keyboard as a calculator to perform the addition and subtraction operation. If not display the error message 11. 12. 4.AL Dept.of CSE."ERRORS$" EXPN DB 10.90H OUT DX.0E403H MOV AL. Initialize the directives. Set NANS as a flag to indicate whether the answer is negative or not. Use FK array to store the expression to b e evaluated. 2. If the element is neither + nor – display the error message.DATA FK DB 4 DUP(?) .MODEL SMALL .(Limitation: it is a single digit calculator). ======================================================================= Algorithm: 1. Display the message for prompting the user to enter the expression 7.array to store the expression KEY DB ? ERMSG DB 10.@DATA MOV DS."ENTER EXPRESSION:$" NANS DB 0 . 5. Define the control word as 90H and output it at CWR. In case of subtraction if the result is negative. Initialize the FK array to store the elements of the expression. 6. ERMSG contains the error message to be displayed in case needed. ======================================================================= 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. If the expression is error free then execute corresponding code segment depending on whether addition or subtraction is to be done. set the flag NANS to 1.CODE MOV AX.Bangalore page 68 .Scan a 3x8 keypad for key closure and simulate ADD and SUBTRACT operations as in a calculator .13. call the display subroutine and display the result and then terminate the program. Copy it to FK array. 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. Compare the forth element of the array to see if it is ‘=’ symbol. 14. 3.13. ======================================================================= Program . 8.AX MOV DX. FK[2] JNC POSITIVE NEG AL MOV NANS.FK BAK:CALL READ CALL DELAY MOV AL.4CH INT 21H READ: MOV AL.1 POSITIVE: CMP FK[3].if equal jump to addition .compare the second char with ‘-‘ .Microprocessor Lab Manual LEA DX.if equal jump to subtraction .EXPN MOV AH.to add FK[0] and FK[2] .if the result is a positive no.4CH INT 21H SUBN:MOV AL.9 INT 21H MOV DI.0CH JZ SUBN JMP ERR MOV AH.display the answer .FK[2] CMP FK[3].expression contains 4 char. DSCE.if not equal jump to error . 5+6= .compare the third char with ‘=’ .4CH INT 21H ERR:LEA DX.80H MOV KEY. ie.4CH INT 21H ADDN:MOV AL. check for row1 page 69 .nans=negative answer=1.AL Dept.compare the third char with ‘=’ .read the input .FK ADD AL.9 INT 21H MOV AH.display the answer .1 MOV BH.of CSE.bl=count for 3 rows .13H JNZ ERR CALL DISP MOV AH.0 MOV BL.if operator is neither of them jump to error . jump to positive .FK SUB AL.3 NEXTROW:ROL AL.compare the second char with ‘+’ .store the read input in FK as expression .Bangalore . eg.to subtract FK[0] and FK[2] .else find two’s complement .display error .AL INC SI DEC DI JNZ BAK CMP FK[1].ERMSG MOV AH.0BH JZ ADDN CMP FK[1]. true .4 LEA SI.al=01.13H JNZ ERR CALL DISP MOV AH.KEY MOV [SI]. 2 INT 21H RET NEXT:CMP DL. and display page 70 .Bangalore .13H JNZ NEXT2 MOV DL.if negative answer is false ie.'-' MOV AH.2 INT 21H RET NEXT2: ADD DL.2 INT 21H POP AX SKIP:AAM ADD AX.Microprocessor Lab Manual MOV DX.to compare if the key pressed is ‘+’ .BH DEC BL JNZ NEXTROW JMP READ KEYCODE: MOV DL.2 INT 21H RET DISP: CMP NANS.AL MOV CL. else the key pressed is a digit .of CSE.8 MOV DX.to compare if the key pressed is ‘=’ .0BH JNZ NEXT MOV DL.to compare if the key pressed is ‘-‘ . 0 jump to skip .'+' MOV AH.0E400H IN AL.else add ‘-‘ symbol before the no.'=' MOV AH.3030H Dept.1 JNZ SKIP PUSH AX MOV DL.30H MOV AH.2 INT 21H RET NEXT1: CMP DL.0E402H OUT DX.to find the key pressed .DX NEXTCOL: ROR AL.KEY CMP DL.'-' MOV AH. DSCE.1 JC KEYCODE INC KEY DEC CL JNZ NEXTCOL MOV AL.0CH JNZ NEXT1 MOV DL. 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.BH INT 21H MOV DL. What is debouncing of the key? Dept.Bangalore page 71 .BL INT 21H RET DELAY:MOV BX.AX MOV AH.Microprocessor Lab Manual MOV BX. DSCE.2FFFH B2: MOV CX.2 MOV DL.of CSE. of sine waveforms MOV BX.0-255 levels possible. declare some points which correspond to the amplitude of the sine wave in an array 3. 8. cosine wave etc.Genarate a sine wave using the DAC interface (The output of the DAC is to be displayed on a CRO).AL MOV SI. 7.0E401H .22.63.0 .@DATA MOV DS. 10.97.0 Dept. of points MOV DX.9 JB B1 B2:MOV AL.43.AX MOV AL.Microprocessor Lab Manual 12b.Bangalore page 72 .0E403H OUT DX. use port B as output port 6. ======================================================================= Algorithm: 1. decrement BX and repeat step 6 until BX becomes zero 9.80H MOV DX.port B as o/p port B1:MOV AL.DATA A DB 00.A[BX] ADD AL. move the first element of the array to AL and add 127 to it. Initialize SI with a large value which indicate the number of wave cycles to be generated. Median is 127 OUT DX. points to plot .AL DEC BX CMP BX.81. keep on adding 127 to each value of AL and decrement BX until it becomes zero 11.BX-count no.AL INC BX CMP BX.125.of CSE.CODE MOV AX.SI-no. Terminate the program ===================================================================== Program: . ======================================================================= 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.119.A[BX] ADD AL.MODEL SMALL . 5.127 OUT DX. Move the first element of the array again to AL and subtract 127 from it.127 .0FFFFH . DSCE. Move 80H into CWR to enable all the ports as output ports 4.109. Initialize assembler directives 2.127 . Subtract 127 from each value of AL and increment BX until it becomes 9. 127 SUB CL.0 JNZ B4 DEC SI JNZ B1 MOV AH.A[BX] MOV CL.9 JB B3 B4: MOV AL.of CSE. Dept.AL MOV AL.AL MOV AL.AL INC BX CMP BX. DSCE.Microprocessor Lab Manual JNZ B2 B3:MOV AL.Generate a Half Rectified Sine wave form using the DAC interface.CL OUT DX.AL DEC BX CMP BX. Explain the operation of DAC.CL OUT DX. 13b.A[BX] MOV CL.(The output of the DAC is to display on a CRO).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.127 SUB CL.Bangalore page 73 . @DATA MOV DS. use port A as output port 6. output 127 14 times to give delay between each rectified waveform.0E403H OUT DX.80H MOV DX.119. Repeat above step until BX becomes zero. Terminate the program.AL INC BX CMP BX.127 .AL MOV CX. 8.portA as o/p port B1: MOV AL.AX MOV AL.Bangalore page 74 .63.A[BX] ADD AL. 10. Declare some points which correspond to the amplitude of the sine wave in an array 3. 7.22. Initialize SI with a large value which indicates the number of wave cycles to be generated.97.of CSE. Repeat steps 6 7 and 8 until SI becomes zero.125. 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.MODEL SMALL .AL Dept.0 MOV DX. Subtract 127 from each value of AL and output this through port A and repeat step 6 until BX becomes zero.43. Move 14 to SI and 127 to AL.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.DATA A DB 00. 5.A[BX] ADD AL. Initialize assembler directives 2.9 JB B1 B2: MOV AL. 11.127 OUT DX.81. 9.127 OUT DX. ===================================================================== Program: . DSCE.CODE MOV AX.0FFFFH MOV BX. Move 80H into CWR to enable all the ports as output ports 4.109.0E400H . AL DEC SI JNZ RPT LOOP B1 EXIT: MOV AH. DSCE.127 .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.14 RPT: MOV AL.loop for half rectified wave OUT DX.Bangalore page 75 .of CSE.Microprocessor Lab Manual DEC BX CMP BX.0 JNZ B2 MOV SI. 97.43.MODEL SMALL .0 JNZ B2 LOOP B1 MOV AH.@DATA MOV DS.4CH Dept.64. ======================================================================= 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.125.0 MOV DX.A[BX] ADD AL.128 OUT DX.128 OUT DX.0E401H B1:MOV AL.of CSE.Microprocessor Lab Manual 14b. 8: Terminate the program ======================================================================= Program: .AL DEC BX CMP BX. ======================================================================= 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.127 .82.AX MOV AL.9 JB B1 B2:MOV AL.119. Generate a Fully Rectified Sine wave from using the DAC interface (The output of the DAC is to be displayed on a CRO).0FFFFH .22.CODE MOV AX.A[BX] ADD AL.80H MOV DX. of waveforms MOV BX.110.CX-no.DATA A DB 00.AL INC BX CMP BX.0E403H OUT DX. DSCE.Bangalore page 76 .AL MOV CX. SI number of times. 2.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. How to vary the frequency of the output sine wave?? Dept.of CSE.Bangalore page 77 . DSCE. This will execute in the loop and by pressing ENTER key the program can be terminated.0 MOV DX. 3. with all requests in OFF state. ======================================================================= Program: . Initially the elevator should be in the ground floor.check for gnd floor JNC GND .Bangalore page 78 .if a key is pressed from the keyboard then exit INT 16H JNE EXIT MOV AL.CODE MOV DX. floors 0. ======================================================================= Algorithm: 1. ii.MODEL SMALL . On request it moves to that floor.if equal go to 2nd floor Dept.0F0H OUT DX.check for 1st floor JNC FF .AL LOOP1:CALL RQCHE . ======================================================================= Outcome: The user can understand the controlling operation of an elevator system by using the elevator module.0E400H OUT DX.0E403H MOV AL.if equal go to gnd SHR AL. Initially elevator is at the ground floor 2.82H .AL BAC: MOV AH. When a request is made from a floor. ======================================================================= Objective: The user will be able to control the elevator which runs from ground floor and forth floor.port B as i/p port OUT DX.1 .if no request wait SHR AL.1 .01 .Drive Elevator Interface in the following way: i.check for 2nd floor JNC SF .e. the elevator should move to that floor.1.1 .Microprocessor Lab Manual 15b. 2 and 3.check if there is a request JZ LOOP1 . 5.if equal go to FF SHR AL. Whenever a request is made elevator must go to that floor and wait there for few seconds and then go to the ground floor. 4. If some requests occur during going up or coming down they should be ignored.AL MOV AL.of CSE. When the elevator reaches any floor it stays in that floor until a request from another floor is made. and then come down to ground floor and stop. wait there for a couple of seconds. DSCE. The floor requests are scanned in fixed order i. 06 CALL GODW JMP BAC TF:MOV AL.06 CALL MUP CALL DELAY CALL DELAY MOV CL.stay in ground floor for few secs .loop till CL=0 .0E400H UP: INC AL CALL DELAY OUT DX.compare if no key is pressed .for first floor LED’s=3 .0FFH RET GND:CALL DELAY CALL DELAY MOV AL.0F0H MOV CL.0F0H MOV CL.cl=count for no.increment the value of AL to move up . for third floor LED’=9 .0F0H JMP BAC FF:MOV AL.to move upwards .cl=count for no.09H CALL MUP CALL DELAY CALL DELAY MOV CL. for second floor LED’s=6 .else go to 3rd floor . of LED’s.4CH INT 21H MUP:MOV DX.send the o/p to port A . of LED’s.clear the i/p data .decrement the value of AL to come down page 79 .Bangalore .0E401H IN AL.clear the i/p data and jump for next request .cl=count for no.send the o/p to port A .take the i/p from the interface .to move downwards .of CSE.go to bac for next request .0F0H MOV CL.Microprocessor Lab Manual JMP TF RQCHE:MOV DX.0F0H CMP AL.0E400H DOWN:DEC AL CALL DELAY OUT DX.AL LOOP UP RET GODW:MOV DX. of LED’s. DSCE.DX OR AL.03 CALL MUP CALL DELAY CALL DELAY MOV CL.AL Dept.03 CALL DOWN JMP BAC SF:MOV AL.09H CALL GODW JMP BAC EXIT: MOV AH. Explain the various modules used in the elevator interfacing module.0FFFFH RPT1:DEC DI JNZ RPT1 DEC SI JNZ RPT2 RET END ======================================================================= Result: The working of the elevator is observed.2FFFH RPT2:MOV DI. ======================================================================= Viva questions: 1. Explain the operation of elevator.Bangalore page 80 .loop till CL=0 RET DELAY:MOV SI. DSCE.of CSE. Dept. 2.Microprocessor Lab Manual LOOP DOWN .
Copyright © 2024 DOKUMEN.SITE Inc.