0% found this document useful (0 votes)
8 views42 pages

DOC-20240123-WA0007.

The document outlines a Computer Organization Lab practical for first-year students, focusing on assembly language programming with the 8085 microprocessor. It includes objectives, outcomes, and a comprehensive list of exercises covering arithmetic operations, sorting, searching, code conversion, and applications. Each exercise is accompanied by aims, algorithms, and example programs with test data and results demonstrating successful execution.

Uploaded by

hari623406
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views42 pages

DOC-20240123-WA0007.

The document outlines a Computer Organization Lab practical for first-year students, focusing on assembly language programming with the 8085 microprocessor. It includes objectives, outcomes, and a comprehensive list of exercises covering arithmetic operations, sorting, searching, code conversion, and applications. Each exercise is accompanied by aims, algorithms, and example programs with test data and results demonstrating successful execution.

Uploaded by

hari623406
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 42

PRACTICAL - II COMPUTER ORGANIZATION LAB

I YEAR / II SEM

OBJECTIVES:

 To understand the programming features and operations of assembly language programs using 8085
microprocessor kit or Simulator

OUTCOMES:

 Implement the arithmetic operations in assembly language programming


 Understand the programming logic of 8085 in various aspects

LIST OF EXERCISES:

I : Addition and Subtraction

1. 8 - bit addition
2. 16 - bit addition
3. 8 - bit subtraction
4. BCD subtraction

II : Multiplication and Division

l . 8 - bit multiplication
2. BCD multiplication
3. 8 - bit division

III: Sorting and Searching

1. Searching for an element in an array.


2. Sorting in ascending order.
3. Finding largest and smallest elements from an array
4. Reversing array elements
5. Block move
6. Sorting in descending order

IV: Code Conversion

l. BCD to Hex and Hex to BCD


2. Binary to ASCII and ASCII to binary
3. ASCII to BCD and BCD to ASCII

V: Applications

1. Square of a single byte Hex number


2. Square of a two digit BCD number
3. Square root of a single byte Hex number
4. Square root of a two digit BCD number

134
I: ADDITION AND SUBTRACTION

1. 8-BIT ADDITION
AIM:

To write an Assembly Language Program to add two 8-bit numbers.


ALGORITHM:
STEP 1: Start.
STEP 2: Load the first number into the accumulator.
STEP 3: Move the content of accumulator to register B.
STEP 4: Load the second number into the accumulator.
STEP 5: Add the numbers in A and B.
STEP 6: Store the accumulator result in a memory location.
STEP 7: End.
PROGRAM:

ADDRESS OPCODE MNEMONICS COMMENTS


4100 3A LDA 4051 H Load the first number into the accumulator
4101 51
4102 40
4103 47 MOV B,A Move the content of accumulator to register B
4104 3A LDA 4052 H Load the second number into the accumulator
4105 52
4106 40
4107 80 ADD B Add the content of B with the content of accumulator
4108 32 STA 4053 H Store the accumulator result in a memory location
4109 53
410A 40
410B 76 HLT End of program

TEST DATA:
INPUT:
4051:09 H (Augend)
4052:04 H (Addend)
OUTPUT:

4053:0D H
RESULT:

Thus, the assembly language program to add two 8-bit numbers has been executed
successfully.

16-BIT ADDITION

135
AIM:

To write an Assembly Language Program to add two 16 bit hexadecimal numbers and store
the sum in 16 bits.
ALGORITHM:

STEP 1: Start.
STEP 2: Load the first 16-bit number from memory to H-L register pair.
STEP 3: Exchange the contents of H-L register pair with D-E register pair.
STEP 4: Load the second 16-bit number from memory to H-L register pair.
STEP 5: Add the two 16-bit numbers using DAD D instruction.
STEP 6: Store the 16-bit result in two consecutive memory locations.
STEP 7 : End.

PROGRAM:

ADDRESS OPCODE MNEMONICS COMMENTS

Load the H-L register pair with the first 16-bit number from
4000 2A LHLD 4050 H
memory

4001 50
4002 40
Exchange the contents of H-L register pair with D-E register
4003 EB XCHG
pair

Load the H-L register with the second 16-bit number from
4004 2A LHLD 4051 H
memory

4005 51
4006 40

4007 19 DAD D Add the contents of H-L and D-E register pairs

4008 22 SHLD 4052 H Store the 16-bit result in H-L register pair in the memory

4009 52
400A 40
400B 76 HLT End of program

TEST DATA:
136
INPUT:

4050:34
4051:12
4052: CD
4053: AB
OUTPUT:

4054:01
4055: BE

RESULT:

Thus, the assembly language program to perform 16-bit addition has been executed

successfully.

137
3. 8-BIT SUBTRACTION
AIM:

To write an Assembly Language Program to subtract two 8-bit hexadecimal numbers and
store the result in memory.
ALGORITHM:
STEP 1: Start.
STEP 2: Load the accumulator with first number in memory address 4051.
STEP 3: Move the content of accumulator to B register.
STEP 4: Load the accumulator with second number in memory address 4052.
STEP 5: Subtract the first number from the second number.
STEP 6: Store the difference in the memory.
STEP 7: End.
PROGRAM:

ADDRESS OPCODE MNEMONICS COMMENTS


4100 3A LDA 4051 Load the first number into the accumulator
4101 51
4102 40
4103 47 MOV B, A Move the content of accumulator to register B
4104 3A LDA 4052 Load the second number into the accumulator
4105 52
4106 40
4107 90 SUB B Subtract the first number from the second number
4108 32 STA 4053 Store the difference in memory
4109 53
410A 40
410B 76 HLT End of program
TEST DATA:
INPUT:
4051:04 (Subtrahend)
4052:09 (Minuend)
OUTPUT:
4053:05
RESULT:

Thus, the assembly language program to subtract two 8-bit numbers has been executed

successfully.

138
4. BCD SUBTRACTION
AIM:

To write an Assembly Language Program to subtract two BCD numbers.

ALGORITHM:

STEP 1 : Start.
STEP 2 : Load the minuend value in memory address 4050 to accumulator.
STEP 3 : Move the value of A to B.
STEP 4 : Load the subtrahend value in memory address 4051 to accumulator.
STEP 5 : Move the value of A to C.
STEP 6 : Move immediately the value 99 to A.
STEP 7 : Subtract the value of C from A.
STEP 8 : Increment the A register by one.
STEP 9 : Add B with A value.
STEP 10: Using DAA, convert the number in accumulator to decimal (BCD).
STEP 11: Store the result in memory address 4052.
STEP 12: End.

PROGRAM

ADDRESS OPCODE MNEMONICS COMMENTS


4100 3A LDA 4050 H Take the minuend in accumulator
4101 50
4102 40
4103 47 MOV B,A Transfer the minuend to B register
4104 3A LDA 4051 H Take the subtrahend in accumulator from memory
4105 51
4106 40
4107 4F MOV C,A Transfer the subtrahend to C register
4108 3E MVI A,99H Load 99 in accumulator
4109 99
410A 91 SUB C Find the 9’s complement of the subtrahend
Increment the accumulator content by one to find the
410B 3C INR A
10’s complement of the subtrahend
Add the minuend with the 10’s complement of the
410C 80 ADD B
subtrahend
410D 27 DAA Convert the result to decimal
410E 32 STA 4052 H Store the result in memory
410F 52
4110 40
4111 76 HLT End of program

139
TEST DATA:
INPUT:

4050:85
4051:39

OUTPUT:

4052:46

RESULT:

Thus, the assembly language program to perform the BCD subtraction has been

executed successfully.

140
II: MULTIPLICATION AND DIVISION

1. 8-BIT MULTIPLICATION
AIM:

To write an Assembly Language Program to multiply two 8 bit hexadecimal numbers.

ALGORITHM:

STEP 1 : Start.
STEP 2 : Load the accumulator with value in memory address 4050.
STEP 3 : Move the value of A to B register.
STEP 4 : Load the accumulator with value in memory address 4051.
STEP 5 : Move the value of A to C register.
STEP 6 : Initialize accumulator to zero.
STEP 7 : Clear the D register for storing the carry.
STEP 8 : Add the content of C with A.
STEP 9 : If the value in accumulator exceeds FFH, increment D register by one.
STEP 10 : Decrement the B register by one.
STEP 11 : If the value in B register is not equal to zero, then go to STEP 8.
STEP 12 : If the value in B register becomes zero, store the lower byte of the product in
memory address 4052.
STEP 13 : Store the higher byte of the product in memory address 4053.
STEP 14 : End.

PROGRAM:

ADDRESS OPCODE LABEL MNEMONICS COMMENTS


4100 3A LDA 4050 Take the multiplier to accumulator
4101 50
4102 40
4103 47 MOV B,A Transfer the multiplier to B register

4104 3A LDA 4051 Take the multiplicand to accumulator


4105 51
4106 40
4107 4F MOV C,A Transfer the multiplicand to C register

4108 AF XRA A Clear the accumulator


4109 57 MOV D,A Clear D register to store the carry
410A 81 L1 ADD C Add the contents of A and C registers
410B D2,0F,40 JNC L2 If there is no carry, then go to the location L2
410E 14 INR D Else, increment D register

410F 05 L2 DCR B Decrement the C register by one

141
4110 C2 JNZ L1 If the value in B register is not equal to zero, then
jump to the location named L1
4111 0A
4112 41
4113 32 STA 4052 Store the product in memory
4114 52
4115 40
4116 7A MOV A,D Transfer the higher byte to accumulator
4117 32 STA 4053
4118 53
4119 40
4120 76 HLT End of program

TEST DATA:

INPUT:

4050:3 (Multiplier)
4051:10 (Multiplicand)

OUTPUT:

4052:30

RESULT:

Thus, the assembly language program to multiply two 8-bit numbers has been executed
successfully.

142
2. BCD MULTIPLICATION

AIM:

To write an Assembly Language Program to multiply two BCD numbers.

ALGORITHM:

STEP 1 : Start.
STEP 2 : Take the multiplicand in accumulator from memory.
STEP 3 : Transfer the multiplicand to B register.
STEP 4 : Take the multiplier in accumulator from memory.
STEP 5 : Transfer it to C register.
STEP 6 : Clear the accumulator
STEP 7 : Add the content of B register with that of the accumulator.
STEP 8 : Use DAA to convert the number in accumulator to decimal and save it in D.
STEP 9 : Decrement the decimal count in C register by one.
STEP 10 : If C is not zero, go to STEP 7.
STEP 11 : Store the BCD product in memory.
STEP 12 : End.

PROGRAM:

ADDRESS OPCODE LABEL MNEMONICS COMMENTS

4100 3A LDA 4050 Get the multiplicand from memory

4102 50
4103 40
4103 47 MOV B,A Transfer the multiplicand to B register

4104 3A LDA 4051 Get the multiplier from memory

4105 51
4106 40
4107 4F MOV C,A Transfer the multiplier to C register

4108 AF XRA A Clear the accumulator, carry and auxiliary flags

4109 80 L1 ADD B Add the contents of A and B registers

Convert the Hex number in accumulator to


410A 27 DAA
decimal
410B 57 MOV D,A Save the content of accumulator in D register

410C 79 MOV A,C Transfer the multiplier into A register


410D C6 ADI 99 Add 99 to the multiplier
410E 99

143
410F 27 DAA Convert it into decimal

4110 4F MOV C,A Save it in C register


Transfer the saved value in D register to
4111 7A MOV A,D
accumulator
4112 C2 JNZ L1 If C is not zero, continue in L1
4113 09
4114 41
4115 32 STA 4052 Store the product in memory
4116 52

4117 40
4118 76 HLT End of program

TEST DATA:

INPUT:

4050: 08
4051: 12

OUTPUT:

4052: 96

RESULT:

Thus, the assembly language program to perform BCD multiplication has been executed
successfully.

144
3. 8-BIT DIVISION
AIM:

To write an Assembly Language Program to divide one 8 bit number by another 8 bit
number.
ALGORITHM:

STEP 1 : Start.
STEP 2 : Load the accumulator with value in memory address 4050.
STEP 3 : Move the value of A to B register.
STEP 4 : Load the accumulator with value in memory address 4051.
STEP 5 : Move FFH to C register.
STEP 6 : Increment the C register by one.
STEP 7 : Subtract the B value from A.
STEP 8 : Check for carry. If there is no carry, then go to step 6.
STEP 9 : Add the content of B with the accumulator.
STEP 10 : Store the remainder in memory location 4053.
STEP 11 : Move the value of C to A.
STEP 12 : Store the quotient in memory address 4052.
STEP 13 : End.

PROGRAM:

ADDRESS OPCODE LABEL MNEMONICS COMMENTS

4100 3A LDA 4050 Take the divisor to accumulator

4101 50
4102 40
4103 47 MOV B, A Transfer the divisor to B register

4104 3A LDA 4051 Take the dividend to accumulator

4105 51
4106 40
4107 0E MVI C, FF Initialize C register to -1

4108 FF
4109 0C L1 INR C Increment C register content by one

410A 90 SUB B Subtract the divisor from the dividend

If the dividend is greater than the divisor


410B D2 JNC L1 then go to the location named L1

145
410C 09
410D 41
Add the contents of A and B to get the
410E 80 ADD B remainder

410F 32 STA 4053 Store the remainder in memory

4110 53
4111 40
Transfer the quotient in C register to
4112 79 MOV A,C accumulator

4113 32 STA 4052 Store the quotient in memory

4114 52
4115 40
4116 76 HLT End of program

TEST DATA:

INPUT:

4050: 03 (Divisor)
4051: 0F (Dividend)

OUTPUT:

4052: 05 (Quotient)
4053: 00 (Remainder)

RESULT:

Thus, the assembly language program to perform 8-bit division has been executed

successfully.

146
III: SORTING AND SEARCHING

1. SEARCHING FOR AN ELEMENT IN AN ARRAY

AIM:

To write an Assembly Language Program to search the given element from an array..

ALGORITHM:

STEP 1 : Start.
STEP 2 : Move 00 to D register.
STEP 3 : Load the accumulator with value in memory address 8000.
STEP 4 : Move the content of M to A.
STEP 5 : Increment the H register by one.
STEP 6 : Move the content of M to C.
STEP 7 : Load the accumulator with value in memory address 9000.
STEP 8 : Compare M with A.
STEP 9 : If the element is found, go for storing the element and the address of the
Memory where it is stored
STEP 10: Increment the H register by one.
STEP 11: Decrement the C register by one.
STEP 12: If the count is not zero, then go to STEP 8.
STEP 13: Load 01 in D register.
STEP 14: Move the content of D to A.
STEP 15: Store the element in memory.
STEP 16: End.
PROGRAM:

ADDRESS OPCODE LABEL MNEMONICS COMMENTS


4000 21, 50,40 LXI H, 4050 Initialize the memory which stores 4 numbers
4003 0E MVI C, 04 H Load 04 in C register
4004 04
Take the first number from memory into the
4005 7E L2 MOV A, M accumulator
4006 FE CPI EE Compare it with the element to be searched
4007 EE
If the element is found, then go for storing the
CA JZ L1 element and the address of the memory where
4008 it is stored
4009 08
400A 41
400B 23 INX H Increment the address
400C 0D DCR C Decrement the count by one
400D C2 JNZ L2 If the count is not zero, continue in L2
400E 05

147
400F 40
Store FF in memory to indicate the search is
4100 3E MVI A, FF not a success
4101 FF
4102 32 STA 4060
4103 60
4104 40
4105 C3 JMP EXIT
4106 14
4107 41
4108 32 L1 STA 4060 Store the element in memory
4109 60
4110 40
Store the address of the memory where the
4111 22 SHLD 4061
element is present
4112 61
4113 40
4114 76 EXIT HLT End of program

TEST DATA:

INPUT:

4050: 09
4051: 05
4052: EE
4053: 32

OUTPUT:
4060: EE (DATA FOUND)
4060: FF (DATA NOT FOUND)

RESULT:

Thus, the assembly language program to search the given element from an array has
been executed successfully.

148
2. SORTING IN ASCENDING ORDER
AIM:

To write an Assembly Language Program to sort n elements of an array in ascending


order.

ALGORITHM:

STEP 1 : Start.
STEP 2 : Load size of list in C register and set D register.
STEP 3 : Copy the count in D register.
STEP 4 : Initialize H-L register pair with the memory address 4050.
STEP 5 : Move first data from M to A.
STEP 6 : Increment memory address in H-L.
STEP 7 : Move the second data from M to B register.
STEP 8 : Compare the data in A register with the data in B register
STEP 9 : If carry flag is set, Jump to L1 loop
STEP 10: Else, ‘swap’ the data stored in memory
STEP 11: Decrement C in register D by 1
STEP 12: If count in D register is not zero, jump L2.
STEP 13: Decrement the count in C register by one.
STEP 14: If count in C register is not zero, jump L3.
STEP 13: End.

PROGRAM:

ADDRESS OPCODE LABEL MNEMONICS COMMENTS


4000 16,09 MVI C, 00 Load C register with required count
4002 51 L3 MOV D, C Copy the count in D register
Initialize the register pair with the starting
address of the memory which stores in
4003 21,50,40 LXI H, 4050 numbers
4006 7E L2 MOV A, M Move the first number to accumulator
4007 23 INX H Increment memory to access list
4008 46 MOV B, M Move the second number to a B register
4009 B8 CMP B Compare the data in A and B registers
If data in A is smaller, then leave the smaller
number in its position and continue further
400A DA,11,40 JC L1 comparisons
400D 77 MOV M, A Move the content of A to M.
400E 2B DCX H Decrement the H-L register pair
400F 70 MOV M, B Move the content of B to M
4010 23 INX H Increment the H-L register pair
4011 15 L1 DCR D If comparisons are not over continue
4012 C2,06,40 JNZ L2 Jump to L2 if C>0
Decrement C register by one to pick the
4013 0D DCR C largest from the remaining for next iteration
Data and continue till C register is equal to
4014 C2,02,40 JNZ L3 zero, be in L3
4022 76 HLT End of program

149
TEST DATA:

INPUT:

4050: 05
4051: 03
4052: 07
4053: 09
4054: 04
4055: 01
4056:06
4057:08
4058:0A
4059:02

OUTPUT:

4050: 01
4051: 02
4052: 03
4053: 04
4054: 05
4055: 06
4056:07
4057:08
4058:09
4059:0A

RESULT:

Thus, the assembly language program to sort the array elements in ascending order
has been executed successfully.

150
3. FINDING LARGEST ELEMENTS FROM AN ARRAY

AIM:
To write an Assembly Language Program to find the largest element of an array.
ALGORITHM:
STEP 1 : Start
STEP 2 : Initialize H-L register pair with memory address 4050
STEP 3 : Load C register with required count
STEP 4 : Move the size of the array from M to A register
STEP 5 : Increment the memory address in H-L register pair
STEP 6 : Move the data from memory to B register
STEP 7 : Compare the data
STEP 8 : If data in A is smaller then leave the smaller number in its position and jump to L1
STEP 9 : Move the content from memory to accumulator
STEP 10 : Decrement the content of H-L
STEP 11 : Move the data from B register to memory
STEP 12 : Decrement the C register by 1
STEP 13 : Jump to L2
STEP 14 : End.

PROGRAM:

ADDRESS OPCODE LABEL MNEMONICS COMMENTS


Initialize H-L register pair with
4000 21,50,40 LXI H, 4050
memory address 4050
4003 0E,09 MVI C, 09 Load C register with required count
Move the size of the array from M to A
4005 7E L2 MOV A, M
register
Increment the memory address in H-L
4006 21 INX H
register pair
Move the first data from memory to B
4007 46 MOV B, M
register
4008 B8 CMP B Compare the data
If data in A is smaller then leave the
4009 DA,10,40 JC L1 smaller number in its position and jump
to L1, Else, ‘Swap’ the data
Move the content from memory to
400C 77 MOV M, A
accumulator
400D 2B DCX H Decrement the content of H-L
400E 70 MOV M, B Move the data from B register to M
400F 23 INX H Restore memory address
4010 0D L1 DCR C Decrement the C register by 1
4011 C3,05,40 JMP L2 Jump to L2
4014 76 HLT End of program

151
TEST DATA:

INPUT:
4050: 2A
4051: FF
4052:23
4053:21
4054:03
4055: 18
4056:01
4057:08
4058:04
4059:02

OUTPUT:
4050: 2A
4051: 01
4052:02
4053:03
4054:04
4055: 18
4056:21
4057:23
4058:80
4059: FF

RESULT:
Thus, the assembly language program to find the largest element of an array
has been executed successfully.

152
4. REVERSING ARRAY ELEMENTS
AIM:

To write an Assembly Language Program to reverse the given array elements.

ALGORIT

STEP 1 : Start
STEP 2 : Initialize the H-L register pair with memory address 4050.
STEP 3 : Initialize the D-E register pair with memory address 4054.
STEP 4 : Load C register with the number of exchanges required which is equal to N/2.
STEP 5 : Get the first element form the memory by H-L register pair to B register.
STEP 6 : Get the last element from the memory by D-E register pair to A register.
STEP 7 : Store the content of A to memory pointed by H-L register pair.
STEP 8 : Transfer the content B to A and then to memory pointed by D-E register pair.
STEP 9 : Increment the memory address in H-L register pair.
STEP 10: Decrement the memory address in D-E register pair.
STEP 11: Decrement the count in C register by 1
STEP 12: If the count is not zero, then continue exchanging.
STEP 13: End.

PROGRAM:

ADDRESS OP CODE LABEL MNEMONIC COMMENTS


Starting address of an array in H-L
4000 21,50,40 LXI H, 4050
register pair
Last address of an array in D-E register
4003 11,54,40 LXI D, 4054
pair
4006 0E MVI C,02 Number of exchanges required is 2
Get the number from the memory pointed
4008 46 LI MOV B,M
by HL to B
Get the number in the memory pointed by
4009 1A LDAX D
DE to A
400A 77 MOV M,A Move an element from A to Memory
400B 78 MOV A,B Move an element from B to A
400C 12 STAX D
Increment memory address in H-L register
400D 23 INX H
pair
Decrement memory address in D-E
400E 15 DCR D
register pair
400F 0D DCR C Decrement the count by 1
4010 C2,08,40 JNZ L1 If the count is not zero, then continue in L1
4013 76 HLT End of program

153
TEST DATA:
INPUT:

4050: 08
4051: 04
4052: 0A
4053: 25
4054: 98

OUTPUT:

4050: 98
4051: 25
4052: 0A
4053: 04
4054: 08

RESULT:

Thus, the assembly language program to reverse the given array an elements has
been executed successfully.

154
5. BLOCK MOVE
AIM:

To write an Assembly Language Program using block move

ALGORITHM:
STEP 1 : Start.
STEP 2 : Initialize H-L register pair with the starting address of the memory which
contain an array of N numbers.
STEP 3 : Initialize D-E register pair with the memory to which the element are going
to be transferred.
STEP 4 : Load C register with the number of elements in the given array.
STEP 5 : Get the element from the memory pointed by H-L register pair.
STEP 6 : Store the element in the memory pointed by D-E register pair.
STEP 7 : Increment the memory address in H-L register pair to get the next element
from the source block.
STEP 8 : Increment the memory address in D-E register pair to store the next element
in the destination block.
STEP 9 : Decrement the count in C register by 1.
STEP 10: If count is not zero, then loop move to step 5.
STEP 11: End.

PROGRAM

ADDRESS OPCODE LABEL MNEMONIC COMMENTS


Initialize the source block of memory with
4000 21,50,40 LXI H, 4050
H-L register pair
Initialize the source block of memory with
4003 11,00,41 LXI D, 4100
D-E register pair
4006 0E,05 MVI C, 05 Five element to be moved in C register
4008 7E L1 MOV A,M Get a data from the source block
4009 12 STAX D Store that data in the destination block
400A 23 INX H Increment the memory address in H-L
400B 13 INX D Increment the memory address in D-E
400C OD DCR C Decrement the count in C register
400D C2,08,40 JNZ L1 If the count is not zero, continue in L1
4010 76 HLT End of program

155
TEST DATA:

INPUT:

4050: 10
4051: 20
4052:30
4053:40
4054:50

OUTPUT:

4100: 10
4101: 20
4102:30
4103:40
4104:50

RESULT:

Thus, the assembly language program to Block Move has been executed successfully.

156
6. SORTING IN DESCENDING ORDER

AIM:

To write an Assembly Language Program to sort n elements of an array in descending


order.

ALGORITHM:

STEP 1 : Start.
STEP 2 : Load size of list in C register and set D register.
STEP 3 : Copy the count in D register.
STEP 4 : Initialize H-L register pair with the memory address 4050.
STEP 5 : Move first data from M to A.
STEP 6 : Increment memory address in H-L.
STEP 7 : Move the second data from M to B register.
STEP 8 : Compare the data in A register with the data in B register
STEP 9 : If carry flag is not set, Jump to L1 loop
STEP 10 : Else, ‘swap’ the data stored in memory
STEP 11 : Decrement C in register D by 1
STEP 12 : If count in D register is not zero, jump L2.
STEP 13 : Decrement the count in C register by one.
STEP 14 : If count in C register is not zero, jump L3.
STEP 13 : End.

PROGRAM:

ADDRESS OPCODE LABEL MNEMONICS COMMENTS


4000 16,09 MVI C, 00 Load C register with required count
4002 51 L3 MOV D, C Copy the count in D register
Initialize the register pair with the starting
4003 21,50,40 LXI H, 4050 address of the memory which stores in
numbers
Move the first number from memory to
4006 7E L2 MOV A, M
accumulator
4007 23 INX H Increment memory to access list
4008 46 MOV B, M Move the second number to a B register
4009 B8 CMP B Compare the data in A and B registers
400A D2,11,40 JNC L1 If carry flag is not set, jump to L1 loop
400D 77 MOV M, A Move the content of A to M.
400E 2B DCX H Decrement the H-L register pair
400F 70 MOV M, B Move the content of B to M
4010 23 INX H Increment the H-L register pair
4011 15 L1 DCR D If comparisons are not over continue
4012 C2,06,40 JNZ L2 Jump to L2 if C>0
Decrement C register by one to pick the
4013 0D DCR C
largest from the remaining for next iteration
Data and continue till C register is equal to
4014 C2,02,40 JNZ L3
zero, be in L3
4022 76 HLT End of program

157
TEST DATA:

INPUT:

4050: 05
4051: 03
4052: 07
4053: 09
4054: 04
4055: 01
4056:06
4057:08
4058:0A
4059:02

OUTPUT:
4050: 0A
4051: 09
4052: 08
4053: 07
4054: 06
4055: 05
4056:04
4057:03
4058:02
4059:01

RESULT:
Thus, the assembly language program to sort the array elements in descending order
has been executed successfully.

158
IV: CODE CONVERSION

1. (A) BCD TO HEX


AIM:

To write an Assembly Language Program to convert BCD to HEX.

ALGORITHM:

STEP 1 : Start
STEP 2 : Load the BCD number in B register
STEP 3 : Copy it in accumulator
STEP 4 : Mask the upper nibble and store the lower nibble in C register
STEP 5 : Get the number in B register into the accumulator
STEP 6 : Mask the lower nibble and rotate the byte four times to the right to get
higher digit.
STEP 7 : Move it to C register
STEP 8 : Multiply the Tens digit in D by 10 or 0A
STEP 9 : Add the units digit to the result
STEP 10: Store the HEX result in memory
STEP 11: End

PROGRAM:

ADDRESS OPCODE LABEL MNEMONICS COMMENTS


4000 3A, 50,40 LDA 4050 Load the BCD number in B register
4003 47 MOV B,A Copy it in accumulator
4004 E6,0F ANI 0F Mask the upper nibble and get the lower
nibble
4006 4F MOV C,A Store the lower nibble in C register
4007 78 MOV A,B Take the number in B into accumulator
4008 E6,F0 ANI F0 Mask the lower nibble
400A 0F RRC Rotate the byte four times to get the
higher digit
400B 0F RRC
400C 0F RRC
400D 0F RRC
400E 57 MOV D,A Put the higher digit in D register
400F AF XRA A Clear the accumulator
4010 1E MVI E,0A Load E register with 0A or 10
4012 87 L1 ADD D Multiply the contents of D and E
registers
4013 1D DCR E
4014 C2,12,40 JNZ L1
4015 81 ADD C Add the lower nibble to the content of the
accumulator
4016 32 STA 4051 Store the result in memory
4017 76 HLT End of program

159
TEST DATA:

INPUT:

4050: 98

OUTPUT:

4051: 62

RESULT:
Thus, the assembly language program to convert BCD to HEX has been
executed successfully.

160
1. (B) HEX TO BCD
AIM:

To write an Assembly Language Program to convert Hex to BCD.

ALGORITHM:

STEP 1: Start
STEP 2: Initialize memory to store the BCD result.
STEP 3: Load the Hex number in accumulator
STEP 4: Load B register
STEP 5: Call division subroutine to divide the remainder b 10 or 0A
STEP 6: Get the final remainder
STEP 7: End

PROGRAM:

ADDRESS OPCODE LABEL MNEMONICS COMMENTS


4000 3A
4001 50
Load the Hex number in accumulator
4002 40 LDA 4050 H
4003 21
4004 51 LXI H, 4051H
Initialize memory to store BCD result
4005 40
4006 06 MVI B, 64 H Load 64 H (or 100 10) in B register
Call DIVN subroutine to divide the given
4008 CD CALL DIVN number.
4009 06 MVI B, 0AH Load 0AH in B register
CALL DIVN Call DIVN subroutine to divide the given
400B CD number by 0AH
400C 77 MOV M,A Store the final remainder in memory
400D 76 HLT End of Program
DIVN
SUBROUTINE
400E 36,FF MVI M,FF H Store FF H in memory
INR M Increment the content of memory by one to
4010 34 L1 clear the memory
4011 90 SUB B (A)  (A)/(B)
4012 D2 JNC L1 If the result is positive continue in LOOP
4013 10
4014 40
ADD B Else, get the remainder by adding the contents
4015 80 of A and B
4016 23 INX H Increment the memory address
4017 C9 RET Return to the main program

161
TEST DATA:

INPUT:

4050: FEH

OUTPUT:

4051: 02
4052: 05
4053: 04

RESULT:
Thus, the assembly language program to convert HEX to BCD has been
executed successfully.

162
2. (A) BINARY TO ASCII CONVERSION
AIM:

To write an Assembly Language Program to convert from Binary to ASCII.

ALGORITHM

STEP 1 : Start
STEP 2 : Load the binary number in accumulator.
STEP 3: If the given number is from 0 to 9 add 30H to accumulator and go to
step 5.
STEP 4: If the given number is from 0AH to 0FH add 07H in addition to 30H
STEP 5: Store the ASCII result in memory.
STEP 6: End

PROGRAM:

ADDRESS OPCODE LABEL MNEMONICS COMMENTS


4000 3A
4001 50 Take the binary number in accumulator
4002 40 LDA 4050
4003 FE
4004 0A CPI 0AH Compare the given number with 0AH
4005 DA JC L1 If the number is less than 9 no need to add 7.
4006 09
4007 40
4008 C6 ADI 07 H Else add 7 to the accumulator
4009 C6 L1 ADI 30H Add 30H to accumulator
400A 32 STA 4051H Store the ASCII result in memory
400B 51
400C 40
400D 76 HLT End of program

TEST DATA:

INPUT:

4050:0BH

OUTPUT:

4051: 42H

RESULT:

Thus, the assembly language program to convert from Binary to ASCII has been
executed successfully.

2. (B) ASCII TO BINARY CONVERSION


AIM:
163
To write an Assembly LanguagePprogram to convert ASCII to Binary.

ALGORITHM:

STEP 1 : Start.
STEP 2: Take the ASCII number in accumulator.
STEP 3: Subtract NUMBER from the accumulator.
STEP 4: If the result is from 0 to 9 go to step 6.
STEP 5: if the result is greater than 9, subtract 7 from accumulator.
STEP 6: Store the BINARY result in memory
STEP 7: End.

PROGRAM:

ADDRESS OPCODE LABEL MNEMONICS COMMENTS


4000 3A,50,40 LDA 4050 Take the ASCII number in accumulator
4003 D6, 30 SUI 30H Subtract the number from the accumulator.
4005 FE, 0A CPI 0A H Compare result in accumulator with 0A H
If the result is less than 0A H no need to
4007 DA, 0C, 40 JC L1 subtract.
400A D6, 07 SUI 07 H Else subtract
400C 32, 07, 40 L1 STA 4051H Store the Binary result in memory
400F 76 HLT End of program

TEST DATA:

INPUT:

4050: 42H

OUTPUT:

4051: 0BH

RESULT:
Thus, the assembly language program to convert from ASCII to Binary has

been executed successfully.

164
3. (A) ASCII TO BCD CONVERSION
AIM:

To write an Assembly Language Program to convert ASCII to BCD.

ALGORITHM:

STEP 1 : Start.
STEP 2: Take the ASCII number in accumulator.
STEP 3: Subtract NUMBER from the accumulator.
STEP 4: Store the BCD result in memory
STEP 5: End.

PROGRAM:
ADDRESS OPCODE MNEMONICS COMMENTS
4000 3A,50,40 LDA 4050H Take the ASCII number in accumulator
Subtract the number from the
4003 D6,30 SUI 30H
accumulator.
4005 32, 51, 40 STA 4051H Store the Binary result in memory
4008 76 HLT End of program

TEST DATA:

INPUT:

4050: 39

OUTPUT:

4051: 09

RESULT:

Thus, the assembly language program to convert from ASCII to BCD has
been executed successfully.

165
3. (B) BCD TO ASCII CONVERSION
AIM:

To write an Assembly Language Program to convert ASCII to BCD.

ALGORITHM:

STEP 1: Start.
STEP 2: Take the BCD number
STEP 3: Add 30 with accumulator
STEP 4: Store content of accumulator to memory
STEP 5: End.

PROGRAM:

ADDRESS OPCODE MNEMONICS COMMENTS


4000 3A,50,40 LDA 4050H Take the ASCII number in accumulator
4003 C6,30 ADI 30H Subtract the number from the
accumulator.
4005 32, 51, 40 STA 4051H Store the Binary result in memory
4008 76 HLT End of program

TEST DATA:

INPUT:

4050: 08

OUTPUT:

4051:38

RESULT:

Thus, the assembly language program to convert from BCD to ASCII has

been executed successfully.

166
V APPLICATIONS
1. SQUARE OF A SINGLE BYTE HEX NUMBER
AIM:
To write an Assembly Language Program to find the square of a number.
ALGORITHM:
STEP 1: Start the 8085 assembly language program.
STEP 2: Initialize the registers H and L with 40, 50
STEP 3: Moves the content of memory location M to register B
STEP 4: Add the content of memory location which is directly specifies by M in
accumulator A
STEP 5: Decrement value of register B by 1
STEP 6: If ZF=0, the L1 jump to memory
STEP 7: Store value of A in 4050
STEP 5: End
PROGRAM:

ADDRESS OPCODE LABEL MNEMONICS COMMENTS


4000 26, 40 MVI H, 40 Initialize register H with 40
4002 2E, 50 MVI L, 50 Initialize register L with 50
4004 3E, 00 MVI A, 00 Initialize accumulator A with 00
Moves the content of memory location M in
4005 46 MOV B, M
register B
Add the content of memory location which is
4006 86 L1 ADD M
directly specifies by M in accumulator A
4007 05 DCR B Decrement value of register B by 1
4008 C2, 06, 40 JNZ L1 Jump to memory location L1, if ZF=0,
400B 32, 51, 40 STA 4051 Store value of A in 4050
400E 76 HLT Stop executing the program
TEST DATA:

INPUT:

4050: D4

OUTPUT:

4051: 10

RESULT:
Thus, the assembly language program to find the square of a number has been executed
successfully.

167
2. SQUARE OF A TWO DIGIT BCD NUMBER
AIM:

To write an Assembly Language Program to square of a two digit BCD number.

ALGORITHM:

STEP 1 : Start.
STEP 2 : Take the multiplicand in accumulator from memory.
STEP 3 : Transfer the multiplicand to B register.
STEP 4 : Take the multiplier in accumulator from memory.
STEP 5 : Transfer it to C register.
STEP 6 : Clear the accumulator
STEP 7 : Add the content of B register with that of the accumulator.
STEP 8 : Use DAA to convert the number in accumulator to decimal
STEP 9 : Decrement the decimal count in C register by one.
STEP 10 : If C is not zero, go to STEP 7.
STEP 11 : Store the BCD product in memory.
STEP 12 : End.

PROGRAM:

ADDRESS OPCODE LABEL MNEMONICS COMMENTS

4000 21, 50, 40 LXI H, 4050 Load the number from 4050

4003 AF XRA A Clear accumulator


4004 46 MOV B,M Load data from memory to B
4005 86 L1 ADD M Add memory byte with A

4006 05 DCR B Decrease B by 1


4007 C2, 05,40 JNZ L1 If Z=0, Jump to loop
400A 32, 51, 40 STA 4051 Store result into memory

400D 76 HLT End of program

TEST DATA:

INPUT:

4050: 08

OUTPUT:

4051: 10

RESULT:

Thus, the assembly language program to square of a two digit BCD numbers has
been executed successfully.
168
3. SQUARE ROOT OF A SINGLE BYTE HEX NUMBER
AIM:
To write 8085 Assembly Language Program to find square root of a single byte hex
number.

ALGORITHM:

STEP 1: Start the 8085 assembly language program


STEP 2: Loads the content of memory location 4050 in accumulator A
STEP 3: Initialize registers B and C with o1
STEP 4: Subtract value from A
STEP 5: If ZF=0, then jump to memory location L1
STEP 6: Increment value of register C by 1
STEP 7: Increment value of register B by 1. It is used two times.
STEP 8: Make jump to L2
STEP 9: Moves the value of register C in accumulator A
STEP 10: Store the value of A in 4051
STEP 11: Stop the program.

PROGRAM:

ADDRESS OPCODE LABEL MNEMONICS COMMENTS


4000 3A LDA 4050 Loads the content
4001 06,01 MVI B,01 Initialize register B with 01
4003 0E,01 MVI C,01 Initialize register C with 01
4005 90 L2 SUB B Subtract value from A
4006 CA,0F, 40 JZ L1 If ZF=0, then jump to memory location L1
4009 0C INR C Increments value of register by 1
400A 04 INR B Increment value of register B by 1. It is used
two times.
400B 04 INR B
400C C3,05,40 JMP L2 Make jump to L2
400F 79 L1 MOV A,C Moves the value of register C in accumulator
A
4010 32,51,40 STA 4051 Stores value of A in 4051
4013 76 HLT Stop executing the program

TEST DATA
INPUT:
4050: 09
OUTPUT:
4051: 03

RESULT:
Thus, the assembly language program to find square root of a single byte hex
number has been executed successfully.

169
4. SQUARE ROOT OF A TWO DIGIT BCD NUMBER

AIM:

To write an Assembly Language Program to find the square root of a two digit
BCD number.

ALGORITHM:

STEP 1 : Start the assembly language program


STEP 2 : Load the number into accumulator
STEP 3 : Load B and C register with 01
STEP 4 : Subtract B register
STEP 5 : Jump Zero, when Z=1
STEP 6 : Increment C register by 1
STEP 7 : Increment B register by 1
STEP 8 : Increment B register by 1
STEP 9 : Move the number C register to accumulator
STEP 10: Store the result in accumulator.
STEP 11: End

PROGRAM:

ADDRESS OPCODE LABEL MNEMONICS COMMENTS


4000 3A,50,40 LDA 4050 Load the number into
accumulator
4003 06,01 MVI B,01 Load B register with 01
4005 0E,01 MVI C,01 Load C register with 01
4007 90 SUB B Subtract B register
4008 CA,0E,40 JZ L1 If Z=1, the jump to L1
400B 0C INR C Increment C register by 1
400C 04 INR B Increment B register by 1
400D 04 INR B Increment B register by 1
400E 79 L1 MOV A,C Move the content C to A
400F 32,51,40 STA 4051 Store the square root value in
4051
4012 76 HLT End of Program

TEST DATA:

INPUT:

4050: 19

OUTPUT:

4051: 05

RESULT:
Thus, the assembly language program to find the square root of a two digit BCD
170
has been executed successfully.
APPENDIX – I

8085 Instruction Set

S. NO. MNEMONICS OPCODE


1 ACI Data CE
2 ADC A 8F
3 ADC B 88
4 ADC C 89
5 ADC D 8A
6 ADC E 8B
7 ADC H 8C
8 ADC L 8D
9 ADC M 8E
10 ADD A 87
11 ADD B 80
12 ADD C 81
13 ADD D 82
14 ADD E 83
15 ADD H 84
16 ADD L 85
17 ADD M 86
18 ADI Data C6
19 ANA A A7
20 ANA B A0
21 ANA C A1
22 ANA D A2
23 ANA E A3
24 ANA H A4
25 ANA L A5
26 ANA M A6
27 ANI Data E6
28 CALL Label CD
29 CC Label DC
30 CM Label FC
31 CMA 2F
32 CMC 3F
33 CMP A BF
34 CMP B B8
35 CMP C B9
36 CMP D BA
37 CMP E BB
38 CMP H BC
39 CMP L BD
40 CMP M BD
41 CNC Label D4
42 CNZ Label C4
43 CP Label F4
44 CPE Label EC
45 CPI Data FE
46 CPO Label E4
47 CZ Label CC
171
48 DAA 27
49 DAD B 09
50 DAD D 19
51 DAD H 29
52 DAD SP 39
53 DCR A 3D
54 DCR B 05
55 DCR C 0D
56 DCR D 15
57 DCR E 1D
58 DCR H 25
59 DCR L 2D
60 DCR M 35
61 DCX B 0B
62 DCX D 1B
63 DCX H 2B
64 DCX SP 3B
65 DI F3
66 EI FB
67 HLT 76
68 IN Port-Address DB
69 INR A 3C
70 INR B 04
71 INR C 0C
72 INR D 14
73 INR E 1C
74 INR H 24
75 INR L 2C
76 INR M 34
77 INX B 03
78 INX D 13
79 INX H 23
80 INX SP 33
81 JC Label DA
82 JM Label FA
83 JMP Label C3
84 JNC Label D2
85 JNZ Label C2
86 JP Label F2
87 JPE Label EA
88 JPO Label E2
89 JZ Label CA
90 LDA Address 3A
91 LDAX B 0A
92 LDAX D 1A
93 LHLD Address 2A
94 LXI B 01
95 LXI D 11
96 LXI H 21
97 LXI SP 31
98 MOV A,A 7F
99 MOV A,B 78
100 MOV A,C 79
101 MOV A,D 7A
102 MOV A,E 7B
172
103 MOV A,H 7C
104 MOV A,L 7D
105 MOV A,M 7E
106 MOV B,A 47
107 MOV B,B 40
108 MOV B,C 41
109 MOV B,D 42
110 MOV B,E 43
111 MOV B,H 44
112 MOV B,L 45
113 MOV B,M 46
114 MOV C,A 4F
115 MOV C,B 48
116 MOV C,C 49
117 MOV C,D 4A
118 MOV C,E 4B
119 MOV C,H 4C
120 MOV C,L 4D
121 MOV C,M 4E
122 MOV D,A 57
123 MOV D,B 50
124 MOV D,C 51
125 MOV D,D 52
126 MOV D,E 53
127 MOV D,H 54
128 MOV D,L 55
129 MOV D,M 56
130 MOV E,A 5F
131 MOV E,B 58
132 MOV E,C 59
133 MOV E,D 5A
134 MOV E,E 5B
135 MOV E,H 5C
136 MOV E,L 5D
137 MOV E,M 5E
138 MOV H,A 67
139 MOV H,B 60
140 MOV H,C 61
141 MOV H,D 62
142 MOV H,E 63
143 MOV H,H 64
144 MOV H,L 65
145 MOV H,M 66
146 MOV L,A 6F
147 MOV L,B 68
148 MOV L,C 69
149 MOV L,D 6A
150 MOV L,E 6B
151 MOV L,H 6C
152 MOV L,L 6D
153 MOV L,M 6E
154 MOV M,A 77
155 MOV M,B 70
156 MOV M,C 71
157 MOV M,D 72
173
158 MOV M,E 73
159 MOV M,H 74
160 MOV M,L 75
161 MVI A, Data 3E
162 MVI B, Data 06
163 MVI C, Data 0E
164 MVI D, Data 16
165 MVI E, Data 1E
166 MVI H, Data 26
167 MVI L, Data 2E
168 MVI M, Data 36
169 NOP 00
170 ORA A B7
171 ORA B B0
172 ORA C B1
173 ORA D B2
174 ORA E B3
175 ORA H B4
176 ORA L B5
177 ORA M B6
178 ORI Data F6
179 OUT Port-Address D3
180 PCHL E9
181 POP B C1
182 POP D D1
183 POP H E1
184 POP PSW F1
185 PUSH B C5
186 PUSH D D5
187 PUSH H E5
188 PUSH PSW F5
189 RAL 17
190 RAR 1F
191 RC D8
192 RET C9
193 RIM 20
194 RLC 07
195 RM F8
196 RNC D0
197 RNZ C0
198 RP F0
199 RPE E8
200 RPO E0
201 RRC 0F
202 RST 0 C7
203 RST 1 CF
204 RST 2 D7
205 RST 3 DF
206 RST 4 E7
207 RST 5 EF
208 RST 6 F7
209 RST 7 FF
210 RZ C8
211 SBB A 9F
212 SBB B 98
174
213 SBB C 99
214 SBB D 9A
215 SBB E 9B
216 SBB H 9C
217 SBB L 9D
218 SBB M 9E
219 SBI Data DE
220 SHLD Address 22
221 SIM 30
222 SPHL F9
223 STA Address 32
224 STAX B 02
225 STAX D 12
226 STC 37
227 SUB A 97
228 SUB B 90
229 SUB C 91
230 SUB D 92
231 SUB E 93
232 SUB H 94
233 SUB L 95
234 SUB M 96
235 SUI Data D6
236 XCHG EB
237 XRA A AF
238 XRA B A8
239 XRA C A9
240 XRA D AA
241 XRA E AB
242 XRA H AC
243 XRA L AD
244 XRA M AE
245 XRI Data EE
246 XTHL E3

175

You might also like