Вы находитесь на странице: 1из 20

LARGEST ELEMENT IN AN ARRAY AIM: To write an assembly level language program to find the largest element in an array using

8085 microprocessor. ALGORITHM: 1. Place all the elements of an array in the consecutive memory locations. 2. Fetch the first element from the memory location and load it in the accumulator. 3. Initialize a counter (register) with the total number of elements in an array. 4. Decrement the counter by 1. 5. Increment the memory pointer to point to the next element. 6. Compare the accumulator content with the memory content (next element). 7. If the accumulator content is smaller, then move the memory content (largest element) to the accumulator. Else continue. 8. Decrement the counter by 1. 9. Repeat steps 5 to 8 until the counter reaches zero 10. Store the result (accumulator content) in the specified memory location. RESULT: Thus the largest number in the given array is found out.

FLOW CHART: START

[HL] [4100H] [B] 04H [A] [HL] [HL [HL] + 1

NO

IS [A] < [HL]? YES [A] [HL] [B] [B]-1

IS [B] = 0? YES [4105] [A] STOP

NO

PROGRAM: ADDRESS 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 410A 410B 410C 410D 410E 410F 4110 4111 4112 4113 OPCODE 21 00 41 06 04 7E 23 BE D2 0C 41 7E 05 C2 06 41 32 05 41 76 OBSERVATION: INPUT ADDRESS DATA OUTPUT ADDRESS DATA LABEL MNEMONICS LXI OPERAND H,4100 REMARKS Initialize HL reg. to 8100H Initialize B reg with no. of comparisons(n-1) Transfer first data to acc. Increment HL reg. to point next memory location Compare M & A If A is greater than M then go to loop Transfer data from M to A reg Decrement B reg If B is not Zero go to loop1

MVI MOV INX CMP JNC

B,04 A,M H M LOOP

LOOP1

LOOP

MOV DCR JNZ

A,M B LOOP1

STA

4105

Store the result in a memory location. Stop the program

HLT

SMALLEST ELEMENT IN AN ARRAY AIM: To write an assembly level language program to find the smallest element in an array. ALGORITHM: 1. Place all the elements of an array in the consecutive memory locations. 2. Fetch the first element from the memory location and load it in the accumulator. 3. Initialize a counter (register) with the total number of elements in an array. 4. Decrement the counter by 1. 5. Increment the memory pointer to point to the next element. 6. Compare the accumulator content with the memory content (next element). 7. If the accumulator content is smaller, then move the memory content (largest element) to the accumulator. Else continue. 8. Decrement the counter by 1. 9. Repeat steps 5 to 8 until the counter reaches zero 10. Store the result (accumulator content) in the specified memory location. RESULT: Thus the smallest number in the given array is found out.

FLOW CHART: START

[HL] [4100H] [B] 04H [A] [HL] [HL [HL] + 1

YES

IS [A] < [HL]? NO [A] [HL] [B] [B]-1

IS [B] = 0? YES [4105] [A] STOP

NO

PROGRAM: ADDRESS 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 410A 410B 410C 410D 410E 410F 4110 4111 4112 4113 OPCODE 21 00 41 06 04 7E 23 BE DA 0C 41 7E 05 C2 06 41 32 05 41 76 OBSERVATION: INPUT ADDRESS DATA OUTPUT ADDRESS DATA LOOP LABEL MNEMONICS LXI MVI MOV INX CMP JC MOV DCR JNZ STA HLT OPERAND H,4100 B,04 A,M H M LOOP A,M B LOOP1 4105 COMMENTS Initialize HL reg. to 4100H Initialize B reg with no. of comparisons(n-1) Transfer first data to acc. Increment HL reg. to point next memory location Compare M & A If A is lesser than M then go to loop Transfer data from M to A reg Decrement B reg If B is not Zero go to loop1 Store the result in a memory location. Stop the program

LOOP1

ASCENDING ORDER AIM: To write an assembly level language program to sort the given number in the ascending order using 8085 microprocessor. ALGORITHM: 1. Get the numbers to be sorted from the memory locations. 2. Compare the first two numbers and if the first number is larger than second then first interchange the number. 3. If the first number is smaller, go to step 4 4. Repeat steps 2 and 3 until the numbers are in required order RESULT: Thus the ascending order program is executed and thus the numbers are arranged in ascending order.

FLOWCHART:

START [B] 04H [HL] [4100H] [C] 04H [A] [HL] [HL [HL] + 1

YES

IS [A] < [HL]? NO [D] [HL]

[HL] [A]

[HL] [HL] - 1 [HL] [D] [HL] [HL] + 1 [C] [C] 01 H A

IS [C] = 0? YES [B] [B]-1

NO

IS [B] = 0? YES STOP

NO

PROGRAM: ADDRESS 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 410A 410B 410C 410D 410E 410F 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 411A OPCODE 06 04 21 00 41 0E 04 7E 23 BE DA 12 41 56 77 2B 72 23 0D C2 07 41 05 C2 02 41 76 LABEL MNEMONICS MVI LXI MVI LOOP2 MOV INX CMP JC MOV MOV DCX MOV INX DCR JNZ DCR JNZ HLT OPERAND B,04 H,4100 C,04 A,M H M LOOP1 D,M M,A H M,D H C LOOP2 B LOOP3 COMMENTS Initialize B reg with number of comparisons (n-1) Initialize HL reg. to 8100H Initialize C reg with no. of comparisons(n-1) Transfer first data to acc. Increment HL reg. to point next memory location Compare M & A If A is less than M then go to loop1 Transfer data from M to D reg Transfer data from acc to M Decrement HL pair Transfer data from D to M Increment HL pair Decrement C reg If C is not zero go to loop2 Decrement B reg If B is not Zero go to loop3 Stop the program

LOOP 3

LOOP1

OBSERVATION: INPUT MEMORY LOCATION DATA MEMORY LOCATION OUTPUT DATA

DESCENDING ORDER AIM: To write an assembly level language program to sort the given number in the descending order using 8085 microprocessor. ALGORITHM: 1. Get the numbers to be sorted from the memory locations. 2. Compare the first two numbers and if the first number is smaller than second then first interchange the number. 3. If the first number is larger, go to step 4 4. Repeat steps 2 and 3 until the numbers are in required order RESULT: Thus the descending order program is executed and thus the numbers are arranged in descending order.

FLOWCHART:

START [B] 04H [HL] [4100H] [C] 04H [A] [HL] [HL [HL] + 1

NO

IS [A] < [HL]? YES [D] [HL]

[HL] [A]

[HL] [HL] - 1 [HL] [D] [HL] [HL] + 1 [C] [C] 01 H A

IS [C] = 0? YES [B] [B]-1

NO

IS [B] = 0? YES STOP

NO

PROGRAM: ADDRESS OPCODE 4100 06 4101 04 4102 4103 4104 4105 4106 4107 4108 4109 410A 410B 410C 410D 410E 410F 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 411A 21 00 41 0E 04 7E 23 BE D2 12 41 56 77 2B 72 23 0D C2 07 41 05 C2 02 41 76 LOOP1 LABEL MNEMONICS MVI LOOP 3 LXI MVI LOOP2 MOV INX CMP JNC MOV MOV DCX MOV INX DCR JNZ DCR JNZ HLT OPERAND B,04 H,4100 C,04 A,M H M LOOP1 D,M M,A H M,D H C LOOP2 B LOOP3 COMMENTS Initialize B reg with number of comparisons (n-1) Initialize HL reg. to 8100H Initialize C reg with no. of comparisons(n-1) Transfer first data to acc. Increment HL reg. to point next memory location Compare M & A If A is greater than M then go to loop1 Transfer data from M to D reg Transfer data from acc to M Decrement HL pair Transfer data from D to M Increment HL pair Decrement C reg If C is not zero go to loop2 Decrement B reg If B is not Zero go to loop3 Stop the program

OBSERVATION: INPUT MEMORY LOCATION DATA MEMORY LOCATION OUTPUT DATA

CODE CONVERSION DECIMAL TO HEX AIM: To write an assembly level language program to convert a given decimal number to hexadecimal. ALGORITHM: 1. 2. 3. 4. 5. 6. Initialize the memory location to the data pointer. Increment B register. Increment accumulator by 1 and adjust it to decimal every time. Compare the given decimal number with accumulator value. When both matches, the equivalent hexadecimal value is in B register. Store the resultant in memory location.

RESULT: Thus an assembly level language program for conversion of decimal to hexadecimal was written and executed.

FLOWCHART:

START HL 4500H

A 00

B B

00H B+1

A +1

Decimal adjust accumulator

NO

Is A=M?

YES
A B

4101

Stop

PROGRAM: ADDRESS 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 410A 410B 410C 410D 410E 410F 4110 4111 4112 4113 OPCODE 21 41 00 3E 00 06 00 04 C6 01 27 BE C2 07 41 78 32 01 41 76 RESULT: INPUT ADDRESS DATA OUTPUT ADDRESS DATA LABEL MNEMONICS LXI MVI MVI LOOP INR ADI DAA CMP JNZ MOV STA HLT M LOOP A,B 4101 OPERAND H,4100 A,00 B,00 B 01 COMMENTS Initialize HL reg. to 4100H Initialize A register. Initialize B register. Increment B reg. Increment A reg Decimal Adjust Accumulator Compare M & A If acc and given number are not equal, then go to LOOP Transfer B reg to acc. Store the result in a memory location. Stop the program

CODE CONVERSION HEXADECIMAL TO DECIMAL AIM: To write an assembly level language program to convert a given hexadecimal number to decimal. ALGORITHM: 1. 2. 3. 4. 5. 6. Initialize the memory location to the data pointer. Increment B register. Increment accumulator by 1 and adjust it to decimal every time. Compare the given hexadecimal number with B register value. When both match, the equivalent decimal value is in A register. Store the resultant in memory location.

RESULT: Thus an ALP program for conversion of hexadecimal to decimal was written and executed.

FLOWCHART:
HL

START 4100H

A 00

B C B

00H 00H B+1

A +1

Decimal adjust accumulator

Is there carry?

C C+1 D A, A B,

Is A=M?

NO 4101 4102 A, A C YES A


Stop

PROGRAM: ADDRESS 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 410A 410B 410C 410D 410E 410F 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 411A 411B 411C 411D 411E 411F OPCODE 21 00 41 3E 00 06 00 0E 00 04 C6 01 27 D2 11 41 0C 57 78 BE 7A C2 09 41 32 01 41 79 32 02 41 76 RESULT: INPUT ADDRESS DATA OUTPUT ADDRESS DATA LABEL MNEMONICS LXI MVI MVI MVI LOOP INR ADI DAA JNC INR MOV MOV CMP MOV JNZ STA MOV STA HLT NEXT C D,A A,B M A,D LOOP 4101 A,C 4102 OPERAND H,4100 A,00 B,00 C,00 B 01 COMMENTS Initialize HL reg. to 4100H Initialize A register. Initialize B register. Initialize C register for carry. Increment B reg. Increment A reg Decimal Adjust Accumulator If there is no carry go to NEXT. Increment c register. Transfer A to D Transfer B to A Compare M & A Transfer D to A If acc and given number are not equal, then go to LOOP Store the result in a memory location. Transfer C to A Store the carry in another memory location. Stop the program

NEXT

Вам также может понравиться