Friday 16 February 2018

Microprocessor-8085-LARGEST/SMALLEST ELEMENT IN AN ARRAY

Microprocessor-8085-LARGEST/SMALLEST ELEMENT IN AN ARRAY

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.








PROGRAM:

ADDRESS
OPCO
DE
LABEL
MNEMONICS
OPERAND
COMMENTS
8001


LXI
H,8100
Initialize HL reg. to 8100H
8002




8003




8004


MVI
B,04
Initialize B reg with no. of comparisons (n-1)
8005




8006


MOV
A,M
Transfer first data to acc.
8007

LOOP1
INX
H
Increment HL reg.  to point next memory location
8008


CMP
M
Compare M & A
8009


JNC
LOOP
If A is greater than M then go to loop
800A




800B




800C


MOV
A,M
Transfer data from M to A reg
800D

LOOP
DCR
B
Decrement B reg
800E


JNZ
LOOP1
If B is not Zero go to loop1
800F




8010




8011


STA
8105
Store the result in a memory location.
8012




8013




8014


RST 5

Stop the program

OBSERVATION:

INPUT
OUTPUT
ADDRESS
DATA
ADDRESS
DATA
8100

8105

8101




8102




8103




8104





 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.



PROGRAM:

ADDRESS
OPCODE
LABEL
MNEMONICS
OPERAND
COMMENTS
8001


LXI
H,8100
Initialize HL reg. to 8100H
8002




8003




8004


MVI
B,04
Initialize B reg with no. of comparisons (n-1)
8005




8006


MOV
A,M
Transfer first data to acc.
8007

LOOP1
INX
H
Increment HL reg.  to point next memory location
8008


CMP
M
Compare M & A
8009


JC
LOOP
If A is lesser than M then go to loop
800A




800B




800C


MOV
A,M
Transfer data from M to A reg
800D

LOOP
DCR
B
Decrement B reg
800E


JNZ
LOOP1
If B is not Zero go to loop1
800F




8010




8011


STA
8105
Store the result in a memory location.
8012




8013




8014


RST 5

Stop the program







OBSERVATION:

INPUT
OUTPUT
ADDRESS
DATA
ADDRESS
DATA
8100

8105

8101




8102




8103




8104




Microprocessor 8085 Lab Cycle:1- 16 BIT-Addition/Subtraction/multiplication/Division Programs

Microprocessor 8085 Lab Cycle:1- 16 BIT-Addition/Subtraction/multiplication/ Division Programs

16 BIT DATA ADDITION


AIM:

            To add two 16-bit numbers stored at consecutive memory locations.

ALGORITHM:

1.      Initialize memory pointer to data location.
2.      Get the first number from memory and store in Register pair.
3.      Get the second number in memory and add it to the Register pair.
4.      Store the sum & carry in separate memory locations.

RESULT:

An ALP program for 16-bit addition was written and executed in 8085mp using special instructions.



PROGRAM:

ADDRESS
OPCODE
LABEL
MNEMONICS
OPERAND
COMMENT
8000

START
LHLD
8050H
Load the augend in HL pair
8001




8002




8003


XCHG

Load augend in DE pair through HL pair.
8004


LHLD
8052H
Load the addend in HL pair
8005




8006




8007


MVI
A, 00H
Initialize reg. A for carry
8008




8009


DAD
D
Add the contents of HL
Pair with that of DE pair.
800A


JNC
LOOP
If there is no carry, go to the instruction labeled LOOP.
800B




800C




800D


INR
A
Otherwise increment  register A
800E

LOOP
SHLD
8054H
Store the content of HL Pair in 8054H
(LSB of sum)
800F




8010




8011


STA
8056H
Store the carry in 8056H through Acc.
(MSB of sum).
8012




8013




8014


RST 5

Stop the program.






OBSERVATION:

INPUT
OUTPUT
ADDRESS
DATA
ADDRESS
DATA
8050H

8054H

8051H

8055H

8052H

8056H

8053H




 

16 BIT DATA SUBTRACTION


AIM:

             To subtract two 16-bit numbers stored at consecutive memory locations.

ALGORITHM:

1.      Initialize memory pointer to data location.
2.      Get the subtrahend from memory and transfer it to register pair.
3.      Get the minuend from memory and store it in another register pair.
4.      Subtract subtrahend from minuend.
5.      Store the difference and borrow in different memory locations.

RESULT:

An ALP program for subtracting two 16-bit numbers was written and executed.

   

  
PROGRAM:

ADDRESS
OPCODE
LABEL
MNEMONICS
OPER
AND
COMMENTS
8000

START
MVI
C, 00
Initialize C reg.
8001




8002


LHLD
8050H
Load the subtrahend in DE reg. Pair through HL reg. pair.
8003




8004




8005


XCHG

8006


LHLD
8052H
Load the minuend in HL reg. Pair.
8007




8008




8009


MOV
A, L
Move content of reg. L to Acc.
800A


SUB
E
Subtract the content of  reg. E from that of acc.
800B


MOV
L, A
Move content of Acc. to reg. L
800C


MOV
A, H
Move content of reg. H to Acc.
800D


SBB
D
Subtract content of reg. D with that of Acc.
800E


MOV
H, A
Transfer content of acc. to reg. H
800F


SHLD
8054H
Store the content of HL pair in memory location 8054H.
8010




8011




8012


JNC
NEXT
If there is borrow, go to the instruction labeled NEXT.
8013




8014




8015


INR
C
Increment reg. C
8016

NEXT
MOV
A, C
Transfer the content of reg. C to Acc.
8017


STA
8056H
Store the content of acc. to the memory location 8056H
8018




8019




801A


RST 5

Stop the program execution.

OBSERVATION:

INPUT
OUTPUT
ADDRESS
DATA
ADDRESS
DATA
8050H

8054H

8051H

8055H

8052H

8056H

8053H









16 BIT MULTIPLICATION


AIM:

To multiply two 16 bit numbers and store the result in memory.

ALGORITHM:

  1. Get the multiplier and multiplicand.
  2. Initialize a register to store partial product.
  3. Add multiplicand, multiplier times.
  4. Store the result in consecutive memory locations.

RESULT:

16-bit multiplication was done in 8085mp using repeated addition method.



PROGRAM:

ADDRESS
OPCODE
LABEL
MNEMONICS
OPERAND
COMMENTS
8000

START
LHLD
8050
Load the first No. in stack pointer through HL reg. pair
8001




8002




8003


SPHL

8004


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




8006




8007


XCHG

8008


LXI
H, 0000H
Clear HL & DE reg. pairs.
8009




800A




800B


LXI
B, 0000H
800C




800D




800E

LOOP
DAD
SP
Add SP with HL pair.
800F


JNC
NEXT
If there is no carry, go to the instruction labeled NEXT
8010




8011




8012


INX
B
Increment BC reg. pair
8013

NEXT
DCX
D
Decrement DE reg. pair.
8014


MOV
A,E
Move the content of reg. E to Acc.
8015


ORA
D
OR Acc. with D reg.
8016


JNZ
LOOP
If there is no zero, go to instruction labeled LOOP
8017




8018




8019


SHLD
8054
Store the content of HL pair inmemory locations 8054 & 4055.
801A




801B




801C


MOV
A, C
Move the content of reg. C to Acc.
801D


STA
8056
Store the content of Acc. in memory location 8056.
801E




801F




8020


MOV
A, B
Move the content of reg. B to Acc.
8021


STA
8057
Store the content of Acc. in memory location 8057.
8022




8023




8024


RST 5

Stop  program execution

OBSERVATION:

INPUT
OUTPUT
ADDRESS
DATA
ADDRESS
DATA
8050

8054

8051

8055

8052

8056

8053

8057

 

 16- BIT DIVISION


AIM:
               
 To divide two 16-bit numbers and store the result in memory using 8085 mnemonics.
ALGORITHM:

  1. Get the dividend and divisor.
  2. Initialize the register for quotient.
  3. Repeatedly subtract divisor from dividend till dividend becomes less than divisor.
  4. Count the number of subtraction which equals the quotient.
  5. Store the result in memory.

RESULT:

The 16-bit Division was done in 8085mp using repeated subtraction method.


PROGRAM:

ADDRESS
OPCODE
LABEL
MNEMONICS
OPERAND
COMMENTS
8000

START
LHLD
8050
Load the first No. in stack pointer through HL reg. pair
8001




8002




8003


XCHG

8004


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




8006




8007


LXI
B, 0000H
Clear BC reg. pair.
8008




8009




800A

LOOP
MOV
A, L
Move the content of reg. L to Acc.
800B


SUB
E
Subtract reg. E from that of Acc.
800C


MOV
L, A
Move the content of Acc to  L.
800D


MOV
A, H
Move the content of reg. H Acc.
800E


SBB
D
Subtract  reg. D from that of Acc.
800F


MOV
H, A
Move the content of Acc to  H.
8010


INX
B
Increment reg.  Pair BC
8011


JNC
LOOP
If there is no carry, go to the location labeled LOOP.
8012




8013




8014


DCX
B
Decrement BC reg. pair.
8015


DAD
D
Add content of HL and DE reg. pairs.
8016


SHLD
8054
Store the content of HL pair in 8054 & 8055.
8017




8018




8019


MOV
A, C
Move the content of reg. C to Acc.
801A


STA
8056
Store the content of Acc. in memory 8056
801B




801C




801D


MOV
A, B
Move the content of reg. B to Acc.
801E


STA
8057
Store the content of Acc. in memory 8057.
801F




8020




8021


RST 5

Stop the program execution.

OBSERVATION:

INPUT
OUTPUT
ADDRESS
DATA
ADDRESS
DATA
8050

8054

8051

8055

8052

8056

8053

8057