You are on page 1of 38

SATHYABAMA UNIVERSITY

DR.JEPPIAAR NAGAR, RAJIV GANDHI SALAI, CHENNAI - 600119

DEPARTMENT OF ELECTRONICS AND TELECOMMUNICATION ENGINEERING


LABORATORY MANUAL

SECX4031
MICROPROCESSOR INTERFACING & APPLICATIONS LAB

(AS PER SYLLABUS 2010-2014)

V SEMESTER, ETCE

Sathyabama University

Department of Electronics and Telecommunication Engineering

CONTENTS
SL. NO MP.1 MP.2 HANDOUTS LAB EXPERIMENT HANDOUT ANNEXURE P AGE NUMBER 3 33

SECX4031 MICROPROCESSORS INTERFACING & APPLICATIONS LAB (SYLLABUS) I. 8085 Programming 1. Study of 8085 Microprocessor 2. 8 bit Addition, Subtraction, Multiplication and Division. 3. 16 bit Addition, Subtraction. 4. BCD to Hex and Hex to BCD code conversion. 5. Largest and smallest of a given set of numbers. 6. Block Movement of Data. 7. Square Root of 8-bit number. II. 8086 Programming 1. Study of 8086 Microprocessor 2. 16 bit Addition, Subtraction, Multiplication and Division. 3. 32 bit Addition and Addition of 3x3 Matrices. 4. Ascending Order and Descending Order. 5. Reversal of a String. III. Interfacing Experiments 1. Keyboard and Display Interface 2. ADC Interface 3. DAC Interface 4. Stepper Motor Interface 5. Traffic Signal Modeling

RECORD NOTEBOOK / OBSERVATION WRITING FORMAT


LEFT HAND SIDE (UNRULED) FLOW CHART MANUAL CALCULATION RIGHT HAND SIDE (RULED) AIM APPARATUS NEEDED ALGORITHM PROCEDURE THEORY (ONLY IN RECORD) PROGRAM INPUT/ OUTPUT RESULT
2

Semester V

Microprocessor, Interfacing and Applications Laboratory-Manual,

Sathyabama University

Department of Electronics and Telecommunication Engineering

MP.1 LAB EXPERIMENT HANDOUT


LIST OF EXPERIMENTS (AS PER UNIVERSITY SYLLABUS) (100 Marks)

INDEX
Sl. No
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 2 2 2 2 3 3 3 3 3 1 1 1 1 1 1

Cycle

Exercise Number
S1.1 1.1 1.2 1.3 1.4 1.5 S2.1 2.1 2.2 2.3

Experiments
Study of 8085 Microprocessor 8 bit Addition, Subtraction, Multiplication and Division 16 bit Addition, Subtraction BCD to Hex and Hex to BCD code conversion Largest and smallest of a given set of numbers. Block Movement of Data.

Page Number
3 1-10 11 14-16 17-19 20-21 22 22-27 28-29 30-32 -

ASSIGNMENT Square Root of 8-bit number Study of 8086 Microprocessor 16 bit Addition, Subtraction, Multiplication and Division 32 bit Addition Ascending Order and Descending Order.

ASSIGNMENT Reversal of a String 3.1 3.2 3.3 3.4 3.5 Keyboard and Display Interface ADC Interface DAC Interface Stepper Motor Interface Traffic Signal Modeling

For Interfacing experiments (Exercise 3.1 to 3.5)- Respective Manuals shall be provided by Lab In-charges in the Laboratory.
Semester V Microprocessor, Interfacing and Applications Laboratory-Manual, 3

Sathyabama University

Department of Electronics and Telecommunication Engineering

8085 PROGRAMMING S1.1. STUDY OF 8085 PROCESSOR

8085 architecture diagram shall be drawn in the record and its functional units shall be described in detail.

Semester V

Microprocessor, Interfacing and Applications Laboratory-Manual,

Sathyabama University

Department of Electronics and Telecommunication Engineering

1.1. 8-BIT ADDITION, SUBTRACTION, MULTIPLICATION AND DIVISION 1.1 (a) ADDITION OF TWO EIGHT BIT NUMBERS (8085) AIM: To write and execute an assembly language program to perform the addition of two eight bit numbers using 8085 kit. ALGORITHM: Step 1 : Step 2 : Step 3 : Step 4 : Step 5 : Step 6 : Step 7 : Step 8 : Step 9 : Step 10 :

Start. Clear C register for carry Load the first data from memory to accumulator and move it to B register. Load the second data from memory to accumulator. Add the content of B register to the accumulator. Check for carry. If carry = 1, go to step 7 else if carry =0, go to step 8. Increment the C register. Store the sum in memory Move the carry to accumulator and store in memory End Program

Note: && - Sample Comment written and Comment to be written for all other programs
In this program Registers A, B C are used for Data Manipulation PROGRAM: Memory Address 8000 8002 Label Hex code 0E,00 3A, 00, 90 Instruction Mnemonic Operand MVI LDA C,00 9000

&& Comment

Clear C register for carry Load the first data from memory to accumulator 8005 47 MOV B,A Move the data to B register. 8006 3A, 01, 90 LDA 9001 Load the second data from memory to accumulator. 8009 80 ADD B Add the content of B register to the accumulator. 800A D2, 0E, 80 JNC 800E Check for carry. If carry = 1, (NO_CY) increment carry register else if carry =0 store the result 800D 0C INR C Increment the C register for carry 800E NO_CY: 32, 00, 95 STA 9500 Store the sum in memory 8011 79 MOV A,C Move the carry to accumulator 8012 32, 01, 95 STA 9501 Store Carry in memory 8015 CF RST 1 End the program Note: RST 1 can be replaced by HLT also to terminate the program. Hex code for HLT is 76. Do not type the labels for example :( NO_CY) in the assembler kit. NOT to write the operands given within brackets
Semester V Microprocessor, Interfacing and Applications Laboratory-Manual, 5

Sathyabama University

Department of Electronics and Telecommunication Engineering

MANUAL CALCULATION: (FOR THE INPUT USED AS DATA) BIT POSITION INPUT DATA 1 DATA 2 AE FD 8 1 + 7 1 1 1 6 1 0 1 5 1 1 1 4 1 0 1 3 1 1 1 2 1 1 1 1 0 0 0 1

OUTPUT

SUM CARRY

= =

AB 01

*** NOTE: This shall be considered as an example manual calculation and to be done done for all arithmetic or logical programs like exercise numbers 1.1, 1.2, 1.3, 2.1 & 2.2 by students. SAMPLE INPUT & OUTPUT: Before Execution Memory Data Address 9000 AE Augend 9001 FD Addend After Execution Memory Data Address 9500 AB Sum 9501 01 Carry

Addition: FD+AE=01AB RESULT: An assembly language program to perform addition of two eight bit numbers using 8085 is written and executed.

Semester V

Microprocessor, Interfacing and Applications Laboratory-Manual,

Sathyabama University

Department of Electronics and Telecommunication Engineering

1.1(b) SUBTRACTION OF TWO EIGHT BIT NUMBERS (8085) AIM: To write and execute an assembly language program to perform subtraction of two eight bit numbers using 8085 kit. ALGORITHM: Step 1 Step 2 Step 3 Step 4 Step 5 Step 6 Step 7 Step 8 Step 9 Step 10 PROGRAM: Memory Address 8000 8002 8005 8006 8009 800A 800D 800E 800F 8010 8013 8014 8017 Label Hex Code 0E, 00 3A, 00, 90 47 3A, 01, 90 90 D2, 0E, 80 0C 2F 3C 32, 01, 95 79 32, 02, 95 CF Instruction Operand Mnemonic MVI C,00 LDA 9001 MOV B,A LDA 9000 SUB B JNC 8010 (L1) INR C CMA INR A STA 9501 MOV A,C STA 9502 RST 1 : Start. : Clear C register to account for sign of the result. : Load the subtrahend (the data to be subtracted) from memory to accumulator and move it to B register. : Load the minuend from memory to accumulator. : Subtract the content of B register from the content of the accumulator. : Check for carry. If carry = 1, go to step 7 else if carry =0, go to step 8. : Increment the C register. Complement the accumulator and add 01H. : Store the difference in memory. : Move the content of C register (sign bit) to accumulator and store in memory. : End program

L1

SAMPLE INPUT & OUTPUT: Before Execution Memory Data Address 9000 AF Subtrahend 9001 EF Minuend Subtraction: EF-AF=40
Semester V Microprocessor, Interfacing and Applications Laboratory-Manual, 7

After Execution Memory Data Address 9501 40 Difference 9502 00 Borrow

Sathyabama University

Department of Electronics and Telecommunication Engineering

RESULT: An assembly language program to perform subtraction of two eight bit numbers using 8085 is written and executed.

1.1 (c) MULTIPLICATION OF TWO EIGHT BIT NUMBERS (8085) AIM: To write and execute an assembly language program to perform multiplication of two eight bit numbers using 8085 kit. ALGORITHM: Step 1 Step 2 Step 3 Step 4 Step 5 Step 6 Step 7 Step 8 Step 9 Step 10 Step 11 Step 12 PROGRAM: Memory Address 8000 8002 8005 8006 8009 800A 800C 800D 8010 8011 8012 8015 8018 8019 801C Label Hex Code 16,00 3A,00,90 47 3A,01,90 4F 3E,00 80 D2,11,80 14 0D C2,0C,80 32,00,95 7A 32,01,95 CF Instruction Mnemonic Operand MVI D, 00 LDA 9000 MOV B, A LDA 9001 MOV C, A MVI A, 00 ADD B JNC L1 (8011) INR D DCR C JNZ L2 (800C) STA 9500 MOV A, D STA 9501 RST 1 : : : : : : : : : : : : Start. Clear Reg D for Carry Load 1st Number ( Multiplicand in Reg B through reg A Load 2nd Number ( Multiplier in Reg C through reg A Clear Reg A ( Accumulator) Now add content of Reg B with Reg A Check for Carry if carry NOT exists then skip next step Decrement 2nd number ( multiplier) in Reg C Check for Reg C for zero, If NOT zero go to step 6 Else continue Store the result ( product) in reg A into output memory address Store the Carry in Reg D into next output memory address End Program

L2

L1

Semester V

Microprocessor, Interfacing and Applications Laboratory-Manual,

Sathyabama University

Department of Electronics and Telecommunication Engineering

SAMPLE INPUT & OUTPUT: Before Execution Memory Address 9000 9001 Data EF AF Multiplicand Multiplier After Execution Memory Address 9500 9501 Data 61 A3 LSB of Product MSB of the Product

Multiplication: EFxAF= A361 RESULT: An assembly language program to perform multiplication of two eight bit numbers using 8085 is written and executed. 1.1 (d) DIVISION OF TWO EIGHT BIT NUMBERS (8085) AIM: To write and execute an assembly language program to perform the division of two eight bit numbers using 8085 kit. ALGORITHM: Step 1 : Step 2 : Step 3 : Step 4 : Step 5 : Step 6 : Step 7 : Step 8 : Step 9 : Step 10: Step 11 : PROGRAM: Memory Address 8000 8002 8005 8006 8009 800A
Semester V

Start. Clear C register to account for quotient. Load the divisor in accumulator and move it to B register. Load the dividend in the accumulator. Check whether divisor is less than dividend. If divisor is less than dividend, go to step 9, else go to next step. Subtract the content of B register from accumulator. Increment the content of C register (quotient). Go to step 5. Store the content of accumulator (remainder) in memory. Move the content of C register (quotient) to accumulator and store in memory. End program.

Label

Hex Code 0E, 00 3A, 00, 90 47 3A, 01, 90 B8 DA, 12 ,80

L2

Instruction Mnemonic Operand MVI C,00 LDA 9001 MOV B,A LDA 9000 CMP B JC 8012 (L1)
9

Microprocessor, Interfacing and Applications Laboratory-Manual,

Sathyabama University

Department of Electronics and Telecommunication Engineering

Memory Address 800D 800E 800F 8012 8015 8016 8019

Label

Hex Code 90 0C C3, 09, 80 32, 00, 95 79 32, 01, 95 CF

L1

Instruction Mnemonic Operand SUB B INR C JMP 8009 (L2) STA 9500 MOV A,C STA 9501 RST 1

SAMPLE INPUT & OUTPUT: Before Execution Memory Address 9000 9001 Data EF AF Divisor Dividend Memory Address 9500 9501 After Execution Data 40 01 Remainder Quotient

Division: EF/AF= Remainder (40) Quotient (01)

RESULT: An assembly language program to perform division of two eight bit numbers using 8085 is written and executed.

Semester V

Microprocessor, Interfacing and Applications Laboratory-Manual,

10

Sathyabama University

Department of Electronics and Telecommunication Engineering

1.2. 16 BIT ADDITION and SUBTRACTION

1.2 (a) ADDITION OF TWO SIXTEEN BIT NUMBERS (8085) AIM: To write an assembly language program to perform addition of two sixteen bit numbers. ALGORITHM: Step 1 : Step 2 : Step 3 : Step 4 : Step 5 : Step 6 : Step 7 : Step 8 : Step 9 : Step 10: Step 11: PROGRAM: Memory Address 8000 8002 8005 8006 8009 800A 800D 800E 8011 8012 8015 Label Hex Code 0E, 00 2A, 00, 90 EB 2A, 02, 90 19 D2, 0E, 80 0C 22, 00, 95 79 32, 02, 95 CF Instruction Operand Mnemonic MVI C,00 LHLD 9000 XCHG LHLD 9002 DAD D JNC 800E (L1) INR C SHLD 9500 MOV A,C STA 9502 RST 1 Start. Clear C register for carry. Load the first data in HL register pair. Move the first data to DE register pair. Load the second data in HL register pair. Add the content of DE register pair to HL register pair. Check for carry. If carry = 1, go to step 8 else if carry =0, go to step 9. Increment the C register to account for carry. Store the sum in memory. Move the carry to accumulator and store in memory. End program.

L1

Semester V

Microprocessor, Interfacing and Applications Laboratory-Manual,

11

Sathyabama University

Department of Electronics and Telecommunication Engineering

SAMPLE INPUT & OUTPUT: Before Execution Memory Address 9000 9001 9002 9003 Data CD AB AA AA Upper Byte (Augend) Lower Byte (Augend) Upper Byte (Addend) Lower Byte (Addend) After Execution Memory Address 9500 9501 9502 Data 77 56 01 Lower Byte Sum Upper Byte Sum Carry

16-Bit Addition: ABCD+AAAA=015677 RESULT: An assembly language program to perform addition of two 16-bit numbers using 8085 is written and executed 1.2 (b) SUBTRACTION OF TWO SIXTEEN BIT NUMBERS (8085) AIM: To write an assembly language program to perform subtraction, of two sixteen bit numbers. ALGORITHM: Step 1 : Step 2 : Step 3 : Step 4 : Step 5 : Step 6 : Step 7 : Step 8 : Step 9 : Step 10: Step 11: PROGRAM: Memory Address 8000 8003 8004
Semester V

Start. Load the first data in HL register pair. Move the first data to DE register pair. Load the second data in HL register pair. Move the content of E to A. Subtract Content of L from A (Lower Bytes) Store the difference in the memory Move the content of D to A. Subtract Content of H from A with borrow (higher Bytes) Store the difference in the memory End program.

Label

Hex Code 2A, 00, 90 EB 2A, 02, 90

Instruction Mnemonic Operand LHLD 9000 XCHG LHLD 9002


12

Microprocessor, Interfacing and Applications Laboratory-Manual,

Sathyabama University

Department of Electronics and Telecommunication Engineering

Memory Address 8007 8008 8009 800C 800D 800E 8011

Label

Hex Code 7B 95 32, 00, 95 7A 9C 32, 01, 95 CF

Instruction Mnemonic Operand MOV A, E SUB L STA 9500 MOV A, D SBB H STA 9501 RST 1

SAMPLE INPUT & OUTPUT: Before Execution Memory Address 9000 9001 9002 9003 Data CD AB AA AA Upper Byte (Minuend) Lower Byte (Minuend) Upper Byte (Subtrahend) Lower Byte (Subtrahend) After Execution Memory Address 9500 9501 Data 23 01 Lower Byte Difference Upper Byte Difference

16-Bit Subtraction: ABCD-AAAA=0123

RESULT: An assembly language program to perform subtraction of two 16-bit numbers using 8085 is written and executed.

Semester V

Microprocessor, Interfacing and Applications Laboratory-Manual,

13

Sathyabama University

Department of Electronics and Telecommunication Engineering

1.3. CONVERTING A BCD NUMBER TO HEX NUMBER and HEX TO BCD NUMBERS 1.3 (a) CONVERTING A BCD NUMBER TO HEX NUMBER (8085) AIM: To write an assembly language program to convert BCD number in memory to the equivalent HEX number using 8085. ALGORITHM: Step 1 : Step 2 : Step 3 : Step 4 : Step 5 : Step 6 : Step 7 : Step 8 : Step 9 : Step 10: Step 11: Step 12: Step 13: Step 15: Step 14: PROGRAM: Memory Address 8000 8003 8004 8006 8007 8008 8009 800A 800B 800D 800F 8010 8011 8014 8015 8016 8018
Semester V

Start Load the BCD number in accumulator (Reg A) Copy it to Reg E Mask the Lower Nibble of the BCD number Rotate it 4 times to move Upper nibble to lower nibble place Copy the number to Reg B Clear Reg A Copy number 0A in Reg C (Decimal number 10) Multiply the number in B by 10d Then move the product in Reg B Copy the original number in Reg E to Reg A Mask the Upper Nibble of the BCD Number Add the Number in Reg B with the number in Reg A The number is copied to a memory location End program.

Label

Hex Code 3A, 00, 90 5F E6, 0F 0F 0F 0F 0F 47 3E,00 0E, 0A 80 OD C2, 0F, 80 47 E6, F0 80

L1

Instruction Mnemonic Operand LDA 9000 MOV E, A ANI F0 RRC RRC RRC RRC MOV B, A MVI A,00 MVI C,0A ADD B DCR C JNZ 800F(L1) MOV B, A MOV A, E ANI 0F ADD B
14

Microprocessor, Interfacing and Applications Laboratory-Manual,

Sathyabama University

Department of Electronics and Telecommunication Engineering

Memory Address 8019 801C

Label

Hex Code 32, 00, 95 CF

Instruction Mnemonic Operand STA 9500 RST 1

SAMPLE INPUT & OUTPUT: Before Execution Memory Data Address 9000 29 (BCD) After Execution Memory Data Address 9500 1D (HEX)

BCD (29d) = Hexadecimal (1DH) RESULT: An assembly language program to convert the Binary coded decimal (BCD) into Hexadecimal number (HEX) has been written and executed using microprocessor 8085. 1.3 (b) CONVERTING HEXADECIMAL NUMBER TO BCD NUMBER (8085) AIM: To write an assembly language program to convert HEX numbers in memory to the equivalent BCD number using 8085. ALGORITHM: Step 1 : Step 2 : Step 3 : Step 4 : Step 5 : Step 6 : Step 7 : Step 8 : Step 9 : Step 10: Step 11: Step 12: Step 13: Step 15: Step 14: Step 15: Step 16: Step 17:
Semester V

Start Clear Reg D and E to store tens and hundreds respectively Load the HEX number in accumulator (Reg A) Compare Hex number with 64h (100d)(Check for Hundreds) If carry , HEX <64 so go to Check Tens ( Step 8 ) NO Carry Next step Subtract 64 h (100s) from the number. Increment Reg E for each hundred and repeat step 6 until HEX becomes less than 100d (64H) Compare Remaining Hex number with 0Ah (10d) (Check for Tens) If carry , Remaining HEX <10 so go to Check ones ( Step ) NO Carry Next step Subtract 0A h (10s) from the number. Increment Reg D for each hundred and repeat step 6 until HEX becomes less than 10d (0AH) Now the remaining is ones and is stored in Reg C Now tens are copied from reg D to Reg A The number is rotated 4 times to move it to tens position (upper Nibble) Then the number is added with ones in Reg c Store the Combined tens and ones in reg A to memory location Store the Hundreds in Reg E to next memory location End program.
Microprocessor, Interfacing and Applications Laboratory-Manual, 15

Sathyabama University

Department of Electronics and Telecommunication Engineering

PROGRAM: Memory Address 8000 8002 8004 8007 8009 800C 800E 800F 8012 8014 8017 8019 801A 801D 801E 801F 8020 8021 8022 8023 8024 8027 8028 802B Label Hex Code 16, 00 1E, 00 3A, 00, 90 FE, 64 DA, 0B, 80 D6, 64 1C C3, 06, 80 FE, 0A DA, 1C, 80 D6, 0A 14 C3, 0B, 80 4F 7A 0F 0F 0F 0F 81 32, 00, 95 7B 32, 01, 95 CF Instruction Mnemonic Operand MVI D, 00 MVI E, 00 LDA 9000 CPI 64 JC 8012 (L1) SUI 64 INR E JMP 8007 (L2) CPI 0A JC 8024(L3) SUI 0A INR D JMP 8012 (L1) MOV C, A MOV A, D RRC RRC RRC RRC ADD C STA 9500 MOV A, E STA 9501 RST 1

L2

L1

L3

SAMPLE INPUT & OUTPUT: Before Execution Memory Data Address 9000 1D (Hex) After Execution Memory Address 9500 9501 Data 29 00 (BCD) Tens and ones Hundreds

Hexadecimal (1DH) = BCD (0029d) RESULT: The program to convert the hexadecimal number (HEX) into Binary coded decimal (BCD) has been written and executed using microprocessor 8085.

Semester V

Microprocessor, Interfacing and Applications Laboratory-Manual,

16

Sathyabama University

Department of Electronics and Telecommunication Engineering

1.4. LARGEST AND SMALLEST OF A GIVEN SET OF NUMBERS 1.4 (a) LARGEST OF A GIVEN SET OF NUMBERS (8085) AIM: To write assembly language programs to search the largest of a given set of array of numbers using 8085. ALGORITHM: Step 1 : Step 2 : Step 3 : Step 4 : Step 5 : Step 6 : Step 7 : Step 8 : Step 9 : Step 10: Step 11: Step 12: Step 13: Step 14: PROGRAM: Memory Address 8000 8003 8004 8005 8006 8007 8008 8009 800C 800D 800E 8011 8014 Label Hex Code 21, 00, 90 46 23 7E 05 23 BE D2, 0D, 80 7E 05 C2, 08, 80 32, 00, 95 76 Instruction Mnemonic Operand LXI H,9000 MOV B,M INX H MOV A,M DCR B INX H CMP M JNC 800D (L1) MOV A,M DCR B JNZ 8007 (L2) STA 9500 HLT Start. Load the address of the first element of the array in HL register pair (pointer). Move the count to B register. Increment the pointer. Get the first data in the accumulator. Decrement the count. Increment the pointer. Compare the content of memory addresses by HL pair with that of accumulator. If CF=0, go to step 11 else go to step 10. Move the content memory addressed HL to accumulator. Decrement the count. Check for zero for the count. If ZF=0, go to step 7 else go to next step. Store the largest data in the memory. End program.

L2

L1

Semester V

Microprocessor, Interfacing and Applications Laboratory-Manual,

17

Sathyabama University

Department of Electronics and Telecommunication Engineering

SAMPLE INPUT & OUTPUT: Before Execution Memory Data Address 9000 05 Count 9001 EF Data 1 9002 DA Data 2 9003 FD Data 3 9004 12 Data 4 9005 05 Data 5 After Execution Memory Data Address 9500 FD Largest

1.4 (b) SMALLEST OF A GIVEN SET OF NUMBERS (8085) AIM: To write assembly language programs to search the smallest of a given set of array of numbers using 8085. ALGORITHM: Step 1 : Step 2 : Step 3 : Step 4 : Step 5 : Step 6 : Step 7 : Step 8 : Step 9 : Step 10: Step 11: Step 12: Step 13: Step 14: Start. Load the address of the first element of the array in HL register pair (pointer). Move the count to B register. Increment the pointer. Get the first data in the accumulator. Decrement the count. Increment the pointer. Compare the content of memory addresses by HL pair with that of accumulator. If CF=1, go to step 11 else go to step 10. Move the content memory addressed HL to accumulator. Decrement the count. Check for zero for the count. If ZF=0, go to step 7 else go to next step. Store the smallest data in the memory. End program.

Semester V

Microprocessor, Interfacing and Applications Laboratory-Manual,

18

Sathyabama University

Department of Electronics and Telecommunication Engineering

PROGRAM: Memory Address 8000 8003 8004 8005 8006 8007 8008 8009 800C 800D 800E 8011 8014 Label Hex Code 21, 00, 90 46 23 7E 05 23 BE DA, 0D, 80 7E 05 C2 , 08, 80 32, 00, 95 76 Instruction Operand Mnemonic LXI H, 9000 MOV B,M INX H MOV A,M DCR B INX H CMP M JC 800D (L1) MOV A,M DCR B JNZ 8007 (L2) STA 9500 HLT

L2

L1

SAMPLE INPUT & OUTPUT: Before Execution Memory Data Address 9000 05 Count 9001 EF Data 1 9002 DA Data 2 9003 FD Data 3 9004 12 Data 4 9005 05 Data 5 After Execution Memory Data Address 9500 05 Smallest

RESULT: The programs to find the Largest and smallest number has been written and executed using microprocessor 8085.

NOTE: Largest and smallest programs are the same except the commands JC and JNC.

Semester V

Microprocessor, Interfacing and Applications Laboratory-Manual,

19

Sathyabama University

Department of Electronics and Telecommunication Engineering

1.5. BLOCK MOVEMENT OF DATA AIM: To write an assembly language program to move a block of data from one set of memory location to other using 8085 microprocessor. ALGORITHM: Step 1: Step 2: Step 3: Step 4: Step 5: Step 6: Step 7: Step 8: Step 9: Step 10: Step 11: Start Load the starting address of the destination block in DE pair (9100) Load the address of the Length of the block in HL pair (9000). From the next address (9001) the source block starts Move the length of the block to Reg B Increment the HL pair to Starting address of the source block Move the first source data to Accumulator ( Reg A) Move the Data to Destination block by Pointing with DE pair. Increment the destination address ( DE Pair) Decrement the Block count in Reg B Check whether the block count is 0, if NOT zero Go to step 4, else next step Terminate the program.

PROGRAM: Memory Hex Label Address Code 8000 11,00,91 8003 21,00,90 8006 46 8007 L1 23 8008 7E 8009 12 800A 13 800B 05 800C C2,07,80 800F CF Instruction Mnemonic Operand LXI D, 9100 LXI H, 9000 MOV B, M INX H MOV A, M STAX D INX D DCR B JNZ 8007 (L1) RST 1

Semester V

Microprocessor, Interfacing and Applications Laboratory-Manual,

20

Sathyabama University

Department of Electronics and Telecommunication Engineering

SAMPLE INPUT & OUTPUT: Before Execution Memory Address 9000 9001 9002 9003 9004 9005 Data 05 0A 05 32 5B CA Number of Data (Count) Data 1 Data 2 Data 3 Data 4 Data 5 After Execution Memory Data Address 9100 0A Data 9101 05 Data 9102 32 Data 9103 5B Data 9104 CA Data

1 2 3 4 5

The block arrays of five 8-bit data are moved from Addresses 9001 to 9100. RESULT: The program to move a block of data from one set of memory location to another set of memory location has been written and executed using microprocessor 8085.

Semester V

Microprocessor, Interfacing and Applications Laboratory-Manual,

21

Sathyabama University

Department of Electronics and Telecommunication Engineering

8086 PROGRAMMING S2.1. STUDY OF 8086 PROCESSOR Draw 8086 architecture diagram in the record Write about the functional units in detail 2.1. 16-BIT ADDITION, SUBTRACTION, MULTIPLICATION AND DIVISION 2.1 (a) ADDITION OF TWO SIXTEEN BIT NUMBERS (8086) AIM: To write and execute an assembly language program to perform addition of two sixteen bit numbers using 8086 kit. ALGORITHM: : Step 1 Step 2 : : Step 3 : Step 4 Step 5 Step 6 Step 7 Step 8 Step 9 Step 10 Step 11 Step 12 : :

: : : : :

Start. Clear CX register for carry Initiate Source Index to a source address where input data is stored. Initiate Destination Index to a destination address where output data is stored. Augends data shall be copied into Accumulator (AX) using source index. Addend data from next input address shall be copied into register BX using source index. Both addend and augends in are added Check for the Carry Flag. If Carry flag is NOT set skip next step 9 Register CX is incremented (Carry) The Sum in Register AX is copied into output memory address using destination index register The Carry stored in Register CX is copied into the next output address The program is halted

Note: - Address, Hex Codes and Comment to be written for all other programs while in the lab
In this program Registers AX, BX, CX are used for Data Manipulation PROGRAM: Memory Address Label Hex Code Instruction Operand Mnemonic MOV CX,0000 MOV SI,1000 MOV DI,1500 MOV AX,[SI] MOV BX,[SI+2] ADD AX,BX JNC (NO_CARY) INC CL MOV [DI],AX MOV [DI+2],CX INT 3 Comment

NO_CARY

Semester V

Microprocessor, Interfacing and Applications Laboratory-Manual,

22

Sathyabama University

Department of Electronics and Telecommunication Engineering

Note: NO_CARY shall be replaced with relevant memory address inside the program else the assembler throws a syntax error.
SAMPLE INPUT & OUTPUT: Before Execution Memory Data Address Augend 1000 (Lower Byte) Augend 1001 (Upper Byte) Addend 1002 (Lower Byte) Addend 1003 (Upper Byte) After Execution Memory Data Address Sum 1500 (Lower Byte) Sum 1501 (Upper Byte) 1502 Carry

RESULT: An assembly language program to perform the addition of two sixteen bit numbers using 8086 is written and executed. 2.1 (b) SUBTRACTION OF TWO SIXTEEN BIT NUMBERS (8086) AIM: To write and execute an assembly language program to perform subtraction of two sixteen bit numbers using 8086 kit. ALGORITHM: Step 1 : : Step 2 : Step 3 : Step 4 Step 5 Step 6 Step 7 Step 8 Step 9 Step 10 Step 11 Step 12 : :

: : : : :

Start. Clear CX register for Carry/Borrow Initiate Source Index to a source address where input data is stored. Initiate Destination Index to a destination address where output data is stored. Minuend data shall be copied into Accumulator (AX) using source index. Subtrahend data from next input address shall be copied into register BX using source index. Subtrahend in register BX is subtracted from minuend in register AX Check for the Carry/Borrow Flag. If Carry/Borrow flag is NOT set skip next step 9 Borrow is Copied into CL register. The difference in AX is twos complemented. The Difference in Register AX is copied into output memory address using destination index register The Borrow stored in Register CX is copied into the next output address The program is halted

BORROW indicates that the Minuend is smaller than Subtrahend


PROGRAM:
Semester V Microprocessor, Interfacing and Applications Laboratory-Manual, 23

Sathyabama University

Department of Electronics and Telecommunication Engineering

Memory Address

Label

Hex Code

NO_BOROW

Instruction Mnemonic Operand MOV CX,0000 MOV SI,1000 MOV DI,1500 MOV AX,[SI] MOV BX,[SI+2] SUB AX,BX JNC (NO_BOROW) INC CL NEG AX MOV [DI],AX MOV [DI+2],CX INT 3

Comment

Note: NO_BOROW shall be replaced with relevant memory address inside the program else the assembler throws a syntax error.
SAMPLE INPUT & OUTPUT: Before Execution Memory Data Address Minuend 1000 (Lower Byte) Minuend 1001 (Upper Byte) Subtrahend 1002 (Lower Byte) Subtrahend 1003 (Upper Byte) After Execution Memory Data Address Difference 1500 (Lower Byte) Difference 1501 (Upper Byte) 1502 Borrow

RESULT: An assembly language program to perform the subtraction of two sixteen bit numbers using 8086 is written and executed. 2.1 (c) MULTIPLICATION OF TWO SIXTEEN BIT NUMBERS (8086) AIM: To write and execute an assembly language program to perform multiplication of two sixteen bit numbers using 8086 kit. ALGORITHM: Step 1 Step 2 Step 3 Step 4
Semester V

: Start. : Initiate Source Index to a source address where input data is stored. : Initiate Destination Index to a destination address where output data is stored. : Multiplicand data shall be copied into Accumulator (AX) using source
Microprocessor, Interfacing and Applications Laboratory-Manual, 24

Sathyabama University

Department of Electronics and Telecommunication Engineering

Step 5 Step 6 Step 7 Step 8 Step 9 PROGRAM:

: : :

index. Multiplier data from next input address shall be copied into register BX using source index. Both Multiplicand and Multiplier are multiplied The Product in Register AX is copied into output memory address using destination index register The Carry stored in Register DX is copied into the next output address The program is halted

Memory Address

Label

Hex Code

Instruction Mnemonic Operand MOV DX,0000 MOV SI,1000 MOV DI,1500 MOV AX,[SI] MOV BX,[SI+2] MUL AX,BX MOV [DI],AX MOV [DI+2],DX INT 3

Comment

SAMPLE INPUT & OUTPUT: Before Execution Memory Data Address Multiplicand 1000 (Lower Byte) Multiplicand 1001 (Upper Byte) Multiplier 1002 (Lower Byte) Multiplier 1003 (Upper Byte) After Execution Memory Data Address Product 1500 (Lower Byte) Product 1501 (Upper Byte) Carry 1502 (Lower Byte) Carry 1503 (Upper Byte)

RESULT: An assembly language program to perform multiplication of two sixteen bit numbers using 8086 is written and executed.

Semester V

Microprocessor, Interfacing and Applications Laboratory-Manual,

25

Sathyabama University

Department of Electronics and Telecommunication Engineering

2.1 (d) DIVISION OF SIXTEEN BIT NUMBER BY EIGHT BIT NUMBER (8086) AIM: To write and execute an assembly language program to perform division of two sixteen bit numbers using 8086 kit. ALGORITHM: Step 1 Step 2 Step 3 Step 4 Step 5 Step 6 Step 7 Step 8 Step 9 PROGRAM: Memory Address Hex Code Instruction Operand Mnemonic MOV DX,0000 MOV SI,1000 MOV DI,1500 MOV AX,[SI] INC SI INC SI MOV BX,[SI] DIV AX,BX [DI],AX MOV INC DI INC DI MOV [DI],DX INT 3 : Start. : Initiate Source Index to a source address where input data is stored. : Initiate Destination Index to a destination address where output data is stored. : Dividend data shall be copied into Accumulator (AX) using source index. : Divisor data from next input address shall be copied into register BX using source index. Division is completed. Remainder is Generated in DX and Quotient in AX : The Quotient in Register AX is copied into output memory address using destination index register : The Remainder stored in Register DX is copied into the next output address : The program is halted

Label

Comment

Semester V

Microprocessor, Interfacing and Applications Laboratory-Manual,

26

Sathyabama University

Department of Electronics and Telecommunication Engineering

SAMPLE INPUT & OUTPUT: Before Execution Memory Data Address Dividend 1000 (Lower Byte) Dividend 1001 (Upper Byte) Divisor 1002 (Lower Byte) Divisor 1003 (Upper Byte) After Execution Memory Data Address Quotient 1500 (Lower Byte) Quotient 1501 (Upper Byte) Remainder 1502 (Lower Byte) Remainder 1503 (Upper Byte)

RESULT: An assembly language program to perform the addition, subtraction, multiplication and division of two sixteen bit numbers using 8086 is written and executed.

Semester V

Microprocessor, Interfacing and Applications Laboratory-Manual,

27

Sathyabama University

Department of Electronics and Telecommunication Engineering

2.2. 32-BIT ADDITION AIM: To write and execute an assembly language program to perform the addition of two thirty two bit numbers using 8086 kit. ALGORITHM: Step 1 : Start. : Initiate Register DX Step 2 Step 3 : Point the source and destination register to source and destination memory addresses respectively : Copy the augend into register AX (Lower word) and register BX (Upper Step 4 Word) Step 5 : Copy the addend into register CX (Lower word) and register DX (Upper Word) : Add the Lower 16 bit words in AX and CX Step 6 Step 7 : Copy the sum in AX to Destination memory location : Initiate CX for storing Carry generated Step 8 : Add the Upper words in BX and DX with carry Step 9 : If Carry is generated then CX else store the result Step 10 Step 11 : Copy the Sum (Upper Word) from BX and Carry from CX to destination Memory locations : Stop the program Step 12 PROGRAM: Memory Address Label Hex Code Instruction Operand Mnemonic MOV DX,0000 MOV SI,1000 MOV DI,1500 MOV AX,[SI] MOV BX,[SI+2] MOV CX,[SI+4] DX,[SI+6] MOV ADD AX,CX MOV CX,0000 MOV [DI],AX ADC BX,DX Comment

JNC
NO_CARY
INC MOV MOV INT

(NO_CARY)
CX [DI+2],BX [DI+4],CX 3

Semester V

Microprocessor, Interfacing and Applications Laboratory-Manual,

28

Sathyabama University

Department of Electronics and Telecommunication Engineering

SAMPLE INPUT & OUTPUT: Before Execution Memory Data Address Augend 1000 (Lower Word Lower Byte) Augend 1001 (Lower Word Upper Byte) Augend 1002 (Upper Word Lower Byte) Augend 1003 (Upper Word Upper Byte) Addend 1004 (Lower Word Lower Byte) Addend 1005 (Lower Word Upper Byte) Addend 1006 (Upper Word Lower Byte) Addend 1007 (Upper Word Upper Byte) After Execution Memory Data Address Sum 1500 (Lower Word Lower Byte) Sum 1501 (Lower Word Upper Byte) Sum 1502 (Upper Word Lower Byte) Sum 1503 (Upper Word Upper Byte) Carry 1504

[BX][AX[ +[DX][CX]=[1504][1503][1502][1501][1500] RESULT: An assembly language program to perform the addition of two thirty two bit numbers using 8086 is executed and verified.

Semester V

Microprocessor, Interfacing and Applications Laboratory-Manual,

29

Sathyabama University

Department of Electronics and Telecommunication Engineering

2.3. ASCENDING ORDER AND DESCENDING ORDER 2.3 (a) ARRANGING AN ARRAY OF NUMBERS IN ASCENDING ORDER (8086) AIM: To write and execute an assembly language program to arrange an array of numbers in ascending order using 8086 kit. ALGORITHM: Step 1 : : Step 2 : Step 3 : Step 4 Step 5 : : Step 6 : Step 7 Step 8 Step 9 Step 10 Step 11 PROGRAM: Memory Address Label Hex Code Instruction Mnemonic Operand MOV SI,1000 MOV CL,[SI] DEC CL INC SI MOV AL,[SI] INC SI CMP AL, [SI] JC (STEP3) XCHG AL,[SI] XCHG AL,[SI-1] LOOP (STEP1) DEC CL JNZ (STEP2) INT 3 Comment : : : :

Start. Point the Source index to source memory location Copy the Number of array elements stored in Source index to register CL Decrement the register CL Increment the Source index and copy the first Number in to Register AL Compare the next number in Memory location with Content in AL If carry is generated Content in AL is smaller than next location content. Then it goes to step3, else to next step The contents in memory locations are swapped by using AL register. Thus smaller number is copied in first location and the larger in next location Then the Steps are repeated until the numbers arranged in ascending order Every time register is decremented and checked for zero content. When CX=0 the sorting of number has been completed Stop the program

STEP1:

STEP2:

STEP3:

Semester V

Microprocessor, Interfacing and Applications Laboratory-Manual,

30

Sathyabama University

Department of Electronics and Telecommunication Engineering

SAMPLE INPUT & OUTPUT:

Before Execution Memory Data Address No of Array 1000 07 elements 1001 23 1002 34 1003 21 1004 AB FA 1005 1006 3B 11 1007

After Execution Memory Data Address 1000 11 1001 21 1002 23 1003 34 1004 3B 1005 AB 1006 FA

RESULT: An assembly language program to Sort an array of numbers in ascending order using 8086 kit is executed and verified. 2.3 (b) SORTING AN ARRAY OF NUMBERS IN DESCENDING ORDER (8086) AIM: To write and execute an assembly language program to arrange an array of numbers in descending order using 8086 kit. ALGORITHM: Step 1 : : Step 2 : Step 3 Step 4 : : Step 5 : Step 6 : Step 7 Step 8 Step 9 Step 10 Step 11 : : : :

Start. Point the Source index to source memory location Copy the Number of array elements stored in Source index to register CL Decrement the register CL Increment the Source index and copy the first Number in to Register AL Compare the next number in Memory location with Content in AL If carry is generated Content in AL is smaller than next location content. Then it goes to step3, else to next step The contents in memory locations are swapped by using AL register. Thus smaller number is copied in first location and the larger in next location Then the Steps are repeated until the numbers arranged in descending order Every time register is decremented and checked for zero content. When CX=0 the sorting of number has been completed Stop the program

Semester V

Microprocessor, Interfacing and Applications Laboratory-Manual,

31

Sathyabama University

Department of Electronics and Telecommunication Engineering

PROGRAM: Memory Address Label Hex Code Instruction Mnemonic Operand MOV SI,1000 MOV CL,[SI] DEC CL INC SI MOV AL,[SI] INC SI CMP AL, [SI] JNC (STEP3) XCHG AL,[SI] XCHG AL,[SI-1] LOOP (STEP1) DEC CL JNZ (STEP2) INT 3 Comment

STEP1:

STEP2:

STEP3:

SAMPLE INPUT & OUTPUT:

Before Execution Memory Data Address No of Array 1000 07 elements 1001 23 1002 34 1003 21 1004 AB FA 1005 1006 3B 11 1007

After Execution Memory Data Address 1000 FA 1001 AB 1002 3B 1003 34 1004 23 1005 21 1006 11

RESULT: An assembly language program to Sort an array of numbers in descending order using 8086 kit is executed and verified.

Semester V

Microprocessor, Interfacing and Applications Laboratory-Manual,

32

Sathyabama University

Department of Electronics and Telecommunication Engineering

MP.2 ANNEXURE
BASICS TO KNOW FOR PROGRAMMING USING 8085
8085 IS AN INTEL 40 PIN CHIP PROCESSOR THAT WORKS AT +5V DC POWER SUPPLY. FOR PROGRAMMING 8085, WE NEED TO KNOW ABOUT MEMORY UNIT, REGISTERS, INSTRUCTION SET, TIMERS & COUNTERS, STACK, INTERRUPTS. MEMORY UNIT o Memory unit is an externally attached chip to a maximum of 64 Kb. o The addresses start from 0000h and end at FFFFH. o The addresses may be of ROM (Read-Only Memory) or RAM (Random Access Memory). o The addresses of ROM cannot be used by the user for programming o Only RAM addresses can be used for programming. For example, addresses 8000H to 9FFFH may be usable addresses. ( KIT manual shall be referred for knowing usable and unusable addresses) REGISTERS o The register unit consists of twelve 8-bit registers and two 16-bit registers. o They are 8-bit registers: A (Accumulator), B, C, D, E, H, L, Flag, W, Z, Temp and Instruction registers. 16-bit registers: SP (Stack Pointer) and PC (Program Counter) o Registers A becomes main operand for any arithmetic or logical instructions. It is used to fetch data from memory or write data into memory. Thus, it is called WORKING REGISTER.

Semester V

Microprocessor, Interfacing and Applications Laboratory-Manual,

33

Sathyabama University

Department of Electronics and Telecommunication Engineering

o The other registers BC can be used as 16-bit register as a pair and individually B and C can be used as 8-bit registers. This setup is called REGISTER PAIR. The other register pairs are DE, HL and WZ. (WZ cannot be used by any programmer) o HL Register pair is considered to be working register pair in 16-bit operations as accumulator in 8-bit operations. o Flag register shows the status of any arithmetic or logical operation when carry/borrow is generated (CARRY FLAG), the registers pointed being data 00H (ZERO FLAG), the MSB of the Content in register A is binary 1 (SIGN FLAG), parity of the Content of Register A is odd or even (PARITY FLAG) o Temp register and Instruction registers cannot be programmer. They are meant for internal operations. INSTRUCTIONS o There are 7 sets of instructions in 8085. o They are Data Transfer Instructions that copy data from memory to Registers, Registers to Memory, Register to register, used by

Accumulator to Output interfaced peripherals, input interfaced peripherals to accumulator. Arithmetic Instructions that perform operations of addition, subtraction, incrementing a register, decrementing a register etc. (NO instructions for Multiplication and division) Logical Instructions that performs compare operations,

rotational operations, and gate operations like OR, AND, NOT, XOR.
Semester V Microprocessor, Interfacing and Applications Laboratory-Manual, 34

Sathyabama University

Department of Electronics and Telecommunication Engineering

Branch instructions for looping and branching of instruction like jumping and calling subroutines. Machine Control Instructions that controls machine to stop operation (HLT) or no operation (NOP). Stack control instructions that are used in programming the stack memory. (A Chosen part of RAM for special purpose use) and Interrupt instructions that control the interrupts and invokes the interrupt programs PROGRAM o A program consists of sequence of instructions. o Instructions are written in sequence of addresses. o The addresses used for writing instructions cannot be used for data storage. For example, if addresses 8000h to 8FFFH are used for writing instructions, the data required for those instructions should not be written in the same addresses. It can be written in any other usable segment of addresses like 9000H to 9FFFH. STEPS FOR WRITING PROGRAM o The steps for writing program are algorithm design, instruction choosing for relevant algorithm, o For writing the program, Algorithm is designed first. With the help of the algorithm, instructions are chosen from instruction set and are written in sequence. o After writing the instructions, logically the instructions are verified with sample data. Then the program is written in the assembler.

Semester V

Microprocessor, Interfacing and Applications Laboratory-Manual,

35

Sathyabama University

Department of Electronics and Telecommunication Engineering

ALGORITHM DESIGN o Let us take an example, adding two 8-bit numbers o ADDING TWO 8-BIT NUMBERS The two 8-bit DATA (to be added) shall be stored in data memory addresses (External). Thus to copy them into the CPU we need to use register A (Accumulator) only. Other registers B, C, D, E, H and L cannot be used for this purpose. (While in 16 bit Copy from memory addresses H and L registers can be used together as a pair) Since two 8-bit numbers are added, two 8-bit registers shall be used for the purpose. For arithmetic and logical operations register A (Accumulator) is one of the register As shown in the below figure, Two 8-bit DATA to be added are fed in usable memory address. For example, memory address 9000H holds DATA1 and 9001H holds DATA2. DATA1 is fetched by Reg A (Instruction: LDA 9000) and Copied into Reg B (Instruction: MOV B,A) and DATA2 is fetched by Reg A (Instruction: LDA 9001). Now Reg A holds DATA2 and Reg B hold DATA1.
LDA MOV LDA 9000 B,A 9001

Note: Any USABLE address can be used in the above instructions. Both data are added (Instruction: ADD B) by using ALU (Arithmetic Logic Unit). It generates the SUM and stores it in Reg A (8-BIT OPERATIONS).
ADD B

Semester V

Microprocessor, Interfacing and Applications Laboratory-Manual,

36

Sathyabama University

Department of Electronics and Telecommunication Engineering

CARRY is generated in CARRY/BORROW flag usually called as CARRY flag. If Carry is generated CARRY flag becomes Binary 1 else becomes Binary 0. CARRY cannot be copied into any register directly. Thus Instruction JNC (Jump NO Carry) is used, where When carry flag is Binary 1, then next Instruction INR C is executed. This instruction Increments Register C. When carry flag is Binary 0, then next Instruction INR C is skipped and NOT executed.
JNC INR ADDRESS_1 ADDRESS_1 C

Now SUM is in register A (Accumulator) and Carry is simulated in Register C. The Added SUM and CARRY are stored in Memory as follows. The SUM in register A is stored directly to any memory address (Instruction: STA 9500).
ADDRESS_1 STA 9500

The Carry stored in register C is Copied in Register A (Instruction: MOV A,C) and then it is stored in the next Higher memory address 9501H (Instruction: STA 9501)
MOV STA A,C 9501

The program stops now using Instruction HLT or RST 1


RST 1

Semester V

Microprocessor, Interfacing and Applications Laboratory-Manual,

37

Sathyabama University

Department of Electronics and Telecommunication Engineering

Now the program is consolidated as follows


MVI LDA MOV LDA ADD JNC INR ADDRESS_1 STA MOV STA RST 1 C,00 9000 B,A 9001 B ADDRESS_1 C 9500 A,C 9501

Figure explaining adding process of two 8-bit data in 8085

ALU

Reg B + Reg A SUM Reg A Reg C

33

Reg A

33

Address 9000 9001

DATA 33 44

44

MEMORY UNIT Address 9500 9501 DATA 77 00

SUM

Reg A

CARRY

CARRY FLAG, JNR (JUMP NO CARRY) INSTRUCTION, INR INSTRUCTION ARE USED TO COPY CARRY FLAG DATA INTO REGISTER A AND THEN TO REG C.

The above program is used for adding two 8-bit numbers using 8085 assembler.

Semester V

Microprocessor, Interfacing and Applications Laboratory-Manual,

38

You might also like