Monday, May 21, 2012

MICROPROCESSORS & APPLICATIONS LAB MANUAL(Second half))


6(A). 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:

ADDRE
SS
OPCO
DE
LABEL
MNEM
ONICS
OPER
AND
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


HLT

Stop the program


OBSERVATION:

INPUT
OUTPUT
ADDRESS
DATA
ADDRESS
DATA
8100

8105

8101


8102


8103


8104










6(B). 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:

ADDRE
SS
OPCO
DE
LABEL
MNEM
ONICS
OPER
AND
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


HLT

Stop the program


OBSERVATION:

INPUT
OUTPUT
ADDRESS
DATA
ADDRESS
DATA
8100

8105

8101


8102


8103


8104










7(A).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.


PROGRAM:

ADDRE
SS
OPCO
DE
LABEL
MNEM
ONICS
OPER
AND
COMMENTS
8000


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




8002

LOOP 3
LXI
H,8100
Initialize HL reg. to
8100H
8003




8004




8005


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




8007

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


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


CMP
M
Compare M & A
800A


JC
LOOP1
If A is less than M then go to loop1
800B




800C




800D


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


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


DCX
H
Decrement HL pair
8010


MOV
M,D
Transfer data from D to M
8011


INX
H
Increment HL pair
8012

LOOP1
DCR
C
Decrement C reg
8013


JNZ
LOOP2
If C is not zero go to loop2
8014




8015




8016


DCR
 B
Decrement B reg
8017


JNZ
LOOP3
If B is not Zero go to loop3
8018




8019




801A


HLT

Stop the program


OBSERVATION:

INPUT
OUTPUT
MEMORY
LOCATION
DATA
MEMORY
LOCATION
DATA
8100

8100

8101

8101

8102

8102

8103

8103

8104

8104


7(B). 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.









PROGRAM:

ADDRE
SS
OPCO
DE
LABEL
MNEM
ONICS
OPER
AND
COMMENTS
8000


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




8002

LOOP 3
LXI
H,8100
Initialize HL reg. to
8100H
8003




8004




8005


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




8007

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


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


CMP
M
Compare M & A
800A


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




800C




800D


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


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


DCX
H
Decrement HL pair
8010


MOV
M,D
Transfer data from D to M
8011


INX
H
Increment HL pair
8012

LOOP1
DCR
C
Decrement C reg
8013


JNZ
LOOP2
If C is not zero go to loop2
8014




8015




8016


DCR
 B
Decrement B reg
8017


JNZ
LOOP3
If B is not Zero go to loop3
8018




8019




801A


HLT

Stop the program









OBSERVATION:

INPUT
OUTPUT
MEMORY
LOCATION
DATA
MEMORY
LOCATION
DATA
8100

8100

8101

8101

8102

8102

8103

8103

8104

8104

8(A). CODE CONVERSION –DECIMAL TO HEX


AIM:

            To convert a given decimal number to hexadecimal.

ALGORITHM:

1.      Initialize the memory location to the data pointer.
2.      Increment B register.
3.      Increment accumulator by 1 and adjust it to decimal every time.
4.      Compare the given decimal number with accumulator value.
5.      When both matches, the equivalent hexadecimal value is in B register.
6.      Store the resultant in memory location.

RESULT:

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






PROGRAM:

ADDRE
SS
OPCO
DE
LABEL
MNEM
ONICS
OPER
AND
COMMENTS
8000


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




8002




8003


MVI
A,00
Initialize A register.
8004




8005


MVI
B,00
Initialize B register..
8006




8007

LOOP
INR
B
Increment B reg.
8008


ADI
01
Increment A reg
8009




800A


DAA

Decimal Adjust Accumulator
800B


CMP
M
Compare M & A
800C


JNZ
LOOP
If acc and given number are not equal, then go to LOOP
800D




800E




800F


MOV
A,B
Transfer B reg to acc.
8010


STA
8101
Store the result in a memory location.
8011




8012




8013


HLT

Stop the program


RESULT:

INPUT
OUTPUT
ADDRESS
DATA
ADDRESS
DATA
         8100

8101















8(B). CODE CONVERSION –HEXADECIMAL TO DECIMAL


AIM:

            To convert a given hexadecimal number to decimal.

ALGORITHM:

1.      Initialize the memory location to the data pointer.
2.      Increment B register.
3.      Increment accumulator by 1 and adjust it to decimal every time.
4.      Compare the given hexadecimal number with B register value.
5.      When both match, the equivalent decimal value is in A register.
6.      Store the resultant in memory location.

RESULT:

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










PROGRAM:

ADDRE
SS
OPCO
DE
LABEL
MNEM
ONICS
OPER
AND
COMMENTS
8000


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




8002




8003


MVI
A,00
Initialize A register.
8004




8005


MVI
B,00
Initialize B register.
8006




8007


MVI
C,00
Initialize C register for carry.
8008




8009

LOOP
INR
B
Increment B reg.
800A


ADI
01
Increment A reg
800B




800C


DAA

Decimal Adjust Accumulator
800D


JNC
NEXT
If there is no carry go to NEXT.
800E




800F




8010


INR
C
Increment c register.
8011

NEXT
MOV
D,A
Transfer A to D
8012


MOV
A,B
Transfer B to A
8013


CMP
M
Compare M & A
8014


MOV
A,D
Transfer D to A
8015


JNZ
LOOP
If acc and given number are not equal, then go to LOOP
8016




8017




8018


STA
8101
Store the result in a memory location.
8019




801A




801B


MOV
A,C
Transfer C to A
801C


STA
8102
Store the carry in another memory location.
801D




801E




801F


HLT

Stop the program


RESULT:

INPUT
OUTPUT

ADDRESS
DATA
ADDRESS
DATA

8100

8101



8102


9(A) 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 accumulator
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


HLT

Stop the program


OBSERVATION:


INPUT
OUTPUT
4500

4502

4501

4503

                                                             



9(B). 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 mem. 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 mem. Location.
4115


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


HLT

Stop the program

OBSERVATION:


INPUT
OUTPUT
4500

4502

4501

4503

10. 2 X 2 MATRIX MULTIPLICATION



AIM:

            To perform the 2 x 2 matrix multiplication.

ALGORITHM:

 

  1. Load the 2 input matrices in the separate address and initialize the HL and the DE register pair with the starting address respectively.
  2. Call a subroutine for performing the multiplication of one element of a matrix with the other element of the other matrix.
  3. Call a subroutine to store the resultant values in a separate matrix.

RESULT:

Thus the 2 x 2  matrix multiplication is performed and the result is stored at 4700,4701 , 4702 & 4703.







PROGRAM:

ADDRESS
OPCODE
LABEL
MNEMONICS
OPERAND
COMMENT
8100


MVI
C, 00
Clear C reg.
8101




8102


LXI
H, 8500
Initialize HL reg. to
4500
8103




8104




8105

LOOP2
LXI
D, 8600
Load DE register pair
8106




8107




8108


CALL
MUL
Call subroutine MUL
8109




810A




810B


MOV
B,A
Move A to B reg.
810C


INX
H
Increment HL register pair .
810D


INX
D
Increment DE register pair
810E


INX
D
Increment DE register pair
810F


CALL 
MUL
Call subroutine MUL
8110




8111




8112


ADD
B
Add [B] with [A]
8113


CALL
STORE
Call subroutine STORE
8114




8115




8116


DCX
H
Decrement HL register pair
8117


DCX
D
Decrement DE register pair
8118


CALL
MUL
Call subroutine MUL
8119




811A




811B


MOV
B,A
Transfer A reg content  to B reg.
811C


INX
H
Increment HL register pair
811D


INX
D
Increment DE register pair
811E


INX
D
Increment DE register pair
811F


CALL
MUL
Call subroutine MUL
8120




8121




8122


ADD
B
Add A with B
8123


CALL
STORE
Call subroutine MUL
8124




8125




8126


MOV
A,C
Transfer C register content to Acc.
8127


CPI
04
Compare with 04 to check whether all elements are multiplied.
8128




8129


JZ
LOOP1
If completed, go to loop1
812A




812B




812C


INX
H
Increment HL register Pair.
812D


JMP
LOOP2
Jump to LOOP2.
812E





812F





8130

LOOP1
HLT

Stop the program.
8131

MUL
LDAX
D
Load acc from the memory location pointed by DE pair.
8132


MOV
D,A
Transfer acc content to D register.
8133


MOV
H,M
Transfer from memory to H register.
8134


DCR
H
Decrement H register.
8135


JZ
LOOP3
If H is zero go to LOOP3.
8136




8137




8138

LOOP4
ADD
D
Add Acc with D reg
8139


DCR
H
Decrement H register.
813A


JNZ
LOOP4
If H is not zero go to LOOP4.
813B




813C




813D

LOOP3
MVI
H,85
Transfer 85 TO H register.
813E




813F


MVI
D,86
Transfer 86 to D register.
8140




8141


RET

Return to main program.
8142

STORE
MVI
B,87
Transfer 87 to B register.
8143




8144


STAX
B
Load A from memory location pointed by BC pair.
8145


INR
C
Increment C register.
8146


RET

Return to main program.


OBSERVATION:

INPUT
OUTPUT
4500

4600

4700

4501

4601

4701

4502

4602

4702

4503

4603

4703




11. BIOS/DOS CALLS – DISPLAY

AIM:
      To display a message on the CRT screen of a microcomputer using DOS calls.

ALGORITHM:
  1. Initialize the data segment and the message to be displayed.
  2. Set function value for display.
  3. Point to the message and run the interrupt to display the message in the CRT.

PROGRAM:

ASSUME CS: CODE, DS: DATA
DATA SEGMENT
MSG DB 0DH, 0AH, “GOOD MORNING” , ODH, OAH, “$”
DATA ENDS
CODE SEGMENT
START:     MOV AX, DATA
                  MOV DS, AX
                  MOV AH, 09H
                  MOV DX, OFFSET MSG
                  INT 21H
                  MOV AH, 4CH
                  INT 21H
CODE ENDS
END START

RESULT:
A message is displayed on the CRT screen of a microcomputer using DOS calls
12. BIOS/DOS CALLS – FILE MANIPULATION
AIM:
To open a file using DOS calls.
ALGORITHM:
  1. Initialize the data segment, file name and the message to be displayed.
  2. Set the file attribute to create a file using a DOS call.
  3. If the file is unable t o create a file display the message 
PROGRAM:
ASSUME CS: CODE, DS: DATA
DATA SEGMENT
FILENAME DB “SAMPLE.DAT”, “$”
MSG DB 0DH, 0AH, “FILE NOT CREATED”, ODH, OAH, “$”
DATA ENDS
CODE SEGMENT
START:           MOV AX, DATA
                        MOV DS, AX
                        MOV DX, OFFSET FILENAME
                        MOV CX, 00H
                        MOV AH, 3CH
                        INT 21H
                        JNC LOOP1
                        MOV AX, DATA
                        MOV DS, AX
                        MOV DX, OFFSET MSG
                        MOV AH, 09H
                        INT 21H
LOOP1           MOV AH, 4CH
                        INT 21H
CODE ENDS
END START
RESULT:
A file is opened using DOS calls.
13. BIOS/DOS CALLS – DISK INFORMATION

AIM:
      To display the disk information.

ALGORITHM:
  1. Initialize the data segment and the message to be displayed.
  2. Set function value for disk information.
  3. Point to the message and run the interrupt to display the message in the CRT.

PROGRAM:

ASSUME CS: CODE, DS: DATA
DATA SEGMENT
MSG DB 0DH, 0AH, “GOOD MORNING” , ODH, OAH, “$”
DATA ENDS
CODE SEGMENT
START:     MOV AX, DATA
                  MOV DS, AX
                  MOV AH, 36H
                  MOV DX, OFFSET MSG
                  INT 21H
                  MOV AH, 4CH
                  INT 21H
CODE ENDS
END START

RESULT:
      The disk information is displayed.




1.8086 STRING MANIPULATION – SEARCH A WORD

AIM:
To search a word from a string.

ALGORITHM:
    1. Load the source and destination index register with starting and the ending address respectively.
    2. Initialize the counter with the total number of words to be copied.
    3. Clear the direction flag for auto incrementing mode of transfer.
    4. Use the string manipulation instruction SCASW with the prefix REP to search a word from string.
    5. If a match is found (z=1), display 01 in destination address. Otherwise, display 00 in destination address.
RESULT:
      A word is searched and the count of number of appearances is displayed.







PROGRAM:
ASSUME CS: CODE, DS: DATA
DATA SEGMENT
LIST DW 53H, 15H, 19H, 02H
DEST EQU 3000H
COUNT EQU 05H
DATA ENDS
CODE SEGMENT
START:           MOV AX, DATA
                        MOV DS, AX
                        MOV AX, 15H
                        MOV SI, OFFSET LIST
                        MOV DI, DEST
                        MOV CX, COUNT
                        MOV AX, 00
                        CLD
REP                 SCASW
            JZ LOOP
            MOV AX, 01
LOOP             MOV [DI], AX
                        MOV AH, 4CH
                        INT 21H
CODE ENDS
END START

INPUT:                     
LIST: 53H, 15H, 19H, 02H

OUTPUT:
      3000    01



No comments:

Post a Comment