0% found this document useful (0 votes)
320 views

Microprocessor Lab Manual

The document describes algorithms for performing 8-bit and 16-bit arithmetic operations using an 8085 microprocessor. For 8-bit operations, it provides code to add, subtract, multiply, and divide two 8-bit data with carry. For 16-bit operations, it provides an algorithm for adding and subtracting two 16-bit data with carry that uses the HL and DE register pairs to store and manipulate the multi-byte values. The goal is to write programs to perform these arithmetic operations using an 8085 microprocessor kit.

Uploaded by

sivagamasundhari
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
320 views

Microprocessor Lab Manual

The document describes algorithms for performing 8-bit and 16-bit arithmetic operations using an 8085 microprocessor. For 8-bit operations, it provides code to add, subtract, multiply, and divide two 8-bit data with carry. For 16-bit operations, it provides an algorithm for adding and subtracting two 16-bit data with carry that uses the HL and DE register pairs to store and manipulate the multi-byte values. The goal is to write programs to perform these arithmetic operations using an 8085 microprocessor kit.

Uploaded by

sivagamasundhari
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 36

EX.

No: 1 8 BIT ARITHMETIC OPERATIONS

AIM
To write programs to perform arithmetic operations using 8085 microprocessor.

APPARATUS REQUIRED
8085 microprocessor kit
+5V Power supply

ALGORITHM
TO ADD TWO 8 BIT DATA WITH CARRY
1) Start
2) One data is loaded in accumulator and content of accumulator is moved to
register B.
3) The second data is loaded in accumulator.
4) Initialize C register with 00H.
5) The content of register B is added with the content of accumulator.
6) A conditional jump instruction is used. If no carry occurs, the result is
stored in any address. If carry occurs, the content of C register is
incremented by 1.
7) Content of C register is moved to accumulator and stored in any address.
8) Stop.

TO SUBTRACT TWO 8 BIT DATA WITH CARRY


1) Start
2) One data is loaded in accumulator and content of accumulator is moved to
register B.
3) The second data is loaded in accumulator.
4) Initialize C register with 00)H.
5) The content of register B is subtracted from the content of accumulator.
6) A conditional jump instruction is used. If no carry occurs, the result is
stored in any address. If carry occurs, the content of C register is
incremented by 1.
7) Content of C register is moved to accumulator and stored in any address.
8) Stop.
TO MULTIPLY TWO 8 BIT DATA
1) Start
2) Load the two datas in B and D register.
3) Clear the accumulator and C register.
4) Add the content of B register with accumulator.
5) If carry occurs, C register content is incremented by 1.
6) Decrement D register content & check for zero flag. If no zero occurs, go
to step 4.
7) Otherwise store the accumulator & C register content in separate memory
locations.
8) Stop.
TO DIVIDE TWO 8 BIT DATA
1. Load the divendend in accumulator & divisor in B register.
2. Clear C register content .
3. Compare accumulator & B register content.
4. If carry occurs, go to step 8.
5. Subtract B register value from Accumulator.
6. Increment C register value (Quotient).
7. GO to step 3.
8. Store the accumulator & C register value in separate
memory locations.
9. Stop.

TO ADD TWO 8 BIT DATA WITH CARRY

ADDRESS LABEL MNEMONICS OPCODE COMMENTS


8000 LDA 8500 3A 00 85 Data in 8500)H is loaded
in acc.
8003 MOV B,A 47 Acc. Value is moved to
B register.
8004 LDA 8501 3A 01 85 Data in 8501)H is loaded
in acc.
8007 MVI C,00 0E 00 Clear C register value.
8009 ADD B 80 [B] value is added with
accumulator.
800A JNC L1 D2 OE 80 If no carry occurs, jump
to L1.
800D INR C 0C [C]=[C] + 1
800E L1: STA 8600 32 00 86 Store accumulator value
in 8600)H.
8011 MOV A,C 79 [C] value is moved to
acc.
8012 STA 8601 32 01 86 Store accumulator value
in 8601)H.
8015 HLT 76 Stop.

TO SUBTRACT TWO 8 BIT DATA WITH CARRY

ADDRESS LABEL MNEMONICS OPCODE COMMENTS


8000 LDA 8500 3A 00 85 Data in 8500)H is loaded
in acc.
8003 MOV B,A 47 Acc. Value is moved to
B register.
8004 LDA 8501 3A 01 85 Data in 8501)H is loaded
in acc.
8007 MVI C,00 0E 00 Clear C register value.
8009 SUB B 90 [B] value is subtracted
from accumulator.
800A JNC L1 D2 OE 80 If no carry occurs, jump
to L1.
800D INR C 0C [C]=[C] + 1
800E L1: STA 8600 32 00 86 Store accumulator value
in 8600)H.
8011 MOV A,C 79 [C] value is moved to
acc.
8012 STA 8601 32 01 86 Store accumulator value
in 8601)H.
8015 HLT 76 Stop.

TO MULTIPLY TWO 8 BIT DATA

ADDRESS LABEL MNEMONICS OPCODE COMMENTS


8000 LDA 8500 3A 00 85 Data in 8500)H is loaded
in acc.
8003 MOV B,A 47 Acc. Value is moved to
B register.
8004 LDA 8501 3A 01 85 Data in 8501)H is loaded
in acc.
8007 MOV D,A Acc. Value is moved to
D register.
8008 MVI C,00 3E 00 Clear C register value.
800A XRA A AF Clear acc. Value.
800B L2: ADD B 80 B] value is added with
accumulator.
800C JNC L1 D2 10 80 If no carry occurs, jump
to L1.
800F INR C 0C [C]=[C] + 1
8010 L1: DCR D [D]=[D] 1
8011 JNZ L2 0B 80 If no zero occurs, go to
L2.
8014 STA 8600 32 00 86 Store accumulator value
in 8600)H.
8017 MOV A,C 79 [C] value is moved to
acc.
8018 STA 8601 32 01 86 Store accumulator value
in 8601)H.
801B HLT 76 Stop.
TO DIVIDE TWO 8 BIT DATA

ADDRESS LABEL MNEMONICS OPCODE COMMENTS


8000 LDA 8500 3A 00 85 Data in 8500)H is loaded
in acc.
8003 MOV B,A 47 Acc. Value is moved to
B register.
8004 LDA 8501 3A 01 85 Data in 8501)H is loaded
in acc.
8007 MVI C,00 0E 00 Clear C register value.

8009 L2: CMP B B8 Compare B register


value with acc.
800A JC L1 DA 12 80 If carry occurs, go to L1
Subtract [B] reg. Value
800D SUB B 90 from acc.
[C]= [C] + 1
800E INR C 0C Jump to L2
800F JMP L2 C3 09 80 Store accumulator value
8012 L1: STA 8600 32 00 86 in 8600)H.
[C] value is moved to
8015 MOV A,C 79 acc.
Store accumulator value
8016 STA 8601 32 01 86 in 8601)H.
Stop.
8019 HLT 76

RESULT
Thus the 8-bit arithmetic operations has been performed using 8085
microprocessor.
EX. No:2 16 -BIT ARITHMETIC OPERATIONS

AIM
To write programs to perform 16-bit arithmetic operations using 8085
microprocessor.

APPARATUS REQUIRED
8085 microprocessor kit
+5V Power supply

ALGORITHM

ADDITION

TO ADD TWO 16-BIT DATA WITH CARRY

1) Load the first data in HL register pair


2) Exchange the content of HL register pair with DE register pair
3) Load the second data in DE register pair
4) Add the content of DE and HL register pair and the result will be in HL
register pair
5) If the result has the carry, increment the carry register by one else store the
content of HL register in two consecutive memory locations
6) Move the content of carry register to accumulator content is stored in next
memory location
7) End of the program

SUBTRACTION

TO SUB TWO 16-BIT DATA WITH CARRY


1) Load the first data in HL register pair
2) Exchange the content of HL register pair with DE register pair
3) Load the second data in DE register pair
4) Subtract the content of two lower order registers and then the higher order
registers
5) Check for borrow, if there is a borrow,increment the content of borrow
register
6) Store the result and borrow in successive memory location
7) End of the program
TO MULTIPLY TWO 16 BIT DATA
1) load the two 16 bit datas in BC and SP register pair.
2) Clear HL and DE register pair.
3) Add HL and SP register pair value .
4) If carry occurs, increment DE register pair value.
5) Otherwise, decrement BC register pair value & check for zero flag.
6) If no zero occurs, go to step 3.
7) If zero occurs, store the HL & DE register pair value in separate memory
locations.
8) Stop.

TO DIVIDE TWO 16 BIT DATA

1) Load the dividend in one register and divisor in another register pair
2) Initialize DE register pair for quotient
3) Check whether division is possible. Compare the two data, if there is no
carry subtraction is performed and remaining value is stored in one
register pair
4) If there is a carry, quotient will be zero and remainder will be dividend
5) For each subtraction increment the content of quotient register pait
6) The quotient and remainder are stored in successive memory locations
7) End of the program

TO ADD TWO 16 BIT DATA

ADDRESS LABEL MNEMONICS OPCODE COMMENTS


8000 MVI C,00 0E 00 Set carry to 00h

8002 LHLD 8500 2A 00 85 Load HL reg.pair


content
8005 XCHG EB Exchange HL with DE
reg.pair
8006 LHLD 8502 2A 02 85 Load HL reg.pair
content
8009 DAD D 19 Add the content of DE
and HL reg.pair
800A JNC L1 D2 0E 80 If carry is occurred
jumps to L1
800D INR C 0C Incremented carry by
one
800E L1 SHLD 8300 22 00 83 Stores the result in 8300
Move c to Acc
8011 MOV A,C 79
Store the carry in 8302
8012 STA 8302 32 02 83 Stop
8015 HLT 76
TO SUBTRACT TWO 16 BIT DATA

ADDRESS LABEL MNEMONICS OPCODE COMMENTS

8000 MVI C,00 0E 00 Sets the carry as 00

8002 LHLD 8500 2A 00 85 Load the content of HL


reg.pair
8005 XCHG EB Exchange the content of
HL with DE reg.pair
8006 LHLD 8502 2A 02 85 Load the content of HL
reg.pair
8009 MOV A,E 7B Move the content from
E to Acc
800A SUB L 95 Subtract the content
from acc to L
800B MOV L,A 6F Move the content from
A to L
800C MOV A,D 7A Move the content from
D to A
800D SBB H 9C Subtract the content
from acc with borrow
800E JNC L1 D2 12 80 If the carry is not
occurred, jumps to L1
8011 INR C 0C Increment the carry by
one
Moves the content from
8012 L1 MOV H,A 67 A to H

Stores the result in 8600


8013 SHLD 8600 22 00 86
Move the content from
C to A
8016 MOV A,C 79
Stores the result in 8602
Stop
8017 STA 8602 22 02 86

801A HLT 76
TO MULTIPLY TWO 16 BIT DATA

ADDRESS LABEL MNEMONICS OPCODE COMMENTS


8000 LXI H,0000H 21 00 00 clear HL reg.pair.
8003 LXI SP,FFFFH 31 FF FF Load SP reg.pair with
Data FFFF )H
8006 LXI B,FFFFH 01 FF FF Load BC reg.pair with
Data FFFF )H
8009 LXI D,0000H 11 00 00 Clear DE register pair
800C L2: DAD SP 39 [HL]=[HL] + [SP]
800D JNC L1 D2 11 80 If no carry occurs, go to
L1
8010 INX D 13 [DE]=[DE] + 1
8011 L1: DCX B 0B [BC]=[BC] - 1
8012 MOV A,C 79 C reg.value is moved to
acc.
8013 ORA B B0 [A]=[A] ^ [B]
8014 JNC L2 C2 0C 80 If no carry occurs, go to
L2
8017 SHLD 8400 22 00 84 Store HL reg. Pair value
in 8400)H
& 8401)H
801A XCHG EB Exchange DE & HL
reg.pair value
801B SHLD 8402 22 02 84 Store HL reg. Pair value
in 8402)H
& 8403)H
801E HLT 76 stop.

TO DIVIDE TWO 16 BIT DATA

ADDRESS LABEL MNEMONICS OPCODE COMMENTS

8000 LXI H,0006H 21 06 00 Load HL reg.pair with


Data 0006H
8003 LXI B,0002H 01 02 00 Load BC reg.pair with
Data 0002)H
8006 LXI D,0000H 11 00 00 Clear DE register pair
8009 L3: MOV A,H 7C Move H reg. Value to
acc.
800A CMP B B8 Compare B reg value
with acc.
800B JC L1 DA 1B 80 If carry occurs, go to L1
If no zero occurs,go to
800E JNZ L2 C2 16 80 L2
Move L reg. Value to
8011 MOV A,L 70 acc.
Compare C reg value
8012 CMP C B9 with acc.
If carry occurs, go to L1
8013 JC L1 DA 1B 80 [HL]=[HL] [BC]
[DE]=[DE] + 1
8016 L2: DSUB B 08 jump to L3
8017 INX D 13 Store HL reg. Pair value
8018 JMP L3 C3 09 80 in 8600)H
801B L1: SHLD 8600 22 00 86 & 8601)H
Exchange DE & HL
reg.pair value
801E XCHG EB Store HL reg. Pair value
in 8602)H
801F SHLD 8602 22 02 86 & 8603)H

8022 HLT 76 stop.

RESULT
Thus the 16-bit arithmetic operations has been performed using 8085
microprocessor.
EX.No. 3 SORTING AND SEARCHING OPERATION USING 8085

AIM
To write an assembly language program to sort an array of data in ascending order
and descending order and also to search the smallest and largest data in an array

APPARATUS REQUIRED
8085 microprocessor kit
+5 v power supply

ALGORITHM

ASCENDING ORDER

1.Get the desired number of data using HL pair.


2.Initialize number of interations and number of computations.
3.Compare the first two values in HL.
4.If carry exists, go to decrement the number of computations.
5.Move the value in A to M and decrement H.
6..Move the value in B to M and decrement H.
7.Perform this operation until the number of data becomes zero.

DESCENDING ORDER

1.Get the number of data using HL resgisster pair.


2.Initialize the number of iterations and computations
3.Perform comparison of two numbers and if carry exists get out of the loop.
4.Perform descending order operation by rearranging the data.
5.Perform this process until the number of data reduced to zero.

SMALLEST NUMBER IN AN ARRAY


1.Get the desired number of data using HL pair.
2.The first loction specifies number of data in array.
3.Compare the accumulator data with memory.
4.If carry exists,decrement the B register.
5.Repeat until it becomes zero.
6. Store the result.

LARGEST NUMBER IN AN ARRAY


1.Get the desired number of data using HL pair.
2.The first loction specifies number of data in array.
3.Compare the accumulator data with memory.
4.If carry does notexists, decrement the B register.
5.Repeat until it becomes zero.
6. Store the result.

Ascending order

ADDRESS LABEL MNEMONICS OPCODE COMMENTS


8000 START MVI C,02 0E,02 Move immediately 02 to
C register
8002 L3: MVI D,02 16,02 Move immediately 02 to
D register
8004 LXI H,8200H 21,00,82 Load immediately
contents of H to location
8200 to H
8007 L2: MOV A,M 7E Move the content of
memory to accumulator.
8008 INX H 23 Increment register
content by 01
8009 MOV B,M 46 Move memory content
to B register
800A CMP B B8 Compare A and B
800B JC L1: DA,12,80 Jump on carry to l1
800E MOV M,A 77 Move memory content
to A register
800F DCX H 2B Decrement register
content by 01
8010 MOV M,B 70 Move memory content
to B register
8011 INX H 23 Increment register
content by 01
8012 L1: DCR D 15 Decrement D register
8013 JNZ L2: C2,07,80 Jump on carry to l2
8016 DCR C 0D Decrement C register
8017 JNZ L3: C2,04,80 Jump on no zero to L3
801A HLT 76 Stop the execution
Descending order

ADDRES LABEL MNEMONICS OPCODE COMMENTS


8000 START MVI C,02 0E,02 Move immediately 02 to C
register
8002 L3: MVI D,02 16,02 Move immediately 02 to D
register
8004 LXI H,8200H 21,00,82 Load immediately contents of H
to location 8200 to H
8007 L2: MOV A,M 7E Move the content of memory to
accumulator.
8008 INX H 23 Increment register content by 01
8009 MOV B,M 46 Move memory content to B
register
800A CMP B B8 Compare A and B
800B JNC L1: D2,12,80 Jump on no carry to L1
800E MOV M,A 77 Move memory content to A
register
800F DCX H 2B Decrement register content by
01
8010 MOV M,B 70 Move memory content to B
register
8011 INX H 23 Increment register content by 01
8012 L1: DCR D 15 Decrement D register
8013 JNZ L2: C2,07,80 Jump on carry to L2
8016 DCR C 0D Decrement C register
8017 JNZ L3: C2,04,80 Jump on no zero to L3
801A HLT 76 Stop the execution

Smallest number in an array

ADDRESS LABEL MNEMONICS OPCODE COMMENTS


8000 START LXI H,8200 21,00,82 Load immediately content
of H register to location
8200h
8003 MOV B,M 46 Move the content of
memory to B register
8004 INX H 23 Increment the HL register
by 01
8005 DCR B 05 Decrement the b register
count
8006 MOV A,M 7E Set or move memory
content to accumulator
8007 L2: INX H 23 Increment the HL register
by 01
8008 CMP M BE Compare elements of
array with current smallest
datum
8009 JC L1 DA,OD, Jump on carry to L1
80
800C MOV A,M 7E If CF=0, then content of
memory is smaller than A.
Hence CF=0 make
memory as smallest by
moving to A register.
800D L1: DCR B 05 Decrement B register by
01
800E JNZ L2 C2,07,80 Jump on no zero to L2
8011 STA 8500 32,00,85 Store the memory data in
memory location in 8500H
8014 HLT 76 Stop the execution.

Largest number in an array

ADDRESS LABEL MNEMONICS OPCODE COMMENTS


8000 START LXI H,8200 21,00,82 Load immediately
content of H register to
location 8200h
8003 MOV B,M 46 Move the content of
memory to B register
8004 INX H 23 Increment the HL
register by 01
8005 DCR B 05 Decrement the b register
count
8006 MOV A,M 7E Set or move memory
content to accumulator
8007 L2: INX H 23 Increment the HL
register by 01
8008 CMP M BE Compare elements of
array with current
smallest datum
8009 JNC L1 DA,OD, Jump on no carry to L1
80
800C MOV A,M 7E If CF=0, then content of
memory is smaller than
A. Hence CF=0 make
memory as smallest by
moving to A register.
800D L1: DCR B 05 Decrement B register by
01
800E JNZ L2 C2,07,80 Jump on no zero to L2
8011 STA 8500H 32,00,85 Store the memory data
in memory location in
8500H
8014 HLT 76 Stop the execution.

RESULT
Thus ascending, descending, searching of smallest and largest of a given number were
performed using 8085 microprocessor kit.
Ex.No.11 PROGRAMMING USING 8086 MICROPROCESSOR

AIM
To write programs to perform arithmetic operations in 8086.

APPARATUS REQUIRED
8086 microprocessor kit
+5V Power Supply

PROCEDURE

ADDITION/SUBTRACTION

1) Clear the accumulator.


2) Move the data from memory location to S1 & D1 registers.
3) Load the 16 bit data to AX & BX registers.
4) Add or subtract the content of BX & AX registers.
5) Check for carry.
6) If there is carry store it in a register.
7) Move the result to the specified memory location.

MULTIPLICATION/DIVISION
1) Move the data from memory location to S1 & D1 registers.
2) Load the 16 bit data to AX & BX registers (Multiplier & Multiplicand, Dividend
& Divisor).
3) Multiply or divide the content of BX & AX registers.
4) Clear for carry.
5) Store the product result in AX register.
6) If there is carry store it in DX register.

ADDRESS LABEL MNEMONICS OPCODE COMMENTS

ASSUME
CS:CODE,
DS:CODE
0000 CODE SEGMENT Initialize code segment
1000 ORG 1000H
1000 MOV AX,0000H B8,0000 Move 0000 to AX
register
1000 MOV CX,0000H B9,0000 Move 0000 to CX reg
1003 MOV SI,1500H B9,1500 Move 1500 to source
index reg
1006 MOV DI,1600H BE,1600 Move 1600 to
destination index reg
1009 MOV AX,[SI] 8B,04 Move [SI] to AX reg

100B INC SI 46 Increment SI reg


100C INC SI 46 Increment SI reg
100D MOV BX,[SI] 8B,1C Move [SI] to BX reg
100F ADD/SUB 03/C3,2B,C Add BX with
AX,BX 3 AX/Subtract BX from
AX reg
1011 JNC L1 73,1011 If no carry,go to L!
1013 INC CX 41 Increment CX reg
1014 MOV [DI],AX 89,05 Move AX to [DI] reg
1016 INC DI 47 Increment DI reg
1017 INC DI 47 Increment DI reg
1018 MOV [DI],CX 89,0D Move AX to [DI] reg
101A INT 03H CC Program termination
interrupt
101B CODE ENDS End of codes
END End of the program
ADDITION/SUBTRACTION

MULTIPLICATION/DIVISION
ADDRESS LABEL MNEMONICS OPCODE COMMENTS

ASSUME
CS:CODE,
DS:CODE
0000 CODE SEGMENT Initialize code segment
2000 ORG 2000H Initialize the starting
address
2000 MOV SI,1500H BE 15 00 Move 1500 to source
index reg
2003 MOVAX,[SI] 8B 04 Move content of SI reg
to Ax reg
2005 INC SI 46 Increment SI reg
2006 INC SI 46 Increment SI reg
2007 MOV BX,[SI] 8B 1C Move content of SI reg
to BX reg
2009 MUL/DIV BX FF E3/F3 Multiply/divide AX reg
by BX reg
200B MOV DI,1600 BF 16 00 Move DI to 1600 reg
200E MOV [DI],AX 89 05 Move the content AX to
DI reg
2010 INC DI 47 Increment DI reg
2011 INC DI 47 Increment DI reg
2012 MOV [DI],DX 89 15 Move the content of DX
reg to DI reg
2014 INT 03H CC Program termination
interrupt
2015 CODE ENDS End of codes
END End of the program

RESULT
Thus the arithmetic operations in 8086 has been performed & executed.
EX.No.12 SORTING AND SEARCHING USING 8086 MICROPROCESSOR

AIM
To write the program to perform sorting and searching operation in 8086

APPARATUS REQUIRED
8086 Microprocessor kit
+5v Power supply

ALGORITHM

TO SORT AN ARRAY OF DATA IN ASCENDING/DESCENDING ORDER

1) Get the number of count n-1 in CL and CH register


2) Get the data in AX and BX register through SI
3) Compare the two data, if carry does not /occurs decrement the count until it
becomes zero
4) Else move the accumulator content to SI, Decrement SI and move the BX content
to SI
5) Repeat the process until all the elements are stored

ADDRESS LABEL MNEMONICS OPCODE COMMENTS

ASSUME
CS:CODE,
DS:CODE
0000 CODE SEGMENT Initialize code segment
2000 ORG 2000H Initialize the starting
address
2000 MOV CL,04 B1 04 Move the data 04 to CL
2002 L3 MOV SI,1500 BE 15 00 Move the content in
1500 to SI
2005 MOV CH,04 BE 04 Move the data 04 to CH
2007 L2 MOV AX,[SI] 8B 04 Move SI data to AX
2009 INC SI 46 Increment SI reg
200A INC SI 46 Increment SI reg
200B MOV BX,[SI] 8B 1C Move content of SI to
BX
200D CMP AX,BX 3B C3 Compare AX with BX
200F JC/JNC L1 73 08 Jump on carry or no
carry to L1
2011 MOV [SI],AX 89 04 Move Ax to SI
2013 DEC SI 4E Decrement SI reg
2014 DEC SI 4E Decrement SI reg
2015 MOV [SI],BX 89 1C Move BX reg to SI reg
2017 INC SI 46 Increment SI reg
2018 INC SI 46 Increment SI reg
2019 L1 DEC CH FE CD Decrement CH reg
2021 JNZ L2 75 EA Jump on no zero to L2
201D DEC CL FE C9 Decrement CL reg
201F JNZ L3 75 E1 Jump on no zero to L3
2021 INT 03 CC Termination of the
program
CODE ENDS End of the code segment
END End of the program

TO SEARCH A SMALLEST/ LARGEST DATA IN AN ARRAY


1) Get the count n-1 in CL register
2) Move the source address to SI and Destination address to DI
3) Load the data in AX by using SI
4) Increment SI and decrement count
5) Move the next pointed by SI to BX register
6) Compare the two data if carry is equal to zero/one
7) Move the content of BX to Ax and increment SI
8) If carry is not zero, increment SI and decrement the count
9) If ZF=0 store the smallest element in address pointed by DI else compare AX and
BX again and repeat the process till smallest element is stored in DI
ADDRESS LABEL MNEMONICS OPCODE COMMENTS

ASSUME
CS:CODE,
DS:CODE
0000 CODE SEGMENT Initialize code segment
2000 ORG 2000H Initialize the starting
address
2000 MOV CL,03 B1 03 Move the data 03 to CL
2002 MOV SI,1500 BE 15 00 Move the content in
1500 to SI
2005 MOV DI,1600 BF 16 00 Move the in 1600 to DI
2008 MOV AX,[SI] 8B 04 Move SI data to AX
200A INC SI 46 Increment SI reg
200B INC SI 46 Increment SI reg
200C DEC CL FE C9 Decrement CL reg
200E L2 MOV BX,[SI] 8B 1C Move content of SI to
BX
2010 CMP AX,BX 3B C3 Compare AX with BX
2012 JC/JNC L1 73 02 Jump on carry or no
carry to L1
2014 MOV AX,BX 8B C3 Move BX to AX
2016 L1 INC SI 46 increment SI reg
2017 INC SI 46 increment SI reg
2018 DEC CL FE C9 Decrement CL reg
201A JNZ L2 75 F2 Jump no zero to L2
201C MOV [DI],AX 89 05 Move AX reg to DI
201E INT 03 CC Termination of the
program
CODE ENDS End of the code segment
END End of the program

RESULT
Thus the searching and sorting operations in 8086 has been performed &
executed.

Ex.No.13

PROGRAMMING USING BIOS AND DOS CALLS-KEYBOARD CONTROL


AIM
To write the program read a data from console

APPARATUS REQUIRED
PC, Macro assembler software

ALGORITHM

READ A DATA FROM CONSOLE

1) Initialize the data segment


2) Declare the message to be displayed in the data segment
3) Write the program within the code segment
4) Move the data segment address to AX and offset address of MSG to BX
5) Call the DOS display service
6) Call the DOS function to read the character from keyboard and echoes it to
display
7) End of the program

ADDRESS LABEL MNEMONICS OPCODE COMMENTS

0000 ASSUME Initialize the segment


CS:CODE,SS:COD registers
E,DS:DATA,ES:C
ODE
DATA SEGMENT Initialize the data
segment
MSG DBINPUT Declare the message
ANY KEY,$
000E DATA ENDS End of the data segment
0000 CODE Initialize the code
SEGMENT segment
1000 ORG 1000 Initialize the starting
address
1000 MOV AX,DATA B8 ---- R Move data to AX
register
1003 MOV DS,AX 8E D8 Move AX to DS register
1005 MOV AH,09H B4 09 Move 09 to AH register
1007 MOV BA 000 0R Move the offset message
DX,OFFSET to DX register
MSG
100A INT 21H CD 21 Create a file in normal
mode
100C MOV AH,01H B4 01 Move 01 to AH register
100E INT 21H CD 21 Create a file in normal
mode
MOV DI,2000H BF 20 00 move 2000 to DI register
MOV [DI],AL 88 05 Move data from AL to
DI address
INT 03H CC Termination of the
program
CODE ENDS End of code segment
END End of the program

RESULT
Thus the keyboard control program using BIOS/DOS calls in 8086 has been
performed & executed.

Ex.No.14 PROGRAMMING USING BIOS AND DOS CALLS


DISPLAY A STRING ON SCREEN USING MACRO &
COPY A STRING USING MACRO
AIM
To write the programs to display and copy string using 8086

APPARATUS REQUIRED
PC, Macro assembler software

ALGORITHM

DISPLAY A STRING ON SCREEN USING MACRO

1) Load the string to be displayed in the data segment


2) Store the program in the code segment
3) Move the data segment address to accumulator and move the DS and Es register
4) To display the string in DOS window move 09 to 0AH register and invoke DOS
service
5) Move the offset address of the Label MSG to DX register
6) Call DOS service to display
7) To terminate the program move 4CH to AH register and 00H to AL register
8) End of the Program

ADDRESS LABEL MNEMONICS OPCODE COMMENTS

0000 ASSUME Initialize the segment


CS:CODE,SS:COD registers
E,DS:DATA,ES:C
ODE
0000 DATA SEGMENT Initialize the data
segment
MSG DBHAI Declare the message
WELCOME,$
000C DATA ENDS End of the data segment
0000 CODE Initialize the code
SEGMENT segment
1000 ORG 1000 Initialize the starting
address
1000 MOV AX,DATA B8 ---- R Move data to AX
register
1003 MOV DS,AX 8E D8 Move AX to DS register
1005 MOV ES,AX B4 C0 Move AX to ES register
1007 MOV AH,09 B4 09 Move 09 to AH register
1009 MOV BA 000 0R Move the offset message
DX,OFFSET to DX register
MSG
100C INT 21H CD 21 Create a file in normal
mode
100E MOV AH,4CH B4 4C Move the termination
command word to AH
register
1010 MOV AL,00H B0 00 Move the data 00 to AL
register
INT 21H CD 21 Create a file in normal
mode
INT 03H CC Termination of the
program
CODE ENDS End of code segment
END End of the program

COPY A STRING USING MACRO

1) Get the string in data segment


2) Define five bytes and initialize the bytes with zero
3) Move the data segment address to accumulator and then move DS and ES register
4) Load the effective address of label TEST to source index and NEWLOC to
destination index
5) Clear the direction flag to set auto increment mode
6) Move the count 05 to CX register
7) Move the string bytes from original location to new location and decrement CX
register for each string byte movement until it becomes zero
8) End of the program

ADDRESS LABEL MNEMONICS OPCODE COMMENTS

0000 ASSUME Initialize the segment


CS:CODE,SS:COD registers
E,DS:DATA,ES:C
ODE
0000 DATA SEGMENT Initialize the data
segment
0040 ORG 0040H Declare the message
0040 TEST DB Declare the string
HELLO
0045 NEWLOC DB 5 05[ 00] Define 5bytes and
DUP(0) initialize the bytes with
zero
004A DATA ENDS End the data segment
0000 CODE Initialize code segment
SEGMENT
1000 ORG 2000H Initialize the starting
address to 2000
1000 MOV AX,DATA B8----R Move the data to AX
register
1003 MOV DS,AX 8E D8 Move the data from AX
to DS register
1005 MOV ES,AX 8E C0 move the data from AX
to ES
1007 LEA SI,TEST 8D 3E 0040 Load the effective
R address of test to SI
100B LEA 8D 3E Load the effective
DI,NEWLOC 0045R address of new loc to DI
100F CLD FC Clear the direction flag
1010 MOV CX,05H B9 00 05 Move the data 05 to CX
1013 REP MOVSB F3/A4 Move the string byte
from original location to
new location
1015 INT 03H CC Termination of the
program
1016 CODE ENDS End of code segment
END End of the program

RESULT

Thus the program for display a message on the screen and copy a string using
BIOS/DOS calls in 8086 has been performed & executed.

Ex.No.15 FILE MANIPULATIONS

AIM
To write an assembly language program to perform File manipulations

APPARATUS REQUIRED
PC, Macro assembler software

ALGORITHM

FILE CREATION
1) Data segment, Extra segment ,code segment registers are initialized
2) Move the offset address of label msg to the DX register
3) Move the values 0000H to CX and 3CH to AH to create a file in normal
mode using INT 21 DOS CALL
4) If carry flag is zero, the file is created and display the message FILE
CREATED
5) If carry flag is set, the file is not created and display the message FILE IS
NOT CREATED
6) End of the program by using DOS CALL

ADDRESS LABEL MNEMONICS OPCODE COMMENTS

ASSUME Initialize the segment


CS:CODE,DS:D registers
ATA,ES:DATA,S
S:CODE
0000 DATA Initialize the data
SEGMENT segment
0000 MSG 1 Declare the message1
DBFILENAME.
ASM,$
000A MSG 2 DB FILE Declare the message 2
CREATED,$
0017 MSG 3 DBFILE Declare the message3
IS NOT
CREATED,$
0028 DATA ENDS End of the data segment
0000 CODE Initialize the code
SEGMENT segment
1000 ORG 1000 Initialize the starting
address
1000 MOV CX,0000H B9 00 00 Move data 0000 to CX
1003 MOV AX,DATA B8--- R Move the data to AX
register
1006 MOV DS,AX 8E D8 Move AX to DS register
1008 MOV ES,AX 8E C0 Move AX to ES register
100A MOV BA 00 00R Move the offset
DX,OFFSET message1 to DX
MSG1
100D MOV AH,3CH B4 3C Move 3ch to AH register
100F INT 21H CD 21 Create a file in normal
mode
1011 JNZ L1 75 09 Jump no zero to L1
1013 MOV AH,09H B4 3C Move 09 to AH register
1015 MOV BA 00 17R Move offset message 3
DX,OFFSET to DX register
MSG3
1018 INT 21H CD 21 Create a file in normal
mode
101A JNZ L2 75 07 Jump no zero to L2
101C L1 MOV AH,09H B4 09 Move 09 to AH register
101E MOV BA 00 1AR Move offset message 2
AX,OFFSET to AX register
MSG2
1021 INT 21H CD 21 Create a file in normal
mode
1023 L2 MOV AH,4CH B4 4C Move 4C to AH register
1025 MOV AL,00 B0 00 Move 00 to AL register
1027 INT 21H CD 21 Create a file in normal
mode
1029 CODE ENDS End of code segment
102A END End of the program
RESULT

Thus the program to perform file manipulations in 8086 has been performed &
executed.

EX.No.16 ARITHMETIC OPERATION USING 8051 MICROCONTROLLER

AIM
To perform arithmetic operations using 8051 microcontroller

APPARATUS REQUIRED
8051 microcontroller Kit, RS-232 cable, power supply, PC

ALGORITHM

ADDITION OF TWO 8-BIT DATA WITH CARRY

1) Initialize count value for storing it in the register


2) Initialize DPTR to an address
3) Store two immediate data in two register
4) Add [A] and R2 register content
5) If carry arises, increment R0 by 1
6) Else move the result to the address in DPTR
7) Move carry from register to address of DPTR through accumulator
8) Long jump to 0003H memory location

SUBTRACTION OF TWO 8-BIT DATA WITH CARRY


1) Initialize DPTR to an address
2) Store two immediate data in two register
3) Subtract [A] and R2 register content
4) If carry arises, increment R0 by 1
5) Else move the result to the address in DPTR
6) Move carry from register to address of DPTR through accumulator
7) Long jump to 0003H memory location

MULTIPLICATION OF TWO 8-BIT DATA WITH CARRY


1) Initialize DPTR to an address
2) Store two immediate data in two register
3) Move R1 register content to accumulator and R2 register content to B register
4) Multiply A and B register content
5) If carry arises, increment R0 by 1
6) Else move the result to the address in DPTR
7) Move carry from register to address of DPTR through accumulator
8) Long jump to 0003H memory location

DIVISION OF TWO 8-BIT DATA WITH CARRY


1) Initialize DPTR to an address
2) Store two immediate data in two register
3) Move R1 register content to accumulator and R2 register content to B register
4) Divide A and B register content
5) Quotient stored in A and remainder stored in B is moved to the specified address
of DPTR
6) Long jump to 0003H memory location

ADDITION
ADDRESS LABEL MNEMONICS OPCODE COMMENTS
80009 CLR C C3 Clear the carry flag
8001 MOV R0,#00 78 00 Move 00 to R0 reg
8003 MOV DPTR,#8300 90 83 00 Move the addr 8300 to
DPTR
8006 MOV R1,#0FF 79 FF Move FF data to R1 reg
8008 MOV A,R1 E9 Move R1 to A reg
8009 MOV R2,#10 7A 10 Move data to R2 reg
800B ADD A,R2 2A Add A with R2
800C JNC L1 50 02 Jump to L1 if no carry
800E INC R0 8 Increment R0 value
800F L1 MOVX @DPTR,A F0 Move A reg content to
the addr
8010 MOV A,R0 B8 Move R0 content to acc
8011 INC DPTR A3 Increment DPTR by
one
8012 MOVX @DPTR,A F0 Move A reg content to
the addr
8013 LJMP 0003 02 00 03 Long jump to the addr
0003

SUBTRACTION
MULTIPLICATION

DIVISION
RESULT
Thus the arithmetic operation in 8051 microcontroller has been performed and
executed.

EX.No.17 CODE CONVERSION USING 8051 MICROCONTROLLER

AIM
To perform code conversions using 8051 microcontroller
APPARATUS REQUIRED
8051 microcontroller Kit, RS-232 cable, power supply, PC

ALGORITHM

BINARY TO HEXADECIMAL CODE CONVERSION

1) Initialize the DPTR to load the data in memory location


2) Transfer the data to A register
3) Clear the carry flag
4) Each time rotate the content in A register through right
5) XOR the data in A register and R0 register
6) Move the data in accumulator to the memory location
7) Long jump to memory location

HEXADECIMAL TO BINARY CODE CONVERSION

1) Initialize the DPTR to load the data in memory location


2) Move the data pointed by DPTR to a register
3) Each time increment the DPTR and rotate the content of accumulator left through
carry
4) If carry is zero, move the data 00H in A register to address pointed by DPTR
5) If carry is not zero, move the data 01H to address pointer by DPTR
6) Decrement the content of R0 register and jump to Loop3 if there is no zero.
RESULT
Thus the code conversion in 8051 microcontroller has been performed and
executed.

Ex.No.18 TIMER AND INTERRUPT IN 8051 MICROCONTROLLER


AIM
To write a program for timer and Interrupt control operation

APPARATUS REQUIRED
8051 Microcontroller kit,RS-232 Cable, Power supply, PC, CRO, Interfacing card

ALGORITHM

TIMER

1) Initialize TMOD register with Timer 0


2) Load the count in TH0 and TL0 of timer 0 and set the run control bit
3) Till the overflow bit is set, compliment data of P1.0
4) If the over flow bit is set, stop timer by clearing run control bit
5) Clear the overflow flag bit
6) Repeat the operation again by loading the count
ADDRESS LABEL MNEMONICS OPCODE COMMENTS
8000 MOV 89,#01 75 89 01 Move 01 to TMOD reg
8003 L2 MOV 8C,#0FF 75 8C FF Move upper count value
FF to TH0 register
8003 MOV 8A,#19 75 8A 19 Move lower count value
19 to TL0 register
8009 CPL 90 B2 90 Complement the data in
port1
800B SETB 8C D2 8C Set the run control bit
800D L1 JNB 8D,L1 30 8B FD If TF0 bit is not set run
to L1
8010 CLR 8D C2 8D Clear the timer over
flow flag bit
8012 CLR 8C C2 8C Clear the run control bit
8014 SJMP L2 80 ED Short jump to L2

INTERRUPT

1) Initialize TMOD register with Timer 0


2) Load the count in TH0 and TL0 of timer 0 and set the run control bit
3) Enable the timer 0 interrupt in IE register.Till the over flow bit is set,compliment data of
P1.0
4) If over flow flag bit is set, Stop timer by clearing run control bit
5) Clear overflow flag bit
6) In the ISR of the timer 0 interrupt write a subroutine that copy the data from the previous
location
7) Return from ISR
ADDRESS LABEL MNEMONICS OPCODE COMMENTS
8000 MOV 89,#01 75 89 01 Move 01 to TMOD reg
8003 L2 MOV 8C,#0FF 75 8C FF Move upper count value
FF to TH0 register
8006 MOV 8A,#19 75 8A 19 Move lower count value
19 to TL0 register
8009 MOV 0A8,#82 75 A8 82 Move the control word
82 to the IE register
800C CPL 90 B2 90 Complement the data in
port1
800E SETB 8C D2 8C Set the run control bit
8010 L1 JNB 8D,L1 30 8B FD If TF0 bit is not set run
to L1
8013 CLR 8D C2 8D Clear the timer over
flow flag bit
8015 CLR 8C C2 8C Clear the run control bit
8017 SJMP L2 80 ED Short jump to L2
FFF0 LJMP 8050 02 80 50 Long jump to 8050
8050 MOV 90 00 82 Move the data in 8200 to
DPTR,#8200 DPTR
8053 MOVX E0 Move the content in
A,@DPTR DPTR address to acc
8054 INC DPTR A3 Increment DPTR
address
8055 MOVX F0 Move Acc to DPTR
@DPTR,A address
8056 RETI 32 Return from the interrupt

RESULT
Thus the timer and interrupt operation in 8051 microcontroller has been
performed and executed.

You might also like