You are on page 1of 113

Dept.

of ECE

MPI LAB MANUAL

MICRO PROCESSOR & INTERFACING LAB MANUAL

DEPARTMENT OF ELECTRONICS & COMMUNICATION ENGINEERING

III B.Tech II Semester (FOR ECE)

V.K.R., V.N.B. & A.G.K. COLLEGE OF ENGINEERING


Gudivada-521301, Ph-08674-242189 www.gudivadaenggcollege.co.in
V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE 1

Dept. of ECE

MPI LAB MANUAL

INSTRUCTIONS TO THE STUDENTS

1. Students are required to attend all labs. 2. Students will work in a group of two in hardware laboratories and individually in computer laboratories. 3. While coming to the lab bring the lab manual cum observation book, record etc. 4. Take only the lab manual, calculator (if needed) and a pen or pencil to the work area. 5. Before coming to the lab, prepare the prelab questions. Read through the lab experiment to familiarize yourself with the components and assembly sequence. 6. Utilize 3 hours time properly to perform the experiment and noting down the readings. Do the calculations, draw the graph and take signature from the instructor. 7. If the experiment is not completed in the prescribed time, the pending work has to be done in the leisure hour or extended hours. 8. You will be expected to submit the completed record book according to the deadlines set up by your instructor. 9. For practical subjects there shall be a continuous evaluation during the semester for 25 sessional marks and 50 end examination marks. 10. Of the 25 marks for internal, 15 marks shall be awarded for day-to-day work and 10 marks to be awarded by conducting an internal laboratory test.

V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE

Dept. of ECE

MPI LAB MANUAL

S.No 1 2 3 4 5 6

CONTENTS OVERVIEW OF THE 80X86 FAMILY INTRODUCTION TO TASM PROCEDURE TO ENTER A PROGRAM USING TASM SOFTWARE: EXAMPLE FOR ASSEMBLE LANGUAGE PROGRAM EXECUTION OF PROGRAM THROUGH TRAINER KIT TRAINER KIT PROGRAMMES 1. ADDITION OF N 8 BIT NUMBERS 2. MULTI BYTE ADDITION 3. MULTIBYTE SUBTRACTION 4. MULTIPLICATION OF 16 BIT NUMBER 5. DIVISION OF 16 BIT NUMBER 6. FACTORIAL OF A GIVEN NUMBER

Page No 6-8 9-10 11-13 14 15

16-17 18-19 20-21 22-23 24-25 26-27

TASM PROGRAMMES 1. MULTI BYTE ADDITION 2. MULTI BYTE SUBTRACTION 3. 8 BIT MULTIPLICATION (UNSIGNED) 4. 8-BIT MULTIPLICATION (SIGNED) 5.16 BIT MULTIPLICATION (UNSIGNED) 6. 8 BIT DIVISION (UNSIGNED) 7. 8-BIT DIVISION (SIGNED) 8. 16 BIT DIVISION (UNSIGNED) 9. LARGEST OF A GIVEN NUMBER 10. ASCII ADDITION 11. ASCII SUBTRACTION 28-30 31-33 34-35 36-37 38-40 41-42 43-44 45-46 47-48 49-50 51-53

LOGIC OPERATIONS 1. CHECK WHETHER A GIVEN 16-BIT NUMBER IS EVEN OR ODD 2. CHECK WHETHER A GIVEN 16-BIT NUMBER IS POSITIVE OR NEGATIVE 54-55 56-57

V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE

Dept. of ECE

MPI LAB MANUAL

3. SORTING (ASCENDING) 4. SORTING (DESCENDING) 5. PACKED TO UNPACKED BCD 6. BCD to ASCII CONVERSION 9 STRING OPERATIONS 1. LENGTH OF THE STRING 2. BLOCK TRANSFER 3. STRING COMPARISION 4. STRING REVERSAL 5. STRING INSERTION 6. STRING DELETION 7. READING KEYBOARD WITH ECHO 8. READING KEYBOARD WITHOUT ECHO 9. DISPLAYING A CHARACTER 10. DISPLAYING A STRING INTERFACING 1. 8255 PPI INTERFACING -1 2. 8279 KEYBOARD/DISPLAY INTERFACING 3. 8259 PROGRAMMABLE INTERUPT CONTROLLER 4. 8251 USART APPENDIX

58-60 61-63 64-66 67-68

69-71 72-74 75-77 78-80 81-84 85-87 88-89 90-91 92-93 94-95

97-99 100-102 103-104 105-106

Expected Questions from Microprocessors Key to the Questions on Microprocessors

108-110 111-113

V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE

Dept. of ECE

MPI LAB MANUAL

V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE

Dept. of ECE

MPI LAB MANUAL

1.OVERVIEW OF THE 80X86 FAMILY


The 80x86 family was first started in 1981 with the 8086 and the newest member is the Pentium which was released thirteen years later in 1994. They are all backwards compatible with each other but each new generation has added features and more speed than the previous chip. Today there are very few computers in use that have the 8088 and 8086 chips in them as they are very outdated and slow. The number of 286 or 386 based computers around is declining as today's software becomes more and more demanding. Even 486's are being replaced by Pentiums. With the Pentium PRO and the MMX based CPUs Intel keeps increasing performance and features. As computers are used to manipulate various types of data, there has to be some physical places where these data can be stored. Some of these places are the registers.

REGISTERS
Registers are places in the CPU where a number can be stored and manipulated. There are three sizes of registers: 8-bit, 16-bit and on 386 and above 32-bit. There are four different types of registers: - General Purpose Registers, - Segment Registers, - Index Registers, - Stack Registers.

GENERAL PURPOSE REGISTERS


First, we are going to describe the main registers. Later, we are going to describe the stack registers. The main registers are 16-bit registers. There are four general purpose registers: AX, BX, CX and DX. They are split up into 8-bit registers. AX is split up into AH which contains the high byte and AL which contains the low byte. On 386's and above there are also 32-bit registers, these have the same names as the 16-bit registers but with an 'E' in front i.e. EAX. You can use AL, AH, AX and EAX separately and treat them as separate registers for some tasks.

SEGMENT REGISTERS
Code segment register CS- Stores the base address of Code segment Stack segment register -SS- Stores the Base address of stack Data segment register-DS- Stores the Base address of data Extra segment register-ES- Stores the Base address of the extra segment V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE 6

Dept. of ECE

MPI LAB MANUAL

INDEX REGISTERS
These registers are sometimes called pointer registers. They are 16-bit registers and are mainly used for string instructions. There are three index registers SI (source index), DI (destination index) and IP (instruction pointer). On 386's and above there are also 32-bit index registers: EDI and ESI. You can also use BX to index strings.

STACK REGISTERS
BP and SP are stack registers and are used when dealing with the stack. We will discuss about them when we will talk about the stack. The designers of the 8088 decided that the maximum need for memory space will be one megabyte. So, the chip they build cannot go above that. The problem is to access a whole megabyte 20 bits are needed. But registers only have 16 bits so 4 more bites are needed. They came up with what they thought was a clever way to solve this problem: segments and offsets. This is a another way to do the addressing with two registers but not using 32 bits. To compute every single address the segment addresses as well as the offset are needed. A segment is usually 64kBytes long. To address a location inside a segment, we need the offset (16 bytes long).

THE STACK
As the number of registers used is low, how do they manage to manipulate the data? There is something called a stack which is an area of memory which you can save and restore values to. To physically imagine this we can consider a stack of plates. The last one you put on is the first one that you take off. This is sometimes referred to as Last On First Off (LOFO) or Last In First Out (LIFO). But, you have to be sure that you do not put to much data in the stack.

NUMBERS IN BINARY
Before we begin to understand how to program in assembly it is best to try to remember how numbers are represented in computers. Numbers are stored in binary, base two. There are several terms which are used to describe different size numbers: 1 BIT: 0 (can have the values 1 or 0) One bit is the simplest piece of information that exists. Its either a one or a zero. 1 NIBBLE: 0000 (4 BITS) V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE 7

Dept. of ECE

MPI LAB MANUAL

The nibble is four bits or half a byte. It has a maximum value of 15 (1111 = 15). This is the basis for the hexadecimal (base 16) number system which is used as it is far easier to understand. Hexadecimal numbers that begin with a letter are prefixed with a 0 (zero). 1 BYTE: 00000000 (equivalent with 2 NIBBLES or 8 BITS) A byte is 8 bits or 2 nibbles. A byte has a maximum value of FFh (255 decimal). A WORD is a 2 byte data. The maximum value that can be represented using a word is 65535. It is the obvious that if bigger number has to be represented, the necessary number of bites will increase.

TABLE 1: A Byte Diagram 1 (MSD) 1 0 0 1 0 1 1 (LSD)

Above, MSD means Most Significant Digit and LSD means Least Significant Digit. A word will be represented as below:

TABLE 2: A Word Diagram Most Significant Byte Least Significant Byte

In memory, bytes are stored one after another. Each one has an associated address. Often data needs more than one byte (every number greater then 256). Then we are going to use a word to represent this number. In 8086 programming, the Most Significant Byte is stored at higher address then LSB.

V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE

Dept. of ECE

MPI LAB MANUAL

2. INTRODUCTION TO TASM
INTRODUCTION:
The aim of this experiment is to introduce the student to assembly language programming and the use of the tools that he will need throughout the lab experiments. This first experiment let the student use the Dos Debugger and the Turbo Assembler (TASM). Editing, Assembling, Linking, Execute up can be done using TASM software

OBJECTIVES:
1. Introduction to Turbo Assembler (TASM) 2. General structure of an assembly language program 3. Use of the Dos Debugger program

OVERVIEW:
In general, programming of microprocessor usually takes several iterations before the right sequence of machine code instruction is written. The process, however is facilitated using a special program called an Assembler. The Assembler allows the user to write alphanumeric instructions. The Assembler, in turn, generates the desired machine instructions from the assembly language instructions.

Assembly language programming consists of following steps:


STEP Editing Assembling Linking Executing PRODUCES Source file Object file Executable file Results

1 2 3 4

Table1.1: Assembly Language Programming Phases

ASSEMBLER:
The assembler is used to convert the assembly language instructions to machine code. It is used immediately after writing the Assembly language program. The assembler starts by checking the syntax or validity of the structure of each instruction in the source file .if any errors are found, the assemblers displays a report on these errors along with brief explanation of their nature. However if the program does contain any errors, the assembler produces an object file that has the same name as the original file but with the obj extension

V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE

Dept. of ECE

MPI LAB MANUAL

LINKER:
The Linker is used convert the object file to an executable file. A linker is a program used to join several object files in to one large object file and convert to an executable file. The linker produces a link file which contains the binary codes for all the combined modules. The linker however doesnt assign absolute address to the program it assigns is said to be relocatable because it can be put any where in memory to be run.

EXECUTING THE PROGRAM:


The executable contains the machine language code .it can be loaded in the RAM and executed by the microprocessor simply by typing ,from the DOS prompt ,the name of the file followed by the carriage Return Key (Enter Key). If the program produces an output on the screen or sequence of control signals to control a piece of hard ware, the effect should be noticed almost immediately. However, if the program manipulates data in memory, nothing would seem to have happened as a result of executing the program.

DEBUGGER:
The debugger can also be used to find logical errors in the program. Even if a program does not contain syntax errors it may not produce the desired results after execution. Logical errors may be found by tracing the action of the program. Once found, the source file should be rewrite to fix the problem, then the re-assembled and re-linked. A special program called the debugger is designed for that purpose. The debugger allows the user to trace the action of the program, by single stepping through the program or executing the program up to a desired point, called break point. It also allows the user to inspect or change the contents of the microprocessor internal registers or the contents of any memory location.

V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE

10

Dept. of ECE

MPI LAB MANUAL

3. PROCEDURE TO ENTER A PROGRAM USING TASM SOFTWARE:


Start Run Type CMD Ok Display shows C :\> D: (Change to D drive because MASM is in D drive) Press ENTER D :\> CD TASM Press ENTER D: \TASM> EDIT Press ENTER Then the display shows the main menu.

V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE

11

Dept. of ECE

MPI LAB MANUAL

Create A file name with .asm extension Ex: Filename.asm Write the program in assemble language then Save and Quit It returns to DOS Prompt Use the following Commands D: \TASM> tasm filename.asm It is for viewing errors and warnings report exist in the asm file(refer Assembler)

D: \TASM> tlink filename.obj The assembler produces an object file that has the same name as the original file but with the obj extension

V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE

12

Dept. of ECE

MPI LAB MANUAL

D: \TASM> td filename.exe It is for viewing the output window

Click Run and Click View It shows the output for Corresponding Inputs

V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE

13

Dept. of ECE

MPI LAB MANUAL

4. EXAMPLE FOR ASSEMBLE LANGUAGE PROGRAM


The assembly language program can be divided in to two parts 1. Data Segment 2. Code Segment In the data segment all the input, output and count (for loop programs) have to specify. This section starts with Data Segment and ends with Data Ends

Example: DATA SEGMENT NUM1 NUM2 RESULT DB RESULT1 DB DATA ENDS

DB DB 00 00

04H 02H

In the code segment remaining the entire program with specified instructions are present Example: CODE SEGMENT START: MOV AX, DATA MOV DS, AX MOV AL, NUM1 MOV BL, NUM2 MUL BL MOV RESULT, AL MOV RESULT1, AH INT 3 CODE ENDS

V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE

14

Dept. of ECE

MPI LAB MANUAL

5. EXECUTION OF PROGRAM THROUGH TRAINER KIT


Procedure For Executing Assembly Language Programs In 8086 By Using 8086 Trainer Kit: Procedure: Step1: After entering the data in to memory locations by using the known procedure then the display shows [blinking cursor] Step2: Type G starting address Ex: G 2000 Step3: Then [press] enter Step4: Then the display shows registers with results Step5: To see results locations, press D 4000 [4000 is the address of the memory location where the result is stored D is the command for displaying the data in memory locations] Step6: Then press enter. Step7: Then the display shows the data in 4000 location. Step8: If we want to substitute Different inputs for the same locations, press S 3000 [3000 is the address of the memory location where the input data is stored S is the command for substituting the data in memory locations]

V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE

15

Dept. of ECE

MPI LAB MANUAL

6. TRAINER KIT PROGRAMMES


ARITHMETIC OPERATIONS
1. ADDITION OF N 8 BIT NUMBERS
AIM: To write a program to add N 8 bit numbers. APPARATUS: 8086 microprocessor trainer kit, power supply ALGORITHM: Step1: Initialize AX// load SI with 3000h memory location Step2: Move the contents of SI in to the CL registers [counter] Step3: Increment SI [first number of n number] Step 4: Move the first number of n number in to BL Step 5: Add AL& BL Step6: If jump on no carry go to the step8 else step7 Step7: Increment AH Step8: Decrement CL [count] Step9: If jump on no zero go to the step 3 Step10: Load DI with 4000h memory location {to store the Result} Step11: Move the result in to DI Step 12: End of the program PROGRAM: MOV AX, 0000H MOVSI, 3000H MOV CL, [SI] INC SI MOV BL, [SI] ADD AL, BL JNC GO INC AH DEC CL JNZ BACK MOV DI, 4000H MOV [DI], AX 16

BACK:

G0:

V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE

Dept. of ECE

MPI LAB MANUAL

INT 03 OBSERVATIONS: Input: S3000: 03 S3001: 02 Output: D4000:09 S3002:03 S3003:04 Output D4000: Input S3000: S3001: S3002: S3003:

RESULT: Thus the addition of n 8 bit numbers is performed and results are observed using 8086 microprocessor trainer kit. VIVA QUESTIONS: 1. What is Microprocessors 2. What are the functions of Accumulator? 3. MOV BL, [SI] which Addressing mode? 4. Basic Difference between 8085 and 8086

V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE

17

Dept. of ECE

MPI LAB MANUAL

2. MULTI BYTE ADDITION


AIM: To write a program to add two multibyte numbers. APPARATUS: 8086 microprocessor trainer kit, power supply. ALGORITHM: Step1: initialize AX// load SI with 3000h memory location Step2: load DI with 4000h memory location Step3: load the CX register with count 03 Step4: move the first byte of first number [SI] in to AL Step5: move the first byte of second number [DI] in to DL Step6: add AL&DL with carry Step7: move the contents of AL in to DI Step8: increment SI Step9: increment DI Step10: move the second byte of first number [SI] in to AL Step11: move the second byte of second number [DI] in to DL Step12: add AL&DL with carry Step13: move the contents of AL in to DI Step14: decrement CX and jump to the step 8 if the CX register is Non zero Step15: end of the program PROGRAM: MOV AX, 0000H MOV SI, 3000H MOV DI, 4000H MOV CX, 03 MOV AL, [SI] MOV DL, [DI] ADC AL, DL MOV [DI], AL INC SI INC DI MOV AL, [SI] MOV DL, [DI] ADC AL, DL MOV [DI], AL 18

BACK:

V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE

Dept. of ECE

MPI LAB MANUAL

LOOP BACK INT 03

OBSERVATIONS: Input: S3000 S3001 S3002 S3003 10 20 30 40 S4000 S4001 S4002 S4003 20 30 40 50 Output: D4000 D4001 D4002 D4003 30 50 70 90 Input: S3000 S3001 S3002 S3003

S4000 S4001 S4002 S4003

Output: D4000 D4001 D4002 D4003

RESULT: Multi byte addition is performed and results are observed using TASM.

VIVA QUESTIONS 1. 2. 3. 4. Why 8085 processor is called an 8-bit processor What is the disadvantage of microprocessor? What is the difference between ADD & ADC What is the purpose served by CX register? 19

V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE

Dept. of ECE

MPI LAB MANUAL

3. MULTIBYTE SUBTRACTION
AIM: To write a program to subtract multibyte numbers APPARATUS: 8086 microprocessor trainer kit, power supply ALGORITHM: Step1: initialize AX// load SI with 3000h memory location Step2: load DI with 4000h memory location Step3: load the CX register with count 03 Step4: move the first byte of first number [SI] in to AL Step5: move the first byte of second number [DI] in to DL Step6: subtract AL from DL with borrow Step7: move the contents of AL in to DI Step8: increment SI Step9: increment DI Step10: move the second byte of first number [SI] in to AL Step11: move the second byte of second number [DI] in to DL Step12: subtract AL from DL with borrow Step13: move the contents of AL in to DI Step14: decrement CX and jump to the step 8 if the CX register is Non zero Step15: end of the program PROGRAM: MOV AX, 0000H MOV SI, 3000H MOV DI, 4000H MOV CX, 03 MOV AL, [SI] MOV DL, [DI] SBB AL, DL MOV [DI], AL INC SI INC DI MOV AL, [SI] MOV DL, [DI] SBB AL, DL MOV [DI], AL 20

BACK:

V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE

Dept. of ECE

MPI LAB MANUAL

LOOP BACK INT 03

OBSERVATIONS: Input: S3000 S3001 S3002 S3003 50 80 50 40 S4000 S4001 S4002 S4003 20 30 40 20 Output: D4000 D4001 D4002 D4003 30 50 10 20 Input: S3000 S3001 S3002 S3003 S4000 S4001 S4002 S4003 Output: D4000 D4001 D4002 D4003

RESULT: Thus multibyte subtraction is performed and results are observed using 8086 microprocessor kit

V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE

21

Dept. of ECE

MPI LAB MANUAL

4. MULTIPLICATION OF 16 BIT NUMBER


AIM: To write a program to multiply two 16 bit numbers APPARATUS: 8086 trainer kit, power supply ALGORITHM: Step1: initialize AX, DX load SI with 3000h memory location Step2: move the contents [SI] in to AX Step3: increment SI Step4: increment SI Step5: move the contents [SI] in to BX Step6: multiply the contents of BX with AX Step7: move the contents of AX to the 4000h memory location Step8: move the contents of DX to the 5000h memory location Step9: end of the program PROGRAM: MOV AX, 0000 MOV DX, 0000 MOV SI, 3000 MOV AX, [SI] INC SI INC SI MOV BX, [SI] MUL BX MOV @4000, AX MOV @5000, DX INT 03 OBSERVATIONS: Input: S3000 S3001 S3002 S3003 02 01 02 01 Output: D4000 D4001 D5000 D5001 04 04 01 00 Input: S3000 S3001 S3002 S3003 Output: D4000 D4001 D5000 D5001

V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE

22

Dept. of ECE

MPI LAB MANUAL

RESULT: Thus multiplication of a 16 bit numbers is performed and results are observed using 8086 microprocessor kit

V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE

23

Dept. of ECE

MPI LAB MANUAL

5. DIVISION OF 16 BIT NUMBER


AIM: To write a program to perform division of two 16 bit numbers APPARATUS: 8086 trainer kit, power supply ALGORITHM: Step1: initialize AX, DX load SI with 3000h memory location Step2: move the contents [SI] in to AX Step3: increment SI Step4: increment SI Step5: move the contents [SI] in to BX Step6: divide the contents of BX with AX Step7: move the contents of AX to the 4000h memory location Step8: move the contents of DX to the 5000h memory location Step9: end of the program PROGRAM: MOV AX, 0000 MOV DX, 0000 MOV SI, 3000 MOV AX, [SI] INC SI INC SI MOV BX, [SI] DIV BX MOV @4000, AX MOV @5000, DX INT 03 OBSERVATIONS: Input: S3000 S3001 S3002 S3003 04 00 02 00 Output: D4000 D4001 D5000 D5001 02 00 00 00 Input: S3000 S3001 S3002 S3003 Output: D4000 D4001 D5000 D5001

V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE

24

Dept. of ECE

MPI LAB MANUAL

RESULT: Thus division of a two 16 bit numbers is performed and results are observed using 8086 microprocessor kit

V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE

25

Dept. of ECE

MPI LAB MANUAL

6. FACTORIAL OF A GIVEN NUMBER


AIM: To write a program to find factorial of a given number APPARATUS: 8086 trainer kit, power supply ALGORITHM: Step1: initialize ax, bx. Step2: load SI with 3000h memory location Step3: move the contents [SI] in to AL Step4: move the contents of AX in to BX Step5: decrement BX Step6: multiply the contents of BX with AX Step7: decrement BX and jump to the step 6 if the BX register is Non zero Step8: move the contents of AX to the 4000h memory location Step9: end of the program PROGRAM: MOV AX, 0000H MOV BX, 0000H MOV SI, 3000H MOV AX, [SI] MOV BX, AX DEC BX MUL BX DEC BX JNZ BACK MOV @4000, AX INT 03

BACK:

OBSERVATIONS: Input: S3000: 05 Output: D4000: 78 Input: S3000: Output: D4000:

V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE

26

Dept. of ECE

MPI LAB MANUAL

RESULT: Thus factorial of a given number is performed and results are observed using 8086 microprocessor kit.

V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE

27

Dept. of ECE

MPI LAB MANUAL

7. TASM PROGRAMMES
ARITHMETIC OPERATION
1. MULTI BYTE ADDITION
AIM: To write a program to add two multi byte numbers. APPARATUS: Computer system installed with TASM. ALGORITHM:

Step1: initialize the data segment. Step2: load cx with counter Step3: load the si first number Step4: load the first byte of num1 (si) into al Step5: add the first byte of num1 (si) and first byte of num2 (si) with carry Step6: move the result into num3 (si) Step7: decrement si Step8: decrement count Step9: jump if not zero to step4 Step10: end of the program

PROGRAM:

ASSUME CS: CODE, DS: DATA DATA SEGMENT NUM1 DB 11H,22H,33H,44H,55H,66H,77H,88H NUM2 DB 11H,22H,33H,44H,55H,66H,77H,88H NUM3 DB ? DATA ENDS CODE SEGMENT START: MOV AX, DATA MOV DS, AX CLC MOV CL, 08 MOV SI, 0007 BACK: MOV AL, NUM1 [SI] ADC AL, NUM2 [SI] MOV NUM3 [SI], AL V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE 28

Dept. of ECE

MPI LAB MANUAL

DEC SI DEC CL JNZ BACK INT 3 CODE ENDS END START

OBSERVATION: (Theoretical) INPUT: NUM1=11h,22h,33h,44h,55h,66h,77h,88h NUM2=11h,22h,33h,44h,55h,66h,77h,88h RES=22h,44h,66h,88h,AAH,CCH,EFH,10H

OUTPUT:

MEMORY LOCATIONS: Input: DS: 0000h:11H 0001h: 22H 0002h: 33H 0003h: 44h 0004h: 55H 0005H: 66H 0006h: 77H 0007h: 88H 0008h: 11H 0009h: 22H 000Ah:33H 000Bh:44H 000Ch:55H 000DH:66H 000Eh:77H 000Fh:88H 0015H: CCH 0016h: EFH 0017h: 10H

OUTPUT: DS: 0010h: 22H 0011h: 44H 0012h: 66H 0013h: 88H 0014h: AAH

OBSERVATION: (practical): INPUT: NUM1= NUM2= OUTPUT: RES=

Memory Locations: Input: ds: 0000h: V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE

0001h: 29

Dept. of ECE

MPI LAB MANUAL

0002h: 0003h: 0004h: 0005H: 0006h: 0007h: 0008h: OUTPUT :DS:0010h: 0011h: 0012h: 0013h:

0009h: 000Ah: 000Bh: 000Ch: 000DH: 000Eh: 000Fh: 0014h: 0015H: 0016h: 0017H:

V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE

30

Dept. of ECE

MPI LAB MANUAL

2. MULTI BYTE SUBTRACTION


AIM: To write a program to subtract two multi byte numbers. APPARATUS: ALGORITHM: STEP1: Initialize the data segment STEP2: Load CX with counter STEP3: Load the SI first number STEP4: Load the first byte of num1(SI) into AL STEP5: subtract the first byte of num1(SI) and first byte of num2(SI) With borrow STEP6: move the result into num3(SI) STEP7: Decrement SI STEP8: Decrement count STEP9: Jump if not zero to step4 STEP10: End of the program Computer system installed with TASM

PROGRAM: ASSUME CS:CODE,DS:DATA DATA SEGMENT NUM1 DB 88H,77H,66H,55H,44H,33H,22H,11H NUM2 DB 11H,22H,33H,44H,11H,22H,11H,11H NUM3 DB ? DATA ENDS CODE SEGMENT START: MOV AX,DATA MOV DS,AX CLC MOV CL,08 MOV SI,0007 BACK: MOV AL,NUM1[SI] SBB AL,NUM2[SI] MOV NUM3[SI],AL DEC SI DEC CL V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE 31

Dept. of ECE

MPI LAB MANUAL

JNZ BACK INT 3 CODE ENDS END START

OBSERVATION: (Theoretical) INPUT: NUM1=88H,77H,66H,55H,44H,33H,22H,11H NUM2=11H,22H,33H,44H,11H,22H,11H,11H RES=77h,55h,33h,11h,33H,11H,11H,00H

OUTPUT: Memory Locations:

0000h: 0001h: 0002h: 0003h: 0004h: 0005: 0006h: 0007h: OUTPUT:DS: 0010h: 0011h: 0012h: 0013h: 0014h: 0015h: 0016h: 0017h: OBSERVATION: (practical): INPUT: NUM1= NUM2= OUTPUT: RES=

Input: DS:

0008h: 0009h: 000Ah: 000Bh: 000Ch: 000Dh: 000Eh: 000Fh:

V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE

32

Dept. of ECE

MPI LAB MANUAL

Memory Locations: INPUT: DS: 0000h: 0001h: 0002h: 0003h: 0004h: 0005H: 0006h: 0007h: 0008h: 0009h: 000Ah: 000Bh: 000Ch: 000DH: 000Eh: 000Fh:

OUTPUT: DS: 0010h: 0011h: 0012h: 0013h: 0014h: 0015H: 0016h: 0017h: RESULT: Multi byte subtraction is performed and results are observed using TASM

EXERCISE: 1. Why is subtract with carry instruction is used in the loop? 2. What is the purpose served by BX register? 3. Why subtraction is done with AL register why not with AX? 4. What is the other instruction which can be used instead of MOV DI, offset NUM2?

V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE

33

Dept. of ECE

MPI LAB MANUAL

3. 8 BIT MULTIPLICATION (UNSIGNED)


AIM: To write a program to multiply two 8-bit unsigned numbers. APPARATUS: ALGORITHM: STEP1: Initialize the data segment STEP2: Load the AL with NUM1 STEP3: Load the BL with NUM2 STEP4: Multiply AL & BL (Unsigned) STEP5: Store the result in AL and AH STEP6: End of the program PROGRAM: ASSUME CS: CODE, DS: DATA DATA SEGMENT NUM1 DB 04H NUM2 DB 02H RESULT DB 00 RESULT1 DB 00 DATA ENDS CODE SEGMENT START: MOV AX, DATA MOV DS, AX MOV AL, NUM1 MOV BL, NUM2 MUL BL MOV RESULT, AL MOV RESULT1, AH INT 3 CODE ENDS END START Computer system installed with TASM

V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE

34

Dept. of ECE

MPI LAB MANUAL

OBSERVATION: (theoretical) INPUT: NUM1=04h NUM2=02h

RES=08h RES1=00h MEMORY LOCATIONS: INPUT: DS: 0000h: 04H 0001h: 02h OUTPUT: DS: 0002h: 08H 0003h: 00h OBSERVATION: INPUT: NUM1= NUM2= RES= RES1=

OUTPUT:

OUTPUT:

MEMORY LOCATIONS: INPUT: DS: 0000h: 0001h: OUTPUT: DS: 0002h: 0003h: RESULT: 8-bit unsigned multiplication is performed and results are observed using TASM. EXERCISE: 1. AL and BL are used for multiplying why not AX & BX? 2. Instead of using MOV BL is it not possible to MUL num2? 3. What is the instruction used for signed multiplication? V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE 35

Dept. of ECE

MPI LAB MANUAL

4. 8-BIT MULTIPLICATION (SIGNED)


AIM: To write a program to multiply two 8-bit signed numbers. APPARATUS: ALGORITHM: STEP1: Initialize the data segment STEP2: Load the AL with NUM1 STEP3: Load the BL with NUM2 STEP4: Multiply AL & BL (signed) STEP5: Store the result in AL and AH STEP6: End of the program PROGRAM: DATA SEGMENT NUM1 DB 0A5H NUM2 DB 20H RES DW ? DATA ENDS CODE SEGMENT ASSUME CS:CODE,DS:DATA START: MOV AX,DATA MOV DS,AX SUB AX,AX MOV AL,NUM1 MOV BL,NUM2 IMUL BL MOV RES,AX INT 3 CODE ENDS END START Computer system installed with TASM

V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE

36

Dept. of ECE

MPI LAB MANUAL

OBSERVATION: (theoretical) INPUT: OUTPUT: NUM1=A5h NUM2=20h RES=A0 F4h

OBSERVATION: (practical): INPUT: NUM1= NUM2= RES=

OUTPUT:

RESULT: 8-bit signed multiplication is performed and results are observed using TASM. VIVA QUESTIONS: 1. What is the difference between IMUL and MUL? 2. What is the use of instruction CBW? 3. What is the use of instruction CWD?

V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE

37

Dept. of ECE

MPI LAB MANUAL

5. 16 BIT MULTIPLICATION (UNSIGNED)

AIM: To write a program to multiply two 16-bit unsigned numbers. APPARATUS: ALGORITHM: STEP1: Initialize the data segment STEP2: Load the AX with NUM1 STEP3: Load the BX with NUM2 STEP4: Multiply AX & BX(Unsigned) STEP5: Store the result in AX and DX STEP6: End of the program PROGRAM: ASSUME CS: CODE, DS: DATA DATA SEGMENT NUM1 DW 0004H NUM2 DW 0002H RESULT DW 00 RESULT1 DW 00 DATA ENDS CODE SEGMENT START: MOV AX,DATA MOV DS,AX MOV AX,NUM1 MOV BX,NUM2 MUL BX MOV RESULT,AX MOV RESULT1,DX INT 3 CODE ENDS END START Computer system installed with TASM

V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE

38

Dept. of ECE

MPI LAB MANUAL

OBSERVATION: (theoretical) INPUT: OUTPUT: NUM1=0004h NUM2=0002h RES=0008h RES1=0000h

MEMORY LOCATIONS: INPUT: DS: 0000h:04H 0001h:00h 0002h:02H 0003h:00h OUTPUT: DS: 0004:08h 0005:00h 0006:00h 0007:00h OBSERVATION: (PRACTICAL): INPUT: OUTPUT: NUM1= NUM2= RES= RES1=

MEMORY LOCATIONS: INPUT: DS: 0000h: 0001h: 0002h: 0003h: OUTPUT: DS: 0004h: 0005h: 0006h: 0007h: RESULT: 16-bit Multiplication is performed and results are observed using TASM.

V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE

39

Dept. of ECE

MPI LAB MANUAL

EXERCISE: 1. Why AL & BL are not used in this program? 2. If result exceeds 32 bit, where is it stored?

V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE

40

Dept. of ECE

MPI LAB MANUAL

6. 8 BIT DIVISION (UNSIGNED)


AIM: To write a program to perform division on two 8-bit unsigned numbers. APPARATUS: Computer system installed with TASM ALGORITHM: STEP1: Initialize the data segment and AX, BX registers STEP2: Load the AL with NUM1(Divisor) STEP3: Load the BL with NUM2(Dividend) STEP4: divide AL & BL(Unsigned) STEP5: Store the result in AL(quotient) and AH(remaider) STEP6: End of the program PROGRAM: ASSUME CS: CODE, DS: DATA DATA SEGMENT NUM1 DB NUM2 DB QUOTIENT DB REMAINDER DB DATA ENDS CODE SEGMENT START: MOV AX,DATA MOV DS,AX MOV AX,0000h MOV DX,0000h MOV AL,NUM1 MOV BL,NUM2 DIV BL MOV QUOTIENT,AL MOV REMAINDER,AH INT 3 CODE ENDS END START

04H 02H ? ?

V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE

41

Dept. of ECE

MPI LAB MANUAL

OBSERVATION: (THEORETICAL) INPUT: OUTPUT: NUM1=04h NUM2=02h QUEO=02h REM=00h

MEMORY LOCATIONS: INPUT: DS: 0000h: 04H 0001h: 02h OUTPUT: DS: 0002:02h 0003:00h OBSERVATION: (PRACTICAL): INPUT: NUM1= NUM2= OUTPUT: RES= RES1= MEMORY LOCATIONS: INPUT: DS: 0000h: 0001h: OUTPUT: DS: 0002: 0003: RESULT: Division of two 8-bit numbers is performed and results are observed using TASM. EXERCISE: 1. Why is the registers DX & AX made zero in the above program? 2. Where is the remainder in 8 bit division? 3. Where is the quotient in 8 bit division? 4. Which interrupt is used when a divide overflow error occurs? V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE 42

Dept. of ECE

MPI LAB MANUAL

7. 8-BIT DIVISION (SIGNED)


AIM: To write a program to perform division on two 8-bit signed numbers. APPARATUS: ALGORITHM: STEP1: Initialize the data segment and AX, BX registers STEP2: Load the AL with NUM1(Divisor) STEP3: Load the BL with NUM2(Dividend) STEP4: divide AL & BL(signed) STEP5: Store the result in AL(quotient) and AH(remainder) STEP6: End of the program PROGRAM: DATA SEGMENT NUM1 DB 0D5H NUM2 DB 20H QUO DB ? REM DB ? DATA ENDS CODE SEGMENT ASSUME CS:CODE,DS:DATA START: MOV AX,DATA MOV DS,AX XOR AX,AX MOV AL,NUM1 MOV BL,NUM2 IDIV BL MOV QUO,AL MOV REM,AH INT 3 CODE ENDS END START OBSERVATION: (THEORETICAL) V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE 43 Computer system installed with TASM

Dept. of ECE

MPI LAB MANUAL

INPUT: OUTPUT:

NUM1=D5h NUM2=20h QEO= FFh REM= F5h

OBSERVATION: (PRACTICAL): INPUT: NUM1= NUM2= OUTPUT: QEO= REM=

RESULT: 8-bit signed division is performed and results are observed using TASM.

EXERCISE: 1. What is the purpose of XOR AX,AX? 2. What is the difference between IDIV and DIV? 3. What is the use of instruction CBW & CWD?

V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE

44

Dept. of ECE

MPI LAB MANUAL

8. 16 BIT DIVISION (UNSIGNED)


AIM: To write a program to perform division on two 16-bit unsigned numbers. APPARATUS: ALGORITHM: STEP1: Initialize the data segment and AX, DX registers STEP2: Load the AX with NUM1(Divisor) STEP3: Load the BX with NUM2(Dividend) STEP4: divide AX & BX(Unsigned) STEP5: Store the result in AX(quotient) and DX(remainder) STEP6: End of the program PROGRAM: ASSUME CS: CODE, DS: DATA DATA SEGMENT NUM1 DW NUM2 DW QUOTIENT DW REMAINDER DW DATA ENDS CODE SEGMENT START: MOV AX,DATA MOV DS,AX MOV AX,0000 MOV DX,0000 MOV AX,NUM1 MOV BX,NUM2 DIV BX MOV QUOTIENT,AX MOV REMAINDER,DX INT 3 CODE ENDS END START Computer system installed with TASM

0004H 0002H ? ?

V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE

45

Dept. of ECE

MPI LAB MANUAL

OBSERVATION: (theoretical) INPUT: OUTPUT: NUM1=0004h NUM2=0002h QUEO=0002h REMA=0000h

OBSERVATION: (practical): INPUT: NUM1= NUM2= OUTPUT: RES= RES1= RESULT: 16-bit division is performed and results are observed using TASM.

EXERCISE: 1. What happens if DX register contains a nonzero value before DIV instruction? 2. What is the instruction used for signed division? 3. In the above program instead of DIV BX is it possible to use DIV num2?

V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE

46

Dept. of ECE

MPI LAB MANUAL

9. LARGEST OF A GIVEN NUMBER


AIM: To write a program to find largest number from a given unordered array of 16 bit numbers. APPARATUS: 8086 trainer kit, power supply ALGORITHM: Step1: initialize ax// load si with 3000h memory location step2: load the cx register with count 03 step3: move the contents [si] in to al step3: compare the contents of [si] with al step4: jump if not less to the step6 step5: move the contents [si] in to al step6: increment si step7: increment si step8: decrement cl step9: jump on non zero to the step3 step10: move the contents of ax to the 4000h memory location step11: end of the program PROGRAM: Assume cs:code, ds:data Data segment Count db 01h,03h,02h,04h Data ends Code segment Start: Mov ax,data Mov ds,ax Mov ax,0000h Mov si,0000h Mov cl,04h Mov al,num1[si] Back: Inc si Cmp al,[si] Jnl next Mov ax,[si] Next: Dec cl Jnz back V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE 47

Dept. of ECE

MPI LAB MANUAL

Mov num1[si],al Int 03 Code ends End start

OBSERVATIONS: Input:

Input:

Output:

Output:

RESULT: Thus largest number from given numbers are found and results are observed using trainer kit.

V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE

48

Dept. of ECE

MPI LAB MANUAL

10. ASCII ADDITION


AIM: To write a program to perform ASCII addition. APPARATUS: ALGORITHM: STEP1: Initialize the data segment STEP2: Load the DL with the NUM1 STEP3: Load the DH with NUM2 STEP4: ANDed DL & DH with 0FH STEP5:Move the DX into AX STEP6:Add the AH & AL STEP7:Ascii Adjust After ADDITION STEP8:ORed AL,AH with 30H and store the result STEP9: End of the program PROGRAM: ASSUME CS: CODE,DS:DATA DATA SEGMENT NUM1 DB 36H NUM2 DB 32H RES DW 00H DATA ENDS CODE SEGMENT START: MOV AX,DATA MOV DS,AX XOR AX,AX MOV DL,NUM1 MOV DH,NUM2 AND DL,0FH AND DH,0FH MOV AX,DX ADD AL,AH MOV AH,00 AAA V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE 49 Computer system installed with TASM

Dept. of ECE

MPI LAB MANUAL

OR AL,30H OR AH,30H MOV RES,AX INT 03H CODE ENDS END START OBSERVATIONS:(Theoretical) INPUT: NUM1=36H NUM2=32H RES=38H 30H

OUTPUT:

OBSERVATION: (practical) INPUT: NUM1= NUM2= OUTPUT: RES= RESULT: ASCII addition is performed and results are observed using TASM.

EXERCISE: 1. What is the purpose of ASCII addition? 2. What is the instruction used for ASCII addition? 3. Why do we make use of instruction ORL AX, 3030H ? 4. Why is AAA after addition?

V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE

50

Dept. of ECE

MPI LAB MANUAL

11. ASCII SUBTRACTION


AIM: To write a program to perform ASCII subtraction. APPARATUS: ALGORITHM: STEP1: Initialize the data segment STEP2: Load the DL with the NUM1 STEP3: Load the DH with NUM2 STEP4: ANDed DL & DH with 0FH STEP5:Move the DX into AX STEP6:Subtract the AH & AL STEP7:Ascii Adjust After subtraction STEP8:ORed AL,AH with 30H and store the result STEP9: End of the program PROGRAM: ASSUME CS:CODE,DS:DATA DATA SEGMENT NUM1 DB 36H NUM2 DB 32H RES DW 00H DATA ENDS CODE SEGMENT START: MOV AX,DATA MOV DS,AX XOR AX,AX MOV DL,NUM1 MOV DH,NUM2 AND DL,0FH AND DH,0FH MOV AX,DX SBB AL,AH MOV AH,00 AAS OR AL,30H V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE 51 Computer system installed with TASM

Dept. of ECE

MPI LAB MANUAL

OR AH,30H MOV RES,AX INT 03H CODE ENDS END START OBSERVATIONS:(Theoretical) INPUT: NUM1=36H NUM2=32H RES=34H 30H

OUTPUT:

MEMORY LOCATIONS: Input: ds: 0000h:36H 0001h:32H output: ds: 0002:34H 0003:30H

OBSERVATION: (practical) INPUT: NUM1= NUM2= OUTPUT: RES= MEMORY LOCATIONS: Input: ds: 0000h: 0001h: output: ds: 0002h: 0003h:

RESULT: ASCII subtraction is performed and results are observed using TASM.

V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE

52

Dept. of ECE

MPI LAB MANUAL

EXERCISE: 1. What is the purpose of ASCII subtraction? 2. What is the instruction used for ASCII subtraction? 3. Why do we make use of instruction ORL AX,3030H ? 4. Why is AAS after addition?

V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE

53

Dept. of ECE

MPI LAB MANUAL

8. LOGIC OPERATIONS 1. CHECK WHETHER A GIVEN 16-BIT NUMBER IS EVEN OR ODD


AIM: To write a program to check whether a given 16-bit number is even or odd. APPARATUS: ALGORITHM: STEP1: Initialize the data segment STEP2: Load the AX with the NUM1 STEP3: Load the BX with 0002H(NUM2) STEP4: Divide AX & BX STEP5:Compare CX & DX STEP6:Jump on even step9 STEP7:Load AX with 1111H(ODD NUMBER) STEP8:Jump to step 10 STEP9: Load the AX with FFFFH(EVEN NUMBER) STEP10:End of the program. PROGRAM: ASSUME CS:CODE,DS:DATA DATA SEGMENT NUM1 DW 0008H DATA ENDS CODE SEGMENT START: MOV AX,DATA MOV DS,AX MOV AX,NUM1 MOV BX,0002H MOV CX,0000H DIV BX CMP CX,DX JE EVEN MOV AX,1111H JMP NEXT EVEN: MOV AX,FFFFH V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE 54 Computer system installed with TASM

Dept. of ECE

MPI LAB MANUAL

NEXT: INT 03H CODE ENDS END START

OBSERVATIONS:(Theoritical) INPUT: NUM1=0008H

OUTPUT:

AX=FFFFH BX=0002H

OBSERVATION: (practical) INPUT: OUTPUT: NUM1= AX= BX=

RESULT: Checking whether a given 16-bit number is even or odd is performed and results are observed using Tasm.

V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE

55

Dept. of ECE

MPI LAB MANUAL

2. CHECK WHETHER A GIVEN 16-BIT NUMBER IS POSITIVE OR NEGATIVE


AIM: To write a program to check whether a given 16-bit number is positive or negative. APPARATUS: ALGORITHM: STEP1: Initialize the data segment STEP2: Load the AX with the NUM1 STEP3: Rotate the contents of AX by one through carry STEP4:Jump on carry (negative number) go to step6 STEP5:Load the AX with FFFFH (if positive number) STEP6:Jump to step8 STEP7:Load AX with 1111H(negative number) STEP8:End of the program. PROGRAM: ASSUME CS:CODE,DS:DATA DATA SEGMENT NUM1 DW 0002H DATA ENDS CODE SEGMENT START: MOV AX,DATA MOV DS,AX MOV AX,NUM1 ROL AX,01H JC NEG_NUM MOV AX,FFFFH JMP EXIT NEG_NUM:MOV AX,1111H EXIT: INT 3 CODE ENDS END START V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE 56 Computer system installed with TASM

Dept. of ECE

MPI LAB MANUAL

OBSERVATIONS:(Theoritical) INPUT: NUM1=0008H

OUTPUT:

AX=FFFFH BX=0000H

OBSERVATION: (practical) INPUT: OUTPUT: NUM1= AX= BX=

RESULT: Checking whether a given 16-bit number is positive or negative is performed and results are observed using TASM.

EXERCISE: 1. How can we differentiate between a positive number and a negative number?

V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE

57

Dept. of ECE

MPI LAB MANUAL

3. SORTING (ASCENDING)
AIM: To write a program to sort a given list of numbers in ascending order. APPARATUS: ALGORITHM: STEP1: Initialize the data segment STEP2: Initialize the count in DX Register STEP3: Load DX with count STEP4: move DX into the CX Register STEP5: Load the SI with first byte of List STEP6:Move the content of SI into AX register STEP7:Compare AXwith second byte of SI STEP8: Jump if Less to the step11 STEP9:Exchage AX and second byte of SI STEP10: Exchage AX and first byte of SI STEP11:Add SI with 02 STEP12:continue the loop until to get the result and go to the step7 STEP13:Decrement DX STEP14:Jump if non zero to the step 4 STEP15:END of the program PROGRAM: ASSUME CS:CODE,DS:DATA DATA SEGMENT LIST DW 53H,25H,89H,02H COUNT EQU 04H DATA ENDS CODE SEGMENT START:MOV AX,DATA MOV DS,AX MOV DX,COUNT MOV CX,DX MOV SI,OFFSET LIST MOV AX,[SI] CMP AX,[SI+02] JL NEXT XCHG [SI+02],AX 58 Computer system installed with TASM

AGAIN0: AGAIN1:

V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE

Dept. of ECE

MPI LAB MANUAL

XCHG [SI],AX NEXT: ADD SI,02H LOOP AGAIN1 DEC DX JNZ AGAIN0 MOV AH,4CH INT 03 CODE END END START OBSERVATIONS:(Theoritical) INPUT: LIST=53H,25H,89H,02H

OUTPUT: LIST=02H,25H,53H,89H MEMORY LOCATIONS: OUTPUT:DS: 0000H:00h 0001H:00h 0002H:02h 0003H:00h 0004H:25h 0005H:00h 0006H:53h 0007H:00h 0008H:89h OBSERVATIONS:(practical) INPUT: LIST=

OUTPUT: LIST= MEMORY LOCATIONS: OUTPUT:DS: 0000H: 0001H: 0002H: 0003H: 0004H: 0005H: 0006H: 0007H: 0008H: V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE 59

Dept. of ECE

MPI LAB MANUAL

RESULT: Sorting of a given list of numbers is performed and results are observed using TASM.

EXERCISE: 1. What is the sorting technique used in above program? 2. Are there any other ways to sort a list?

V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE

60

Dept. of ECE

MPI LAB MANUAL

4. SORTING (DESCENDING)
AIM: To write a program to sort a given list of numbers in descending order. APPARATUS: ALGORITHM: STEP1: Initialize the data segment STEP2: Initialize the count in DX Register STEP3: Load DX with count STEP4: move DX into the CX Register STEP5: Load the SI with first byte of List STEP6:Move the content of SI into AX register STEP7:Compare AXwith second byte of SI STEP8: Jump if Greater to the step11 STEP9:Exchage AX and second byte of SI STEP10: Exchage AX and first byte of SI STEP11:Add SI with 02 STEP12:continue the loop until to get the result and go to the step7 STEP13:Decrement DX STEP14:Jump if non zero to the step 4 STEP15:END of the program PROGRAM: ASSUME CS:CODE,DS:DATA DATA SEGMENT LIST DW 53H,25H,89H,02H COUNT EQU 04H DATA ENDS CODE SEGMENT START: MOV AX,DATA MOV DS,AX MOV DX,COUNT AGAIN0: MOV CX,DX MOV SI,OFFSET LIST AGAIN1: MOV AX,[SI] CMP AX,[SI+02] JG NEXT V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE 61 Computer system installed with TASM

Dept. of ECE

MPI LAB MANUAL

XCHG [SI+02],AX XCHG [SI],AX NEXT:ADD SI,02H LOOP AGAIN1 DEC DX JNZ AGAIN0 MOV AH,4CH INT 03 CODE END END START OBSERVATIONS:(Theoritical) INPUT: LIST=53H,25H,89H,02H

OUTPUT: LIST=89H,53H,25H,02H MEMORY LOCATIONS: OUTPUT:DS: 0000H:00h 0001H:00h 0002H:89h 0003H:00h 0004H:53h 0005H:00h 0006H:25h 0007H:00h 0008H:02h OBSERVATIONS:(practical) INPUT: LIST=

OUTPUT: LIST= MEMORY LOCATIONS: OUTPUT:DS: 0000H: 0001H: 0002H: 0003H: 0004H: 0005H: 0006H: V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE 62

Dept. of ECE

MPI LAB MANUAL

0007H: 0008H: RESULT: Sorting of a given list of numbers is performed and results are observed using TASM. EXERCISE: 1. What is the sorting technique used in above program? 2. Are there any other ways to sort a list?

V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE

63

Dept. of ECE

MPI LAB MANUAL

5. PACKED TO UNPACKED BCD


AIM: To write a program to convert a packed BCD number to unpacked BCD number. APPARATUS: ALGORITHM: STEP1: Initialize the data segment STEP2: Load AL with BCDIP & store into the DL STEP3: ANDed the AL with 0F0H STEP4:Load the 04 into into CL STEP5:Rotate accumulator contents by 04 through carry ane moved into the BH STEP6: ANDed the DL with 0F0H and moved into BL STEP7:Store the result STEP8:End of the program PROGRAM: DATA SEGMENT BCDIP DB 56H UBCDOP DW 0 DATA ENDS CODE SEGMENT ASSUME CS:CODE,DS:DATA START: MOV AX,DATA MOV DS,AX XOR AX,AX MOV AL, BCDIP MOV DL,AL AND AL,0F0H MOV CL,4 ROR AL,CL MOV BH,AL AND DL,0FH MOV BL,DL MOV UBCDOP,BX V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE 64 Computer system installed with TASM

Dept. of ECE

MPI LAB MANUAL

INT 3 CODE ENDS END START

OBSERVATIONS:(Theoretical) INPUT: BCDIP=56H

OUTPUT: UBCDOP=06H 05H MEMORY LOCATIONS: Input: ds: 0000h:56h output: ds: 0001h:06h 0002h:05h OBSERVATIONS:(practical) INPUT: OUTPUT: BCDIP= UBCDOP=

MEMORY LOCATIONS: Input: ds: 0000h: output: ds: 0001h: 0002h:

RESULT: Conversion of packed BCD to unpacked BCD is performed and results are observed using TASM.

EXERCISE: 1. What is the purpose of the instruction ROR AL, CL? 2. What is the purpose of the instruction AND AL, 0FH & AND AL,0F0H in the program.? 3. What is the expansion of UPBCD? V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE 65

Dept. of ECE

MPI LAB MANUAL

4. What is the use of DAA instruction? 5. What is the reason for packing unpacked BCD? 6. What is common between unpacked BCD and ASCII?

V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE

66

Dept. of ECE

MPI LAB MANUAL

6. BCD to ASCII CONVERSION


AIM: To write a program to convert a BCD number to its equivalent ASCII number. APPARATUS: ALGORITHM: STEP1: Initialize the data segment STEP2: Load AL with BCDIP & store into the DL STEP3:ORed the AL with 30H STEP4:Store the result STEP5:End of the program PROGRAM: ASSUME CS:CODE, DS:DATA DATA SEGMENT BCDIP DB ASCOP DB 00 DATA ENDS CODE SEGMENT START: MOV AX,DATA MOV DS,AX XOR AX,AX MOV AL, BCDIP OR AL,30H MOV ASCOP,AL INT 3 CODE ENDS END START Computer system installed with TASM

04H

OBSERVATIONS:(Theoretical) INPUT: OUTPUT: BCDIP=04H ASCOP=34H

V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE

67

Dept. of ECE

MPI LAB MANUAL

MEMORY LOCATIONS: Input: ds: 0000h:04h output: ds: 0001h:34H OBSERVATIONS:(practical) INPUT: OUTPUT: BCDIP= ASCOP=

MEMORY LOCATIONS: Input: ds: 0000h: output: ds: 0001h:

RESULT: Conversion of BCD to ASCII is performed and results are observed using TASM.

EXERCISE: 1. What is the difference between adding 30h and OR 30H to a BCD number to conversion to ASCII? 2. Why unpacking is necessary during the conversion? 3. What is the ASCII character for symbol A? 4. What is the ASCII character for symbol zero 0?

V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE

68

Dept. of ECE

MPI LAB MANUAL

9. STRING OPERATIONS 1. LENGTH OF THE STRING


AIM: To write a program to find the length of the given string. APPARATUS: ALGORITHM: Step1:Initialize the data segment Step2: Initialize si and di Step:3 Take the count as 0000h Step4: Move the character of the string to al reg. Step5: compare the al contents with dl ( the data in dl is 00h) If zero flag is set goto step6 else goto step 8 Step6: increment the count value and increment the si Step7: jump to step4 Step8: move the count value to output Step9: end of the program. PROGRAM: Assume cs:code, ds:data Data segment String1 db VKR String2 db ? Data ends Code segment Start: Mov ax,data Mov ds,ax Mov ax,0000h Mov si,0000h Mov cl,00h Mov dl,00h Up: Mov al,string1[si] Mov dl,00h Cmp al,dl Je Up1 Inc cl V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE 69 Computer system installed with TASM

Dept. of ECE

MPI LAB MANUAL

Inc si Jmp Up Mov String2[si],al Up1: Int 03 Code ends End start

OBSERVATIONS:(Theoretical) INPUT: STRING=KAKINADA OUTPUT: K=6BH A=61H K=6BH I=69H N=6EH A=61H D=64H A=61H MEMORY LOCATIONS: output: ds: 0000h:6BH 0001h:61H 0002h:6BH 0003h:69H 0004h:6EH 0005h:61H 0006h:64H 0007h:61H

OBSERVATIONS:(practical) OUTPUT: STRING=

MEMORY LOCATIONS: output: ds: 0000h: 0001h: V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE 70

Dept. of ECE

MPI LAB MANUAL

0002h: 0003h: 0004h: 0005h: 0006h: 0007h: RESULT: Length of a string is performed and results are observed using TASM. EXERCISE: 1. What is the operation performed by the instruction cmp al,$ ? 2. What is function 09h / int 21h performed? 3. Why SI is not been incremented is the program?

V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE

71

Dept. of ECE

MPI LAB MANUAL

2 BLOCK TRANSFER
AIM: To write a program to transfer a block of characters from one place to another place using string instructions. APPARATUS: ALGORITHM: STEP1: Initialize the data segment and ES STEP2: Load SI with first number (num1) STEP3: Load DI with first number (num2) STEP4: Load the count into CL STEP5: clear the direction flag and transfer the string of bytes into Respective memory locations STEP6: End of the program PROGRAM: ASSUME CS:CODE, DS:DATA DATA SEGMENT NUM1 DB 11H,22H,33H,44H,55H,66H,77H,88H NUM2 DB 01H,02H,03H,04H,05H,06H,07H,08H COUNT EQU 08H DATA ENDS CODE SEGMENT START: MOV AX, DATA MOV DS, AX MOV ES, AX MOV SI, OFFSET NUM1 MOV DI, OFFSET NUM2 MOV CL, COUNT CLD REP MOVSW INT 03H CODE ENDS END START Computer system installed with TASM

V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE

72

Dept. of ECE

MPI LAB MANUAL

OBSERVATIONS:(Theoretical) INPUT: NUM1:11H,22H,33H,44H,55H,66H,77H,88H NUM2:01H,02H,03H,04H,05H,06H,07H,08H OUTPUT: NUM1: 11H,22H,33H,44H,55H,66H,77H,88H MEMORY LOCATIONS: OUTPUT: DS: 0000h:11H 0001h:22H 0002h:33H 0003h:44H 0004h:55H 0005h:66H 0006h:77H 0007h:88H

OBSERVATIONS:(PRACTICAL) INPUT: NUM1: NUM2: OUTPUT: NUM1: MEMORY LOCATIONS: OUTPUT: DS: 0000h: 0001h: 0002h: 0003h: 0004h: 0005h: 0006h: 0007h: RESULT: Block transfer is performed and results are observed using TASM.

V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE

73

Dept. of ECE

MPI LAB MANUAL

EXERCISE: 1. If the DF=1, will the SI and DI register decremented? 2. The destination memory is pointed by which register combination? 3. The source is pointed to by which register combination?

V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE

74

Dept. of ECE

MPI LAB MANUAL

3 STRING COMPARISION
AIM: To write a program to Compare the two strings. APPARATUS: ALGORITHM: STEP1: Initialize the data segment and ES STEP2: Load CL with first count (string1) STEP3: Load CL with first count (string2) STEP4: Compare CL &CH (string1 & string2) STEP5: Jump if non zero to the step18 STEP6:load the first string character into AL STEP7:load the second string character into BL STEP8: Jump if non zero to the step18 STEP9:load the first string character into AL STEP10:load the second string character into BL STEP11:Compare the strings STEP12: Jump if non zero to the step18 STEP13:Increment SI STEP14:Decrement CL &CH STEP15: Jump if non zero to the step6 STEP17:load the AX with 0000h STEP18: Jump to the step20 STEP19:load the AX with1111h STEP20: End of the program PROGRAM: Assume cs:code, ds:data Data segment Count1 db 04h Count2 db 04h String1 db JNTU String2 db JNTU Data ends Code segment Start: Mov ax,data Mov ds,ax V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE 75 Computer system installed with TASM

Dept. of ECE

MPI LAB MANUAL

Mov cl,count1 Mov ch,count2 Cmp ch,cl Jnz Below Mov si,0000h Up: Mov al,string1[si] Mov bl,string2[si] Cmp al,bl Jnz Below Inc si Dec cl Dec ch Jnz Up Jmp Below1 Below: Mov ax,0000h Jmp exit Below1: Mov ax,1111h Exit: Int 03 Code ends End start OBSERVATIONS:(Theoretical) INPUT: STRING1 =JNTU STRING2=KAKINADA OUTPUT: AX:1111H MEMORY LOCATIONS: OUTPUT: DS: 0000h:04H 0001h:04H 0002h:4AH:J 0003h:4EH:N 0004h:54H:T 0005h:55H:U 0006h:4BH:K 0007h:41H:A 0008h:4BH:K 0009h:49H:I 000Ah:4EH:N 000Bh:41H:A V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE 76

Dept. of ECE

MPI LAB MANUAL

000Ch:44H:D 000Dh:41H:A OBSERVATIONS:(Practical) INPUT: STRING1 = STRING2= OUTPUT :AX:1111H

MEMORY LOCATIONS: OUTPUT: DS: 0000h: 0001h: 0002h: 0003h: 0004h: 0005h: 0006h: 0007h: 0008h:

0009h: 000Ah: 000Bh: 000Ch: 000Dh:

RESULT: compare the two strings are performed and results are observed using TASM.

V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE

77

Dept. of ECE

MPI LAB MANUAL

4 STRING REVERSAL
AIM: To write a program to reverse a given string. APPARATUS: ALGORITHM: STEP1: Initialize the data segment and ES STEP2: Initialize SI &DI STEP3: Load BX with count STEP4: move the BL into DL STEP5: Jump if non zero to the step18 STEP6:load the first string character into AL STEP7:load the second string character into BL STEP8: Jump if non zero to the step18 STEP9:load the first string character into AL STEP10:load the second string character into BL PROGRAM: Assume cs:code, ds:data Data segment Count dw 0003h String1 db VKR String2 db ? Data ends Code segment Start : Mov ax,data Mov ds,ax Mov si,0000h Mov di,0000h Mov bx,count Mov cl,04h Up: Mov al,String1[si+bx] Mov String2[di],al Inc di Dec bx Jnz Up Int 03 V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE 78 Computer system installed with TASM

Dept. of ECE

MPI LAB MANUAL

Code ends End start

OBSERVATIONS:(Theoretical) INPUT: OUTPUT: STRING1=KAKINADA STRING2=ADANIKAK

MEMORY LOCATIONS: INPUT:DS: 0000H:K=6BH 0001H:A=61H 0002H:K=6BH 0003H:I=69H 0004H:N=6EH 0005H:A=61H 0006H:D=64H 0007H:A=61H OBSERVATIONS:(practical) INPUT: OUTPUT: STRING1= STRING2=

OUTPUT:DS: 0008H:A=61H 0009H:D=64H 000AH:A=61H 000BH:N=6EH 000CH:I=69H 000DH:K=6BH 000EH:A=61H 000FH:K=6BH

MEMORY LOCATIONS: INPUT:DS: 0000H 0001H 0002H 0003H OUTPUT:DS: 0008H 0009H 000AH 000BH 000CH RESULT:

= = = = = = = = =

0004H 0005H 0006H 0007H

= = = =

000DH = 000EH = 000FH =

String reversal is performed and results are observed using TASM. V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE 79

Dept. of ECE

MPI LAB MANUAL

EXERCISE: 1. Why BX register is added with 5? 2. Why MOVS instruction is not used? 3. What is the function of LODS and STOS instructions?

V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE

80

Dept. of ECE

MPI LAB MANUAL

5. STRING INSERTION
AIM: To write a program to insert a word in the given sentence. APPARATUS: ALGORITHM: STEP1: Initialize the data segment STEP2: Initialize the SI Register with 0000 STEP3: Load DL with Location STEP4: Initialize the DI Register with 0000 STEP5: Move the content of LEN into the CL register STEP6:Compare DX with SI Register STEP7: Jump if Equal to the step18 STEP8: Move the content of String1 into the AL register STEP9:Move the content of AL into the String2 of DI Register STEP10: Decrement CL and increment SI,DI STEP11:Jump to STEP6 STEP12:Move the content of ELEMENT into the AL register STEP13:Move the AL into DI STEP14:Increment DI STEP15:Move the SI into AL and AL into DL STEP16: Increment SI STEP17: Continue the loop until to get result STEP18:End of the program PROGRAM: Assume cs:code, ds:data Data segment String1 db GUDVADA String2 db ? Element db I Len db 08h Location db 03h Data ends Code segment Start: Mov ax,data 81 Computer system installed with TASM

V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE

Dept. of ECE

MPI LAB MANUAL

Mov ds,ax Mov si,0000h Mov dl,Location Mov di,0000h Mov cl,len Up: Cmp dx,si Je down Mov al,string1[si] Mov string2[di],al Dec cl Inc si Inc di Jmp Up Down: Mov al,element Mov string2[di],al Up1: inc di Mov al,string1[si] Mov string2[di],al Inc si Loop Up1 Int 03 Code ends End start OBSERVATIONS:(Theoretical) INPUT: STRING1=RAJASKAR ELEMENT=E STRING2=RAJASEKAR

OUTPUT:

MEMORY LOCATIONS: INPUT:DS: 0000H:R=52H 0001H:A=41H 0002H:J=4AH 0003H:A=41H 0004H:S=53H 0005H:K=4BH 0006H:A=41H 0007H:R=52H V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE 82

Dept. of ECE

MPI LAB MANUAL

OUTPUT:DS: 0008H:R=52H 0009H:A=41H 000AH:J=4AH 000BH:A=41H 000CH:S=53H 000DH:E=45H 000EH:K=4BH 000FH:A=41H 0010H:R=52H

OBSERVATIONS:(practical)

INPUT:

STRING1= ELEMENT= STRING2=

OUTPUT:

MEMORY LOCATIONS: INPUT:DS: 0000H 0001H 0002H 0003H 0004H 0005H 0006H 0007H OUTPUT:DS: 0008H 0009H 000AH 000BH 000CH 000DH 000EH 000FH

= = = = = = = = = = = = = = = =

V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE

83

Dept. of ECE

MPI LAB MANUAL

RESULT: String insertion is performed and results are observed using TASM.

EXERCISE: 1. Why register DI is loaded with 5? 2. What is the function of rep movsb? 3. What is the purpose of mov ah,01h / int 21h?

V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE

84

Dept. of ECE

MPI LAB MANUAL

6. STRING DELETION
AIM: To delete a word from the given sentence. APPARATUS: ALGORITHM: STEP1: Initialize the data segment STEP2: Initialize the SI Register with 0000 STEP3: Load CL with counter STEP4: Load DH with counter 1 STEP5: Move the content of String1 into the AL register STEP6: Compare AL and DL STEP7 Jump on zero to step15 STEP8:Increment CH and SI STEP9: Compare CL and CH STEP10:Jump if non zero to step5 STEP11:Subtract DH and CL STEP12:Move the SI into AL and AL into DL STEP13: Increment SI and decrement DH STEP14:Jump if non zero to step12 STEP15:End of the program PROGRAM: Assume cs:code, ds:data Data segment String1 db GUDIVADA String2 db ? Count1 db 04h Data ends Code segment Start: Mov ax,data Mov ds,ax Mov si,0000h Mov ch,00h Mov cl,count1 Mov dh,count1 85 Computer system installed with TASM

V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE

Dept. of ECE

MPI LAB MANUAL

Mov dl,00h Up1: Mov al,string1[si] Cmp al,dl Jz Below Inc ch Inc si Cmp cl,ch Jnz Up1 Sub dh,cl Up2: Mov al,string1[si] Mov string2[si],al Inc si Dec ch Jnz Up2 Below: int 03h Code ends End start

OBSERVATIONS:(Theoretical) INPUT: OUTPUT: STRING1=KAKINADA STRING2=NADA

MEMORY LOCATIONS: INPUT:DS: 0000H:K=4BH 0001H:A=41H 0002H:K=4BH 0003H:I=49H 0004H:N=4EH 0005H:A=41H 0006H:D=44H 0007H:A=41H

OUTPUT:DS: 000EH:N=4EH 000FH:A=41H V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE 86

Dept. of ECE

MPI LAB MANUAL

0010H:D=44H 0011H:A=41H

OBSERVATIONS:(practical) INPUT: OUTPUT: STRING1= STRING2=

MEMORY LOCATIONS: INPUT:DS: 0000H: 0001H: 0002H: 0003H: 0004H: 0005H: 0006H: 0007H:

OUTPUT:DS: 000EH: 000FH: 0010H: 0011H:

RESULT: String deletion is performed and results are observed using TASM. EXERCISE: 1. What is the purpose of string length? 2. What does equ stands for? 3. What is the purpose of label start after the end directive?

V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE

87

Dept. of ECE

MPI LAB MANUAL

7. READING KEYBOARD WITH ECHO

AIM: To write a program to read the keyboard with echo. APPARATUS: ALGORITHM: STEP1: Initialize the data segment STEP2: Move 01 into AL STEP3: Initialize DOS STEP4: Move AL into address STEP5: End of the program PROGRAM: DATA SEGMENT CHAR DB 0 DATA ENDS CODE SEGMENT ASSUME CS:CODE, DS:DATA START: MOV AX,DATA MOV DS,AX MOV AH,01H INT 21H MOV CHAR, AL INT 3 CODE ENDS END START OBSERVATIONS: INPUT: N Computer system installed with TASM

OUTPUT:N

V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE

88

Dept. of ECE

MPI LAB MANUAL

RESULT: Reading a keyboard is performed and results are observed using TASM. EXERCISE: Write a brief note on DOS interrupts. 2. What does AH register hold when INT 21H is called?
1.

V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE

89

Dept. of ECE

MPI LAB MANUAL

8. READING KEYBOARD WITHOUT ECHO

AIM: To write a program to read the keyboard without echo. APPARATUS: ALGORITHM: STEP1: Initialize the data segment STEP2: Move 08 into AL STEP3: Initialize DOS STEP4: Move AL into address STEP5: End of the program PROGRAM: DATA SEGMENT CHAR DB 0 DATA ENDS CODE SEGMENT ASSUME CS:CODE, DS:DATA START: MOV AX,DATA MOV DS,AX MOV AH,08H INT 21H MOV CHAR, AL INT 3 CODE ENDS END START OBSERVATIONS: INPUT: OUTPUT: RESULT: Reading a keyboard is performed and results are observed using TASM. V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE 90 Computer system installed with TASM

Dept. of ECE

MPI LAB MANUAL

EXERCISE: Write a brief note on DOS interrupts. 2. What does AH register hold when INT 21H is called?
1.

V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE

91

Dept. of ECE

MPI LAB MANUAL

9. DISPLAYING A CHARACTER
AIM: To write a program to displaying a given string. APPARATUS: ALGORITHM: STEP1: Initialize the data segment STEP2: Move 08 into AL STEP3: Initialize DOS STEP4: Move AL into address STEP5: End of the program PROGRAM: DATA SEGMENT CHAR DB DATA ENDS Computer system installed with TASM

CODE SEGMENT ASSUME CS: CODE, DS: DATA START: MOV AX, DATA MOV DS, AX MOV AH, 02H MOV DL,CHAR INT 21H MOV AX, 4C00H INT 21H CODE ENDS END START OBSERVATIONS: INPUT: OUTPUT: RESULT:

V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE

92

Dept. of ECE

MPI LAB MANUAL

Displaying a character on screen is performed and results are observed using TASM. EXERCISE: 1. Write a brief note on DOS interrupts. 2. What does AH register hold when INT 21H is called?

V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE

93

Dept. of ECE

MPI LAB MANUAL

10. DISPLAYING A STRING


AIM: To write a program to displaying a given string. APPARATUS: ALGORITHM: STEP1: Initialize the data segment STEP2: Load DX with the string STEP3: Initialize DOS STEP4: End of the program PROGRAM: ASSUME CS: CODE, DS: DATA DATA SEGMENT STRING DB 'HAPPY NEW YEAR', 0DH, 0AH,'$' DATA ENDS CODE SEGMENT START: MOV AX, DATA MOV DS, AX LEA DX, STRING MOV AH, 09H INT 21H CODE ENDS END START OBSERVATIONS: INPUT: HAPPY NEW YEAR Computer system installed with TASM

OUTPUT: HAPPY NEW YEAR

RESULT: Displaying a string on screen is performed and results are observed using TASM. V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE 94

Dept. of ECE

MPI LAB MANUAL

EXERCISE: 1. Write a brief note on DOS interrupts. 2. What does AH register hold when INT 21H is called?

V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE

95

Dept. of ECE

MPI LAB MANUAL

V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE

96

Dept. of ECE

MPI LAB MANUAL

1. 8255 PPI INTERFACING -1


AIM: Configure 8255A such that port A and port B as an output ports .Execute the program at 0000:2000h APPARATUS: 1. 8086 TRAINER KIT 2. 8255 STUDY CARD 3. ADAPTER, KEYBOARD, CABLES, ETC PROGRAM: // DAC FOR ADC INTERFACE // Connect the interface over J4 of the trainer // This program illustrates the use of counter method for A/D conversion // The program can be executed in Standalone or Serial Mode // Execute the program from 2000H OUTPUT 2500AD ORG 2000H MOV AX,00H MOV CS,AX MOV ES,AX

//INITIALISE SEGMENT REGISTERS

MOV SP,3000H //INITIALISE STACK POINTER CALL FAR 0FE00:0031H //NEWLINE MOV DX,0FFE6H //INITIALISE 8255 AS FOLLOWS MOV AL,81H //PORT A = OUTPUT OUT DX,AL //PORT C = INPUT JMP SHORT START TEST: DB 0DH,20H,'CONVERTING... ', 00H MES: DB 0AH,0DH,20H, 'DIGITAL VALUE = ',00H START: MOV DX,0FFE4H IN AL,DX CALL DELAY CALL DELAY AND AL,02H JZ START //wait for start of conversion(SOC)

V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE

97

Dept. of ECE

MPI LAB MANUAL

MOV AX,0FFH PUSH AX CONT: MOV DX,0FFE4H //check for SOC IN AL,DX CALL DELAY AND AL,02H JNZ START //If true start again POP AX //else continue MOV DX,0FFE0H INC AL //increment count and OUT DX,AL //output to port PUSH AX PUSH DX LEA DX,TEST //display 'converting...' MOV AX,DX POP DX CALL FAR 0FE00:0013H CALL DELAY MOV DX,0FFE4H //read comparator output IN AL,DX AND AL,00000001B JNZ CONT //if PC0=1,continue else LEA DX,MES //conversion is over MOV AX,DX CALL FAR 0FE00:0013H //display message POP AX CALL FAR 0FE00:0052H //DISPLAY OUTPUT CALL FAR 0FE00:0031H JMP SHORT START DELAY: MOV CX,8000H HERE: LOOP HERE RET END //delay routine

V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE

98

Dept. of ECE

MPI LAB MANUAL

OBSERVATIONS: INPUT: OUTPUT:

RESULT: 8086 Interfacing with 8255 is done and results are observed.

V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE

99

Dept. of ECE

MPI LAB MANUAL

2. 8279 KEYBOARD/DISPLAY INTERFACING


AIM: To interface keyboard/display with 8086 microprocessor and display a given sentence on the display board.(Left Entry) APPARATUS: 1. 8086 TRAINER KIT 2. 8279 STUDY CARD 3. ADAPTER, KEYBOARD, CABLES, ETC PROGRAM: CMDREG DATAREG EQU 0FFEBH EQU 0FFE9H

.8086 .MODEL TINY .STACK 32 .DATA .CODE ORG 2000H START: MOV AX,CS MOV DS,AX MOV AL,10H // ENCODED SCAN-8CHAR 8 BIT LEFT ENTRY MOV DX,CMDREG OUT DX,AL MOV AL,090H //WRITE RAM AUTO INCREMENT OUT DX,AL MOV CX,08 CLEAR:MOV AL,00 MOV DX,DATAREG OUT DX,AL LOOP CLEAR BACK: MOV DX,CMDREG IN AL,DX // READ THE COMMAND R4EGISTER TO GET THE 8279 STATUS

V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE

100

Dept. of ECE

MPI LAB MANUAL

AND AL,07 // NUMBER OF KEYS PRESSED IS IN THE LOWER 3 BITS MASK //THESE AND CHECK IF NOT ZERO. IF ZERO NO KEY PRESSED JZ BACK MOV BX,OFFSET SSCHARLUT MOV AL,040H // READ THE FIRST RAM ADDRESS OF FIFO OUT DX,AL MOV DX,DATAREG // IN AL, DX AND AL,01FH XLAT // CONVERT THE KEY READ TO THE SS CODE MOV DX,DATAREG OUT DX,AL // DISPLAY AT THE CURRENT DIGIT POSITION JMP BACK SSCHARLUT: SS0 DB 3FH //0 SS1 DB 6H //1 SS2 DB 5BH //2 SS3 DB 4FH //3 SS4 DB 66H //4 SS5 DB 6DH //5 SS6 DB 7DH //6 SS7 DB 07H //7 SS8 DB 7FH SS9 DB 6FH SSA DB 77H SSB DB 7CH SSC DB 39H SSD DB 5EH SSE DB 79H SSF DB 71H END START OBSERVATIONS: INPUT:

V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE

101

Dept. of ECE

MPI LAB MANUAL

OUTPUT: RESULT: 8086 Interfacing with 8279 is done and results are observed.

V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE

102

Dept. of ECE

MPI LAB MANUAL

3. 8259 PROGRAMMABLE INTERUPT CONTROLLER


AIM: To interface Programmable Interrupt Controller with 8086 microprocessor. APPARATUS: 1. 8086 TRAINER KIT 2. 8259 STUDY CARD 3. ADAPTER, KEYBOARD, CABLES, ETC PROGRAM: ORG 1000H MOV AL,17H OUT 0C0H, AL MOV AL,08H OUT 0C2H, AL MOV AL,01H OUT 0C2H, AL MOV AL,FEH OUT 0C2H, AL STI HERE: JMP HERE MOV AL,20H LOOP 0C0H,AL INT 02H Interrupt Vector:0000:0200 00h 0000:0021 12h 0000:0022 00h 0000:0023 00h OBSERVATIONS: INPUT: OUTPUT:

V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE

103

Dept. of ECE

MPI LAB MANUAL

RESULT: 8086 Interfacing with 8279 is done and results are observed.

V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE

104

Dept. of ECE

MPI LAB MANUAL

4. 8251 USART
AIM: To interface USART (Universal Synchronous Asynchronous Receiver Transmitter) with 8086 microprocessor. APPARATUS: 1 2 3 PROGRAM: TRANSMITTER END: ORG 1000H MOV AL,36H OUT 0CEH, AL MOV AL,10H OUT 0C8H, AL MOV AL,00H OUT 0C8H, AL MOV AL,4EH OUT 0C2H, AL MOV AL,37H OUT 0C2H, AL LOOP1:IN AL,0C2H AND AL,04H JZ LOOP1 MOV AL,41H OUT 0C0H,AL INT 02H RECEIVER END: ORG 1200H MOV AL,36H OUT 0CEH, AL MOV AL,10H OUT 0C8H, AL MOV AL,00H V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE 105 8086 TRAINER KIT 8251 STUDY CARD ADAPTER, KEYBOARD, CABLES, ETC

Dept. of ECE

MPI LAB MANUAL

OUT 0C8H, AL MOV AL,4EH OUT 0C2H, AL MOV AL,37H OUT 0C2H, AL LOOP2:IN AL,0C2H AND AL,04H JZ LOOP2 IN AL,0C0H MOV BX,I500H MOV [BX],AL INT 02H

OBSERVATIONS: INPUT: OUTPUT:

RESULT: 8086 Interfacing with 8279 is done and results are observed.

V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE

106

Dept. of ECE

MPI LAB MANUAL

V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE

107

Dept. of ECE

MPI LAB MANUAL

Expected Questions from Microprocessors


1. Who Invented 8086 microprocessor? 2. In which year 8086 microprocessor is invented? 3. How many address lines are available on 8086? 4. How many data lines are available on 8086? 5. Why address bus is unidirectional? 6. Whether data bus is unidirectional or bidirectional? 7. What is a bus? 8. If AL=0FFh and ADD AL,01h instruction is executed, what is the status of status flags? 9. Under what condition bus contention occurs? 10. How can you avoid bus contention? 11. The segment 1234h and offset is 0022h, then the physical address is? 12. If an instruction is accessed by 8086 is 20ms, the time taken by 8088 is? 13. The no. of cycles required by 8086 for writing/reading to/from memory/IO ports is? 14. Whether 8086 contains internal clock generator? 15. 8086 requires external clock signal with a duty cycle of? 16. In 8086 the lower bank of 8086 contains? 17. When ready pin of 8086 is at logic 0 then wait states are 18. The vectored interrupt in 8086 is? 19. Non vectored interrupt in 8086 is? 20. To restart from the initial state when 1 is placed on 8086 RESET pin, the duration for which the signal must present is? 21. The rate of transmission in serial mode is? 22. In serial I/O, data transmission takes place using which code? 23. USART converts data from which form to which from? 24. The inputs and outputs of 8251 are compatible with which logic? 25. Whether RS232C is compatible with TTL Logic? 26. If TxD output remains high the 8251 contains which characters? 27. In RS232C, RS stands for? 28. In RS 232C standard uses positive logic or negative logic? 29. Which transmission is used for high speed serial data transmission? 30. Expand DCE and DTE? 31. Which type of ADC is the fastest one? 32. Which type of ADC is the most expensive one? 33. Which type of ADC used DAC inside? 34. How many comparators are required by an 8-bit flash type ADC? V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE 108

Dept. of ECE

MPI LAB MANUAL

35. In 8259 if IR3, IR6, IR7 are activated, which interrupt has the highest priority? 36. Which register in 8259 is used to disable interrupt requests? 37. Which ports are used in BSR mode of 8255? 38. Which port provides hand shaking signals in Mode1 & Mode2 of 8255? 39. What is the IC used for DMA transfer? 40. How many peripherals can be connected to 8237 at any point of time? 41. For bidirectional data transfer, 8255 is operated in which mode? 42. DMA will send a request signal to which pin of 8086? 43. Which instruction is used to return from the interrupt service procedure? 44. What are the ICs MC 1488 and MC 1489? 45. When accessing a memory location shared with a coprocessor, the signal that prevents the coprocessor from accessing that location is? 46. There are two no. of 2Kx8 memory chips. How to obtain 4Kx8 memory? 47. When the processor has 32 address lines, how much memory can be interfaced to that processor? 48. Whether Stepper Motor is an AC Motor or DC Motor? 49. Give any application of Stepper Motor in our real life? 50. What do you mean by interfacing?

Expected Questions from Microcontrollers


1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19.

Who has introduced MCS-51 family of microcontrollers? MCS-51 family of microcontrollers contains which ICs? What is the difference between MP and MC? Give any Example of Microcontrollers? Is 8051 an 8-bit controller? Why 8051 is an 8-bit controller? What is the on chip ROM capacity of 8051? What is the on chip RAM capacity of 8051? How many IO ports are available on 8051 on chip? How many timers are available on 8051 on chip? Which version of 8051 doesnt have on chip ROM? Which version of 8051 contains EPROM on chip? 8051 contains which type of ROM? What is the purpose of ROM in 8051? What is the purpose of RAM in 8051? Whether ROM is accessible randomly or not? What is the capacity of on chip EPROM on 8751? Can you connect external program memory to 8051? Can you connect external data memory to 8051? 109

V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE

Dept. of ECE

MPI LAB MANUAL

20. What is the capacity of external program memory that can be connected to 8051? 21. What is the capacity of external data memory that can be connected to 8051? 22. How can you access internal program memory? 23. How can you access external program memory? 24. How is it possible to access both internal & external ROM using PC? 25. How can you access internal data memory? 26. How can you access external data memory? 27. Do you require any signal to access external data memory? 28. Do you require any signal to access external program memory? 29. What is the reason behind connecting only 64KB of external program memory? 30. What is the reason behind connecting only 64KB of external data memory? 31. Expand DPTR? 32. Is a DPTR an 8-bit register? 33. Can we access PC as two 8-bit registers? 34. Is there any register in 8086 similar to PC in 8051? 35. Expand SFR? 36. Is PC a special function register? 37. Whether external interrupts are edge triggered or level triggered type? 38. Expand ALE? 39. Expand PSEN? 40. What is the function of PSEN pin? 41. For serial communication the pins of which IO port is used? 42. Which register is used to operate 8051 in different modes? 43. What are the modes of operation of 8051? 44. Whether PCON is a bit addressable SFR? 45. Which port will hold the higher order address information during memory access? 46. Which Io port of 8051 doesnt have dual function? 47. What is the Architecture of 8051? 48. What is stack? 49. What is the function of SP register? 50. The number of clock cycles in one machine cycle of 8051 is?

V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE

110

Dept. of ECE

MPI LAB MANUAL

Key to the Questions on Microprocessors


1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. 30. 31. 32. 33. 34. Intel Corporation 1974 20 address lines 16 data lines The address bus is unidirectional because the information on the address bus is always provided by the microprocessor. Data bus is bidirectional. Bus is a collection of signal lines. Generally they carry address, data and control signals. CF=1, PF=1, AF=1, ZF=1, SF=0 and OF=0 Bus contention occurs when two outputs trying to drive the same line. Bus contention can be avoided by using tri-state condition which isolates one of the outputs. 12362h. 40ms. 4 clock cycles. No 33% duty cycle for its optimal functioning. Even address locations. Between T3 and T4 states. NMI. INTR. 4 clock cycles. Baud. ASCII. Parallel form to Serial. TTL Logic. No. No data (Stop bits). Recommended Standard. Negative logic. Synchronous transmission. DCE stands for Data Communications Equipment and DTE stands for Data Terminal Equipment. Flash type ADC. Successive Approximation ADC. Successive Approximation ADC. 8 Comparators. 111

V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE

Dept. of ECE

MPI LAB MANUAL

35. 36. 37. 38. 39. 40. 41. 42. 43. 44. 45. 46. 47. 48. 49. 50.

IR3. Interrupt Mask Register. Only Port C bits. Port C provides hand shaking signals. 8237 or 8257 Four Mode 2 HOLD pin. IRET. Voltage translators. LOCK By connecting address lines in serial and data lines parallel 232 = 4GB DC Motor Printers, X-Y plotters, Hard disk/Floppy Disk Drives, etc., Interfacing means not only connecting the devices but also communicating between them.

Key to the Questions on Microcontrollers


1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. Intel Corporation 8031, 8051, 8052, 8751 and 8752 Microcontrollers. MP contains ALU, Control Unit and On chip memory where as Microcontroller contains MP, ROM, RAM, IO Ports, Counters/Timers on chip. 8051 Yes Because all the internal registers and accumulator are of 8-bit wide and they can process 8-bit data. 4KB 128 bytes 4 no. of 8-bit IO Ports 2 no. of 16-bit Timers/Counters 8031 8751 Simple Read Only Memory ROM is used for storing Programs hence it is called as Program Memory. RAM is nothing but Data Memory and is used to store data Yes 4KB Yes 112

V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE

Dept. of ECE

MPI LAB MANUAL

19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29. 30. 31. 32. 33. 34. 35. 36. 37. 38. 39. 40. 41. 42. 43. 44. 45. 46. 47. 48. 49. 50.

Yes 64KB 64KB Program Counter Program Counter Whenever we access external program memory, we use MOVX instruction which distinguish the internal & external ROM. By means of its address in the program instructions. Data Pointer. Yes. We require Logic 0 on External Access pin. No signal is required to access external program memory. Because PC is a 16-bit register, the maximum memory that can be interfaced externally is 216 = 64KB only. DPTR is a 16-bit register// the maximum memory that can be interfaced externally is 216 = 64KB only. Data Pointer DPTR is a 16-bit register, but we can access it as two 8-bit registers DPH & DPL. No, we cant access PC as two 8-bit registers. PC is very similar to IP register in 8086. SFR stands for Special Function register. No, PC is the only register which doesnt come under SFR. They can be programmed as either edge triggered or level triggered. Address Latch Enable PSEN stands for Program Store ENable. PSEN is used to store program in external memory. Port 3 pins are used for serial communication. PCON (Power CONtrol) SFR is used. Power Down Mode and Idle Mode. No. PCON is not bit addressable. Port 2 will hold the higher order address information during memory access. Port 1 pins have no dual functions. The Architecture of 8051is called Harvard Architecture. Stack is an area in internal RAM that is used in conjunction with certain opcodes to store and retrieve data quickly. SP holds an internal RAM address that is called top of the stack. 12 clock cycles.

V.K.R, V.N.B & A.G.K ENGINEERING COLLEGE

113

You might also like