Você está na página 1de 45

CS2259

MICROPROCESSORS LABORATORY (Common to CSE & IT)

0032

AIM: To learn the assembly language programming of 8085,8086 and 8051 and also to give a practical training of interfacing the peripheral devices with the processor.

OBJECTIVES: To implement the assembly language programming of 8085,8086 and 8051. To study the system function calls like BIOS/DOS. To experiment the interface concepts of various peripheral device with the processor. Experiments in the following: 1. Programming with 8085 2. Programming with 8086-experiments including BIOS/DOS calls: Keyboard control, Display, File Manipulation. 3. Interfacing with 8085/8086-8255,8253 4. Interfacing with 8085/8086-8279,8251 5. 8051 Microcontroller based experiments for Control Applications 6. Mini- Project TOTAL: 45 PERIODS

List of equipments/components for 30 students (two per batch) 1. 8085 Trainer Kit with onboard 8255, 8253, 8279 and 8251 15 nos. 2. TASM/MASM simulator in PC (8086 programs) 30 nos. 3. 8051 trainer kit 15 nos. 4. Interfacing with 8086 PC add-on cards with 8255, 8253, 8279 and 8251 15 nos. 5. Stepper motor interfacing module 5 nos. 6. Traffic light controller interfacing module 5 nos. 7. ADC, DAC interfacing module 5 nos. 8. CROs 5 nos.

Powered By www.technoscriptz.com

Programming with 8085


Experiment No: 1 Experiment No: 2 Experiment No: 3 Experiment No: 4 Experiment No: 5 Experiment No: 6 Experiment No: 7 Experiment No: 8 Experiment No: 9 Experiment No: 10 Experiment No: 11 Experiment No: 12 Experiment No: 13 Two 8 bit Data Addition Two 8 bit Data Subtraction Two 8 bit Data Multiplication Two 8 bit Data Division Two 16 bit Data Multiplication Largest element in an Array Smallest element in an Array Ascending Order Descending Order Code conversion Decimal to Hex Code conversion Hex to Decimal BCD Addition BCD Subtraction

Powered By www.technoscriptz.com

1. Two 8 BIT DATA ADDITION


AIM: To add two 8 bit numbers stored at consecutive memory locations. FLOW CHART:
START

[C]

00H

[HL]

4500H

[A]

[M]

[HL]

[HL]+1

[A]

[A]+[M]

NO

YES Is there a Carry?

[C]

[C]+1

[HL]

[HL]+1

[M]

[A]

[HL]

[HL]+1

[M]

[C] Powered By www.technoscriptz.com

ALGORITHM: 1. 2. 3. 4. Initialize memory pointer to data location. Get the first number from memory in accumulator. Get the second number and add it to the accumulator. Store the answer at another memory location.

PROGRAM: ADDRESS OPCODE LABEL 4100 START 4101 4102 4103 4104 4105 4106 MNEMONICS OPERAND MVI C, 00 LXI H, 4500 COMMENT Clear C reg. Initialize HL reg. to 4500 Transfer first data to accumulator Increment HL reg. to point next memory Location. Add first number to acc. Content. Jump to location if result does not yield carry. Increment C reg. Increment HL reg. to point next memory Location. Transfer the result from acc. to memory. Increment HL reg. to point next memory Location. Move carry to memory Stop the program

MOV INX

A, M H

4107 4108 4109 410A 410B 410C L1

ADD JNC

M L1

INR INX

C H

410D 410E

MOV INX

M, A H

410F 4110

MOV HLT

M, C

OBSERVATION:

INPUT 4500 4501 4502 4503

OUTPUT

Powered By www.technoscriptz.com

RESULT: Thus the 8 bit numbers stored at 4500 &4501 are added and the result stored at 4502 & 4503.

2. Two 8 BIT DATA SUBTRACTION


AIM: To Subtract two 8 bit numbers stored at consecutive memory locations. ALGORITHM: 1. 2. 3. 4. Initialize memory pointer to data location. Get the first number from memory in accumulator. Get the second number and subtract from the accumulator. If the result yields a borrow, the content of the acc. is complemented and 01H is added to it (2s complement). A register is cleared and the content of that reg. is incremented in case there is a borrow. If there is no borrow the content of the acc. is directly taken as the result. 5. Store the answer at next memory location.

RESULT: Thus the 8 bit numbers stored at 4500 &4501 are subtracted and the result stored at 4502 & 4503.

Powered By www.technoscriptz.com

FLOW CHART:
START

[C]

00H

[HL]

4500H

[A]

[M]

[HL]

[HL]+1

[A]

[A]-[M]

Is there a Borrow ?

NO

YES
Complement [A] Add 01H to [A]

[C]

[C]+1

[HL]

[HL]+1

[M]

[A]

[HL]

[HL]+1

[M]

[C]

Powered By www.technoscriptz.com
STOP

PROGRAM: ADDRESS OPCODE LABEL 4100 START 4102 4102 4103 4104 4105 4106 MNEMONICS OPERAND MVI C, 00 LXI H, 4500 COMMENT Clear C reg. Initialize HL reg. to 4500 Transfer first data to accumulator Increment HL reg. to point next mem. Location. Subtract first number from acc. Content. Jump to location if result does not yield borrow. Increment C reg. Complement the Acc. content Add 01H to content of acc. Increment HL reg. to point next mem. Location. Transfer the result from acc. to memory. Increment HL reg. to point next mem. Location. Move carry to mem. Stop the program

MOV INX

A, M H

4107 4108 4109 410A 410B 410C 410D 410E 410F

SUB JNC

M L1

INR CMA ADI L1 INX

01H H

4110 4111

MOV INX

M, A H

4112 4113 OBSERVATION:

MOV HLT

M, C

INPUT 4500 4501 4502 4503

OUTPUT

Powered By www.technoscriptz.com

3. TWO 8 BIT DATA MULTIPLICATION


AIM: To multiply two 8 bit numbers stored at consecutive memory locations and store the result in memory. ALGORITHM: LOGIC: Multiplication can be done by repeated addition. 1. 2. 3. 4. 5. 6. 7. 8. Initialize memory pointer to data location. Move multiplicand to a register. Move the multiplier to another register. Clear the accumulator. Add multiplicand to accumulator Decrement multiplier Repeat step 5 till multiplier comes to zero. The result, which is in the accumulator, is stored in a memory location.

RESULT: Thus the 8-bit multiplication was done in 8085p using repeated addition method.

Powered By www.technoscriptz.com

FLOW CHART:
START

[HL] 4500

B M

[HL] [HL]+1

A 00

C 00

[A] [A] +[M]

Is there any carry YES C C+1 B B-1

NO

NO

IS B=0 YES A

Powered By www.technoscriptz.com

[HL]

[HL]+1

[M]

[A]

[HL]

[HL]+1

[M]

[C]

STOP

Powered By www.technoscriptz.com

PROGRAM: ADDRESS OPCODE LABEL 4100 START 4101 4102 4103 4104 MNEMONICS LXI OPERAND H, 4500 COMMENT Initialize HL reg. to 4500 Transfer first data to reg. B Increment HL reg. to point next mem. Location. Clear the acc. Clear C reg for carry

MOV INX

B, M H

4105 4106 4107 4108 4109 410A 410B 410C 410D 410E 410F 4110 4111 4112 L1

MVI MVI

A, 00H C, 00H

ADD JNC

M NEXT

Add multiplicand multiplier times. Jump to NEXT if there is no carry Increment C reg Decrement B reg Jump to L1 if B is not zero. Increment HL reg. to point next mem. Location. Transfer the result from acc. to memory. Increment HL reg. to point next mem. Location. Transfer the result from C reg. to memory. Stop the program

NEXT

INR DCR JNZ

C B L1

INX

4113 4114

MOV INX

M, A H

4115 4116 OBSERVATION:

MOV HLT

M, C

INPUT 4500 4501 4502 4503

OUTPUT

Powered By www.technoscriptz.com

4. TWO 8 BIT DATA DIVISION


AIM: To divide two 8-bit numbers and store the result in memory. ALGORITHM: LOGIC: Division is done using the method Repeated subtraction. 1. Load Divisor and Dividend 2. Subtract divisor from dividend 3. Count the number of times of subtraction which equals the quotient 4. Stop subtraction when the dividend is less than the divisor .The dividend now becomes the remainder. Otherwise go to step 2. 5. stop the program execution.

RESULT: Thus an ALP was written for 8-bit division using repeated subtraction method and executed using 8085 p kits

Powered By www.technoscriptz.com

FLOWCHART:
START

B 00

[HL] 4500

A M

[HL] [HL]+1 M A-M

[B] [B] +1 NO

IS A<0 YES A A+ M

B B-1

[HL]

[HL]+1

[M]

[A]

[HL]

[HL]+1

[M]

[B]

STOP

Powered By www.technoscriptz.com

PROGRAM: ADDRESS 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 410A 410B 410C 410D 410E 410F 4110 4111 4112 LOOP OPCODE LABEL MNEMO NICS MVI LXI OPERA ND B,00 H,4500 COMMENTS Clear B reg for quotient Initialize HL reg. to 4500H Transfer dividend to acc. Increment HL reg. to point next mem. Location. Subtract divisor from dividend Increment B reg Jump to LOOP if result does not yield borrow Add divisor to acc. Decrement B reg Increment HL reg. to point next mem. Location. Transfer the remainder from acc. to memory. Increment HL reg. to point next mem. Location. Transfer the quotient from B reg. to memory. Stop the program

MOV INX SUB INR JNC

A,M H M B LOOP

ADD DCR INX MOV INX MOV HLT

M B H M,A H M,B

OBSERVATION:

S.NO 1 2 ADDRESS 4500 4501 4500 4501

INPUT DATA

ADDRESS 4502 4503 4502 4503

OUTPUT DATA

Powered By www.technoscriptz.com

5. TWO 16 BIT DATA MULTIPLICATION


AIM: To multiply two 16 bit numbers and store the result in memory. ALGORITHM: 1. 2. 3. 4. Get the multiplier and multiplicand. Initialize a register to store partial product. Add multiplicand, multiplier times. Store the result in consecutive memory locations.

RESULT: Thus the 16-bit multiplication was done in 8085p using repeated addition method.

Powered By www.technoscriptz.com

FLOWCHART: START

L H

[8050] [8051]

SP

HL

L H

[8052] [8053]

DE

HL

HL BC

0000 0000

HL

HL+SP

NO

Is Carry flag set? YES BC BC+1

DE

DE+1

NO

Is Zero flag set? YES

Powered By www.technoscriptz.com

[8054] [8055]

L H

[8056] [8057]

C B

STOP

Powered By www.technoscriptz.com

PROGRAM ADDRESS OPCODE LABEL MNEM ONICS 8000 START LHLD 8001 8002 8003 SPHL 8004 LHLD 8005 8006 8007 XCHG 8008 LXI 8009 800A 800B LXI 800C 800D 800E LOOP DAD 800F JNC 8010 8011 8012 INX 8013 NEXT DCX 8014 MOV 8015 ORA 8016 JNZ 8017 8018 8019 SHLD 801A 801B 801C MOV 801D STA 801E 801F 8020 MOV 8021 STA 8022 8023 8024 HLT OBSERVATION:
ADDRESS INPUT DATA OUTPUT ADDRESS DATA

OPERAN D 8050

COMMENTS Load the first No. in stack pointer through HL reg. pair

8052

Load the second No. in HL reg. pair & Exchange with DE reg. pair.

H, 0000H Clear HL & DE reg. pairs. B, 0000H

SP NEXT

Add SP with HL pair. If there is no carry, go to the instruction labeled NEXT Increment BC reg. pair Decrement DE reg. pair. Move the content of reg. E to Acc. OR Acc. with D reg. If there is no zero, go to instruction labeled LOOP Store the content of HL pair in memory locations 8054 & 8055. Move the content of reg. C to Acc. Store the content of Acc. in memory location 8056. Move the content of reg. B to Acc. Store the content of Acc. in memory location 8056. Stop program execution

B D A,E D LOOP

8054

A, C 8056

A, B 8057

8050 8051 8052

8054 8055 8056

Powered By www.technoscriptz.com

8053

8057

6. LARGEST ELEMENT IN AN ARRAY


AIM: To find the largest 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 largest number in the given array is found out.

Powered By www.technoscriptz.com

FLOW CHART: START [HL] [8100H]

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

NO

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

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

NO

Powered By www.technoscriptz.com

PROGRAM: ADDRE SS 8001 8002 8003 8004 8005 8006 8007 8008 8009 800A 800B 800C 800D 800E 800F 8010 8011 8012 8013 8014 OPCO DE LABEL MNEM ONICS LXI OPER AND H,8100 COMMENTS 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

8105

Store the result in a memory location. Stop the program

HLT

OBSERVATION: INPUT ADDRESS DATA 8100 8101 8102 8103 8104 OUTPUT ADDRESS DATA 8105

Powered By www.technoscriptz.com

7. SMALLEST ELEMENT IN AN ARRAY


AIM: 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.

Powered By www.technoscriptz.com

FLOW CHART: START [HL] [8100H]

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

YES

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

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

NO

Powered By www.technoscriptz.com

PROGRAM: ADDRE SS 8001 8002 8003 8004 8005 8006 8007 8008 8009 800A 800B 800C 800D 800E 800F 8010 8011 8012 8013 8014 OPCO DE LABEL MNEM ONICS LXI OPER AND H,8100 COMMENTS 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 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

MVI MOV INX CMP JC

B,04 A,M H M LOOP

LOOP1

LOOP

MOV DCR JNZ

A,M B LOOP1

STA

8105

Store the result in a memory location. Stop the program

HLT

OBSERVATION: INPUT ADDRESS DATA 8100 8101 8102 8103 8104 OUTPUT ADDRESS DATA 8105

Powered By www.technoscriptz.com

8.ASCENDING ORDER
AIM: 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 I 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.

Powered By www.technoscriptz.com

FLOWCHART:

START [B] 04H [HL] [8100H]

[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 Powered By www.technoscriptz.com

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

NO

IS [B] = 0? YES STOP

NO

Powered By www.technoscriptz.com

PROGRAM: ADDR E SS 8000 8001 8002 8003 8004 8005 8006 8007 8008 8009 800A 800B 800C 800D 800E 800F 8010 8011 8012 8013 8014 8015 8016 8017 8018 8019 801A OPCO DE LABEL MNEM ONICS MVI LOOP 3 LXI OPER AND B,04 H,8100 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

MVI LOOP2 MOV INX CMP JC

C,04 A,M H M LOOP1

LOOP1

MOV MOV DCX MOV INX DCR JNZ

D,M M,A H M,D H C LOOP2

DCR JNZ

B LOOP3

Decrement B reg If B is not Zero go to loop3

HLT

Stop the program

OBSERVATION: INPUT MEMORY LOCATION 8100 8101 8102 8103 DATA MEMORY LOCATION 8100 8101 8102 8103 OUTPUT DATA

Powered By www.technoscriptz.com

8104

8104

9. DESCENDING ORDER
AIM: 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 I 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.

Powered By www.technoscriptz.com

FLOWCHART:

START [B] 04H [HL] [8100H]

[C] 04H [A] [HL] [HL [HL] + 1

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

[HL] [A]

[HL] [HL] - 1

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

A Powered By www.technoscriptz.com

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

NO

IS [B] = 0? YES STOP

NO

Powered By www.technoscriptz.com

PROGRAM: ADDRE SS 8000 8001 8002 8003 8004 8005 8006 8007 8008 8009 800A 800B 800C 800D 800E 800F 8010 8011 8012 8013 8014 8015 8016 8017 8018 8019 801A OPCO DE LABEL MNEM ONICS MVI LXI OPER AND B,04 H,8100 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

LOOP 3

MVI LOOP2 MOV INX CMP JNC

C,04 A,M H M LOOP1

LOOP1

MOV MOV DCX MOV INX DCR JNZ

D,M M,A H M,D H C LOOP2

DCR JNZ

B LOOP3

Decrement B reg If B is not Zero go to loop3

HLT

Stop the program

OBSERVATION: INPUT MEMORY LOCATION 8100 8101 8102 8103 DATA MEMORY LOCATION 8100 8101 8102 8103 OUTPUT DATA

Powered By www.technoscriptz.com

8104

8104

10. CODE CONVERSION DECIMAL TO HEX


AIM: 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 ALP program for conversion of decimal to hexadecimal was written and executed.

Powered By www.technoscriptz.com

Powered By www.technoscriptz.com

FLOWCHART:

START

HL A

4500H 00

B B

00H B+1

A +1

Decimal adjust accumulator

NO

Is A=M?

YES
A B

8101

Stop

Powered By www.technoscriptz.com

PROGRAM: ADDRE SS 8000 8001 8002 8003 8004 8005 8006 8007 8008 8009 800A 800B 800C 800D 800E 800F 8010 8011 8012 8013 OPCO DE LABEL MNEM ONICS LXI OPER AND H,8100 COMMENTS Initialize HL reg. to 8100H 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

MVI MVI LOOP INR ADI DAA CMP JNZ

A,00 B,00 B 01

M LOOP

MOV STA

A,B 8101

HLT

RESULT: INPUT ADDRESS DATA 8100 OUTPUT ADDRESS DATA 8101

Powered By www.technoscriptz.com

11. CODE CONVERSION HEXADECIMAL TO DECIMAL


AIM: 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.

Powered By www.technoscriptz.com

START

FLOWCHART:
HL A 8100H 00

B C B

00H 00H B+1

A +1

Decimal adjust accumulator

Is there carry?

C D A,

C+1 A B,

Is A=M?

NO 8101 8102 A, A YES A


Stop

Powered By www.technoscriptz.com

PROGRAM: ADDRE SS 8000 8001 8002 8003 8004 8005 8006 8007 8008 8009 800A 800B 800C 800D 800E 800F 8010 8011 8012 8013 8014 8015 8016 8017 8018 8019 801A 801B 801C 801D 801E 801F OPCO DE LABEL MNEM ONICS LXI OPER AND H,8100 COMMENTS Initialize HL reg. to 8100H 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

MVI MVI MVI LOOP INR ADI DAA JNC

A,00 B,00 C,00 B 01

NEXT

NEXT

INR MOV MOV CMP MOV JNZ

C D,A A,B M A,D LOOP

STA

8101

MOV STA

A,C 8102

HLT

RESULT: INPUT ADDRESS 8100 OUTPUT ADDRESS DATA 8101 8102 Powered By www.technoscriptz.com

DATA

12. BCD ADDITION


AIM: To add two 8 bit BCD numbers stored at consecutive memory locations. ALGORITHM: 1. 2. 3. 4. 5. Initialize memory pointer to data location. Get the first number from memory in accumulator. Get the second number and add it to the accumulator Adjust the accumulator value to the proper BCD value using DAA instruction. Store the answer at another memory location.

RESULT: Thus the 8 bit BCD numbers stored at 4500 &4501 are added and the result stored at 4502 & 4503.

Powered By www.technoscriptz.com

FLOW CHART:

START

[C]

00H

[HL]

4500H

[A]

[M]

[HL]

[HL]+1

[A] [A]+[M] Decimal Adjust Accumulator NO

Is there aYES Carry ?

[C]

[C]+1

[HL]

[HL]+1

[M]

[A]

[HL]

[HL]+1

[M]

[C]

STOP

Powered By www.technoscriptz.com

PROGRAM: ADDRESS OPCODE LABEL 4100 START 4103 4102 4103 4104 4105 4106 MNEMONICS OPERAND MVI C, 00 LXI H, 4500 COMMENT Clear C reg. Initialize HL reg. to 4500 Transfer first data to accumulator Increment HL reg. to point next memory Location. Add first number to acc. Content. Decimal adjust accumulator Jump to location if result does not yield carry. Increment C reg. Increment HL reg. to point next memory Location. Transfer the result from acc. to memory. Increment HL reg. to point next memory Location. Move carry to memory Stop the program

MOV INX

A, M H

4107 4108 4109 410A 410B 410C 410D L1

ADD DAA JNC

L1

INR INX

C H

410E 410F

MOV INX

M, A H

4110 4111

MOV HLT

M, C

OBSERVATION:

INPUT 4500 4501 4502 4503

OUTPUT

Powered By www.technoscriptz.com

13. BCD SUBTRACTION


AIM: To Subtract two 8 bit BCD numbers stored at consecutive memory locations. ALGORITHM: 1. 2. 3. 4. 5. Load the minuend and subtrahend in two registers. Initialize Borrow register to 0. Take the 100s complement of the subtrahend. Add the result with the minuend which yields the result. Adjust the accumulator value to the proper BCD value using DAA instruction. If there is a carry ignore it. 6. If there is no carry, increment the carry register by 1 7. Store the content of the accumulator (result)and borrow register in the specified memory location

RESULT: Thus the 8 bit BCD numbers stored at 4500 &4501 are subtracted and the result stored at 4502 & 4503.

Powered By www.technoscriptz.com

FLOW CHART:
START

[D] HL B HL C A [A] [A] [A]

00H 4500 M HL+ 1 M 99 [A] [C] [A]+1 [A]+[B] DAA

Is there a Carry ?

YES

NO
[D] [D]+1

[HL]

[HL]+1

[4502] [4503]

A D

STOP

Powered By www.technoscriptz.com

PROGRAM: ADDRESS OPCODE LABEL 4100 START 4101 4102 4103 4104 4105 4106 MNEMONICS OPERAND COMMENT MVI D, 00 Clear D reg. LXI H, 4500 Initialize HL reg. to 4500 Transfer first data to accumulator Increment HL reg. to point next mem. Location. Move second no. to B reg. Move 99 to the Accumulator Subtract [C] from acc. Content. Increment A register Add [B] with [A] Adjust Accumulator value for Decimal digits Jump on carry to loop

MOV INX

B, M H

4107 4108 4109 410A 410B 410C 410D 410E 410F 4110 4111 4112 4113 4114 LOOP

MOV MVI SUB INR ADD DAA JC

C, M A, 99 C A B

LOOP

INR INX MOV INX

D H M,A H

4115 4116 OBSERVATION:

MOV HLT

M, D

Increment D reg. Increment HL register pair Move the Acc.content to the memory location Increment HL reg. to point next mem. Location. Transfer D register content to memory. Stop the program

INPUT 4500 4501 4502 4503

OUTPUT

Powered By www.technoscriptz.com

Você também pode gostar