Sunday, 6 January 2013

Microprocessor-8085-programs-part-B(CYCLE:1)



10.    Largest element in an array
11.    Smallest element in an array
12.    Ascending order
13.    Descending order
14.    BCD addition
15.    BCD subtraction
16.    BLOCK TRANSFER
17.    Fibonacci series
 
10. 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
4001


LXI
H,4100
Initialize HL reg. to 4100H
4002




4003




4004


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




4006


MOV
A,M
Transfer first data to acc.
4007

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


CMP
M
Compare M & A
4009


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




400B




400C


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

LOOP
DCR
B
Decrement B reg
400E


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




4010




4011


STA
4105
Store the result in a memory location.
4012




4013




4014


RST 1

Stop the program

OBSERVATION:

INPUT
OUTPUT
ADDRESS
DATA
ADDRESS
DATA
4100

4105

4101



4102



4103



4104













11. 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
4001


LXI
H,4100
Initialize HL reg. to 4100H
4002




4003




4004


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




4006


MOV
A,M
Transfer first data to acc.
4007

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


CMP
M
Compare M & A
4009


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




400B




400C


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

LOOP
DCR
B
Decrement B reg
400E


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




4010




4011


STA
4105
Store the result in a memory location.
4012




4013




4014


RST 1

Stop the program

OBSERVATION:

INPUT
OUTPUT
ADDRESS
DATA
ADDRESS
DATA
4100

4105

4101



4102



4103



4104










12.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   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.







PROGRAM:

ADDRESS
OPCODE
LABEL
MNEMONICS
OPERAND
COMMENTS
4000


MVI
B,04
Initialize B reg with number of comparisons (n-1)
4001




4002

LOOP 3
LXI
H,4100
Initialize HL reg. to
4100H
4003




4004




4005


MVI
C,04
Initialize C reg with no. of comparisons(n-1)
4006




4007

LOOP2
MOV
A,M
Transfer first data to acc.
4008


INX
H
Increment HL reg.  to point next memory location
4009


CMP
M
Compare M & A
400A


JC
LOOP1
If A is less than M, then go to LOOP1
400B




400C




400D


MOV
D,M
Transfer data from M to D reg
400E


MOV
M,A
Transfer data from acc to M
400F


DCX
H
Decrement HL pair
4010


MOV
M,D
Transfer data from D to M
4011


INX
H
Increment HL pair
4012

LOOP1
DCR
C
Decrement C register
4013


JNZ
LOOP2
If C is not zero go to LOOP2
4014




4015




4016


DCR
B
Decrement B register
4017


JNZ
LOOP3
If B is not Zero go to LOOP3
4018




4019




401A


RST 1

Stop the program



OBSERVATION:

INPUT
OUTPUT
ADDRESS
DATA
ADDRESS
DATA
4100

4100

4101

4101

4102

4102

4103

4103

4104

4104




13. 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,                   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.

 

PROGRAM:

ADDRESS
OPCODE
LABEL
MNEMONICS
OPERAND
COMMENTS
4000


MVI
B,04
Initialize B reg with number of comparisons (n-1)
4001




4002

LOOP3
LXI
H,4100
Initialize HL reg. to 4100H
4003




4004




4005


MVI
C,04
Initialize C reg with no. of comparisons(n-1)
4006




4007

LOOP2
MOV
A,M
Transfer first data to acc.
4008


INX
H
Increment HL reg.  to point next memory location
4009


CMP
M
Compare M & A
400A


JNC
LOOP1
If A is greater than M then go to LOOP1
400B




400C




400D


MOV
D,M
Transfer data from M to D reg
400E


MOV
M,A
Transfer data from acc to M
400F


DCX
H
Decrement HL pair
4010


MOV
M,D
Transfer data from D to M
4011


INX
H
Increment HL pair
4012

LOOP1
DCR
C
Decrement C reg
4013


JNZ
LOOP2
If C is not zero go to LOOP2
4014




4015




4016


DCR
B
Decrement B reg
4017


JNZ
LOOP3
If B is not Zero go to LOOP3
4018




4019




401A


RST 1

Stop the program



OBSERVATION:

INPUT
OUTPUT
MEMORY
LOCATION
DATA
MEMORY
LOCATION
DATA
4100

4100

4101

4101

4102

4102

4103

4103

4104

4104


  14. BCD ADDITION

AIM:

             To add two 8 bit BCD numbers stored at consecutive memory locations.

ALGORITHM:

1.      Initialize memory pointer to data location.
2.      Get the first number from memory in accumulator.
3.      Get the second number and add it to the accumulator
4.      Adjust the accumulator value to the proper BCD value using DAA instruction.
5.      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.



PROGRAM:

ADDRESS
OPCODE
LABEL
MNEMONICS
OPERAND
COMMENT
4100

START
MVI
C, 00
Clear C reg.
4101           




4102


LXI
H, 4500
Initialize HL reg. to 4500
4103




4104




4105


MOV
A, M
Transfer first data to accumulator
4106


INX
H
Increment HL reg.  to point next memory    Location.
4107


ADD
M
Add first number to acc. content.
4108


DAA

Decimal adjust acc.
4109


JNC
L1
Jump to location if result does not yield carry.
410A




410B




410C


INR
C
Increment C reg.
410D

L1
INX
H
Increment HL reg.  to point next memory Location.
410E


MOV
M, A
Transfer the result from acc. to memory.
410F


INX
H
Increment HL reg. to point next memory Location.
4110


MOV
M, C
Move carry to memory
4111


RST 1

Stop the program

OBSERVATION:

INPUT
OUTPUT
ADDRESS
DATA
ADDRESS
DATA
4500

4502

4501

4503

                                                             


15. BCD SUBTRACTION
AIM:

             To subtract two 8 bit BCD numbers stored at consecutive memory locations.

ALGORITHM:

1.      Load the minuend and subtrahend in two registers.
2.      Initialize Borrow register to 0.
3.      Take the 100’s complement of the subtrahend.
4.      Add the result with the minuend, which yields the result.
5.      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.
 
PROGRAM:

ADDRESS
OPCODE
LABEL
MNEMONICS
OPERAND
COMMENT
4100

START
MVI
D, 00
Clear D reg.
4101




4102


LXI
H, 4500
Initialize HL reg. to 4500
4103




4104




4105


MOV
B, M
Transfer first data to accumulator
4106


INX
H
Increment HL reg. to point next memory location.
4107


MOV
C, M
Move second no. to B reg.
4108


MVI
A, 99
Move 99 to the accumulator
4109




410A


SUB
C
Subtract [C] from  acc. content.
410B


INR
A
Increment  A  register
410C


ADD
B
Add [B] with [A]
410D


DAA

Adjust Accumulator value for decimal digits
410E


JC
LOOP
Jump on carry to loop
410F




4110




4111


INR
D
Increment D reg.
4112

LOOP
INX
H
Increment HL register pair
4113


MOV
M , A
Move the Acc.content to the memory location
4114


INX
H
Increment HL reg. to point next memory location.
4115


MOV
M, D
Transfer D register content to memory.
4116


RST 1

Stop the program

OBSERVATION:

INPUT
OUTPUT
ADDRESS
DATA
ADDRESS
DATA
4500

4502

4501

4503


                         16.BLOCK TRANSFER

AIM:
          To transfer 16 bytes of data from 4050h to 4070h


ALGORITHM:




1.      Initialize counter =16,source memory pointer, and destination memory pointer
2.       
3.      Get the byte from   source memory location and store  the byte in destination memory location.
4.      Increment the source memory  pointer and the destination memory pointer
5.      Decrement counter if counter is not zero,goto step=2 and repeat steps





RESULT:

                    16 bytes of data are transferred   from  a source memory block(4050h) to destination    memory  block (4070h).









Program:

ADDRESS
OPCODE
LABEL
MNEMONICS
OPERAND
COMMENT
4000

START
MVI
C,06H
Initialize counter in c reg=06
4001




4002


LXI
H, 4050
Initialize  source memory pointer
4003




4004




4005


LXI
D,4070
Initialize destination memory pointer
4006





4007





4008

LOOP
MOV
A, M
Transfer first byte to accumulator
4009


STAX
D
store contents of accumulator in
400A


INX
H
Increment HL reg paircontent.
400B


INX
D
Increment  DE reg pair
400C


DCR
C
Decrement c reg pair
400D


JNZ
LOOP
Jmp to loop if  c reg is not zero




















OBSERVATION:


INPUT
OUTPUT
ADDRESS
DATA
ADDRESS
DATA
4050

4070

4051



4071

4052

4072

4053

4073

4054


4074

4055

4075




17.Fibonacci series

 AIM:

                 To  obtain the Fibonacci series using 8085.


ALGORITHM:

1.      Load memory location 4050 with 00h and 4051 with 01h

2.      Initialize counter with (n-2) for n values of  Fibonacci series

3.      Initialize the source memory pointer to 4050h

4.      Transfer first byte to accumulator and second byte into other register

5.      Add those two bytes and store it in accumulator and decimal adjust  the accumulator

6.      Store the contents of accumulator into specified location

7.      Decrement memory pointer and counter

8.      Repeat from step 4 if counter is not zero  



RESULT:

        The Fibonacci series is generated using 8085 microprocessor
 
 
Program:

ADDRESS
OPCODE
LABEL
MNEMONICS
OPERAND
COMMENT
4000

START
MVI
C,09H
Initialize counter in c reg=09
4001




4002


LXI
H, 4050
Initialize  source memory pointer
4003




4004




4005
loop

Mov
A,M
Transfer first data to acc.
4006


Inx
H
Increment HL reg pair
4007


Mov
B,M
Transfer contents of M reg to B reg
4008


INX
H
Increment HL reg pair.
ADD[B] with [A]store in [A]
4009


ADD
B
400A


DAA

DecimaLaDJUST aCUMULATOR
400B


MOV
M,A
Transfer contents of accumulator to m register
400C


DCX
H
Decrement HLreg pair
400D


DCR
C
Decrement c reg
400E


JNZ
LOOP
If c reg is not zero
       400F




Go to loop
      4010





     4011


        RST 1

Stops the program
 
OBSERVATION:

INPUT
OUTPUT
ADDRESS
DATA
ADDRESS
DATA
4050

4050

4051



4051



4052







4053



4054



4055



4056



4057



4058



4059



405A

No comments:

Post a Comment