DOC-20240123-WA0007.
DOC-20240123-WA0007.
I YEAR / II SEM
OBJECTIVES:
To understand the programming features and operations of assembly language programs using 8085
microprocessor kit or Simulator
OUTCOMES:
LIST OF EXERCISES:
1. 8 - bit addition
2. 16 - bit addition
3. 8 - bit subtraction
4. BCD subtraction
l . 8 - bit multiplication
2. BCD multiplication
3. 8 - bit division
V: Applications
134
I: ADDITION AND SUBTRACTION
1. 8-BIT ADDITION
AIM:
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:
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:
Thus, the assembly language program to subtract two 8-bit numbers has been executed
successfully.
138
4. BCD SUBTRACTION
AIM:
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
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:
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:
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:
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:
4102 50
4103 40
4103 47 MOV B,A Transfer the multiplicand to B register
4105 51
4106 40
4107 4F MOV C,A Transfer the multiplier to C register
143
410F 27 DAA Convert it into decimal
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:
4101 50
4102 40
4103 47 MOV B, A Transfer the divisor to B register
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
145
410C 09
410D 41
Add the contents of A and B to get the
410E 80 ADD B remainder
4110 53
4111 40
Transfer the quotient in C register to
4112 79 MOV A,C accumulator
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
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:
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:
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:
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:
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:
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:
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:
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
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:
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:
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
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:
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:
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:
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:
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:
TEST DATA:
INPUT:
4050:0BH
OUTPUT:
4051: 42H
RESULT:
Thus, the assembly language program to convert from Binary to ASCII has been
executed successfully.
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:
TEST DATA:
INPUT:
4050: 42H
OUTPUT:
4051: 0BH
RESULT:
Thus, the assembly language program to convert from ASCII to Binary has
164
3. (A) ASCII TO BCD CONVERSION
AIM:
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:
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:
TEST DATA:
INPUT:
4050: 08
OUTPUT:
4051:38
RESULT:
Thus, the assembly language program to convert from BCD to ASCII has
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:
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:
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:
4000 21, 50, 40 LXI H, 4050 Load the number from 4050
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:
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:
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
175