0% found this document useful (0 votes)
3K views20 pages

Experiment - 1 Addition of Two 8 Bit Numbers

The document describes an experiment to find the smallest number in an array of data using an 8085 microprocessor. It provides an algorithm that loads the address and count of the array, gets the first data element as the initial smallest number, compares each subsequent element to the current smallest, and updates the smallest if a smaller element is found. It stores the final smallest number in memory location 4300H. The program implements this algorithm to find the smallest number in a block of bytes stored from location 4201H.

Uploaded by

Madhur Aswani
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)
3K views20 pages

Experiment - 1 Addition of Two 8 Bit Numbers

The document describes an experiment to find the smallest number in an array of data using an 8085 microprocessor. It provides an algorithm that loads the address and count of the array, gets the first data element as the initial smallest number, compares each subsequent element to the current smallest, and updates the smallest if a smaller element is found. It stores the final smallest number in memory location 4300H. The program implements this algorithm to find the smallest number in a block of bytes stored from location 4201H.

Uploaded by

Madhur Aswani
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/ 20

EXPERIMENT -1

ADDITION OF TWO 8 BIT NUMBERS

AIM:

To perform addition of two 8 bit numbers using 8085.

ALGORITHM:

1) Start the program by loading the first data into Accumulator.


2) Move the data to a register (B register).
3) Get the second data and load into Accumulator.
4) Add the two register contents.
5) Check for carry.
6) Store the value of sum and carry in memory location.
7) Terminate the program.

THEORY:

To perform this task, we are using the ADD operation of 8085 Microprocessor. When
the result of the addition is the 1-byte result, then the carry flag will not be enabled.
When the result is exceeding the 1-byte range, then the carry flag will be 1
PROGRAM:

MVI C, 00 Initialize C register to 00


LDA 4150 Load the value to Accumulator.
MOV B, A Move the content of Accumulator to B register.
LDA 4151 Load the value to Accumulator.
ADD B Add the value of register B to A
JNC LOOP Jump on no carry.
INR C Increment value of register C
LOOP: STA 4152 Store the value of Accumulator (SUM).
MOV A, C Move content of register C to Acc.
STA 4153 Store the value of Accumulator (CARRY)
HLT Halt the program.
OBSERVATION/RESULTS:

Input: 80 (4150)
80 (4251)
Output: 00 (4152)
01 (4153)

CONCLUSION:

Thus the program to add two 8-bit numbers was executed.


EXPERIMENT- 2
SUBTRACTION OF TWO 8 BIT NUMBERS

AIM:

To perform the subtraction of two 8 bit numbers using 8085.

ALGORITHM:

1. Start the program by loading the first data into Accumulator.


2. Move the data to a register (B register).
3. Get the second data and load into Accumulator.
4. Subtract the two register contents.
5. Check for carry.
6. If carry is present take 2’s complement of Accumulator.
7. Store the value of borrow in memory location.
8. Store the difference value (present in Accumulator) to a memory
9. location and terminate the program.

THEORY:

In 8085, the SUB instruction is used 2’s complemented method for subtraction. When
the first operand is larger, the result will be positive. It will not enable the carry flag after
completing the subtraction. When the result is negative, then the result will be in 2’s
complemented form and carry flag will be enabled.
PROGRAM:

MVI C, 00 Initialize C to 00
LDA 4150 Load the value to Acc.
MOV B, A Move the content of Acc to B register.
LDA 4151 Load the value to Acc.
SUB B
JNC LOOP Jump on no carry.
CMA Complement Accumulator contents.
INR A Increment value in Accumulator.
INR C Increment value in register C
LOOP: STA 4152 Store the value of A-reg to memory address.
MOV A, C Move contents of register C to Accumulator.
STA 4153 Store the value of Accumulator memory address.
HLT Terminate the program.

OBSERVATION/RESULTS:

Input: 06 (4150)
02 (4251)

Output: 04 (4152)
01 (4153)

CONCLUSION:

Thus the program to subtract two 8-bit numbers was executed.


EXPERIMENT- 3
MULTIPLICATION OF TWO 8 BIT NUMBERS

AIM:

To perform the multiplication of two 8 bit numbers using 8085.

ALGORITHM:

1) Start the program by loading HL register pair with address of memory location.
2) Move the data to a register (B register).
3) Get the second data and load into Accumulator.
4) Add the two register contents.
5) Check for carry.
6) Increment the value of carry.
7) Check whether repeated addition is over and store the value of product and carry
in memory location.
8) Terminate the program.

THEORY:

The 8085 has no multiplication operation. To get the result of multiplication, we should
use the repetitive addition method.
After multiplying two 8-bit numbers it may generate 1-byte or 2-byte numbers, so we
are using two registers to hold the result.

PROGRAM:

MVI D, 00 Initialize register D to 00


MVI A, 00 Initialize Accumulator content to 00
LXI H, 4150
MOV B, M Get the first number in B - reg
INX H
MOV C, M Get the second number in C- reg.
LOOP: ADD B Add content of A - reg to register B.
JNC NEXT Jump on no carry to NEXT.
INR D Increment content of register D
NEXT: DCR C Decrement content of register C.
JNZ LOOP Jump on no zero to address
STA 4152 Store the result in Memory
MOV A, D
STA 4153 Store the MSB of result in Memory
HLT Terminate the program.

OBSERVATION/RESULTS:

Input: FF (4150)
FF (4151)
Output: 01 (4152)
FE (4153)

CONCLUSION:

Thus the program to multiply two 8-bit numbers was executed.


EXPERIMENT- 4

DIVISION OF TWO 8 BIT NUMBERS

AIM:

To perform the division of two 8 bit numbers using 8085.

ALGORITHM:

1) Start the program by loading HL register pair with address of memory location.
2) Move the data to a register(B register).
3) Get the second data and load into Accumulator.
4) Compare the two numbers to check for carry.
5) Subtract the two numbers.
6) Increment the value of carry .
7) Check whether repeated subtraction is over and store the value of product and
carry in memory location.
8) Terminate the program.

THEORY:

The 8085 has no division operation. To get the result of the division, we should use the
repetitive subtraction method.

By using this program, we will get the quotient and the remainder. 4153H will hold the
quotient, and 4152H will hold the remainder.

PROGRAM:

LXI H, 4150
MOV B, M Get the dividend in B – reg.
MVI C, 00 Clear C – reg for qoutient
INX H
MOV A, M Get the divisor in A – reg.
NEXT: CMP B Compare A - reg with register B.
JC LOOP Jump on carry to LOOP
SUB B Subtract A – reg from B- reg.
INR C Increment content of register C.
JMP NEXT Jump to NEXT
LOOP: STA 4152 Store the remainder in Memory
MOV A, C
STA 4153 Store the quotient in memory
HLT Terminate the program.

OBSERVATION/RESULTS:

Input: FF (4150)
FF (4251)

Output: 01 (4152) ----- Remainder


FE (4153) -----Quotient

CONCLUSION:

Thus the program to divide two 8-bit numbers was executed


EXPERIMENT- 5
SMALLEST NUMBER IN AN ARRAY OF DATA

AIM:

To find the smallest number in an array of data using 8085 instruction set.

ALGORITHM:

1) Load the address of the first element of the array in HL pair


2) Move the count to B – reg.
3) Increment the pointer
4) Get the first data in A – reg.
5) Decrement the count.
6) Increment the pointer
7) Compare the content of memory addressed by HL pair with that of A - reg.
8) If carry = 1, go to step 10 or if Carry = 0 go to step 9
9) Move the content of memory addressed by HL to A – reg.
10) Decrement the count
11) Check for Zero of the count. If ZF = 0, go to step 6, or if ZF = 1 go to next step.
12) Store the smallest data in memory.
13) Terminate the program.

THEORY:

In this program the data are stored at location 4201H onwards. The 4200H is containing
the size of the block. After executing this program, it will return the smallest number and
store it at location 4300H.
Logic is simple, we are taking the first number at register B to start the job. In each
iteration we are getting the number from memory and storing it into register A. Then if
B > A, then we simply update the value of B with A, otherwise go for the next iteration.
Thus we can find the smallest number in a block of bytes.

PROGRAM:

LXI H,4200 Set pointer for array


MOV B,M Load the Count
INX H
MOV A,M Set 1st element as largest data
DCR B Decrement the count
LOOP: INX H
CMP M If A- reg < M go to AHEAD
JC AHEAD
MOV A,M Set the new value as smallest
AHEAD: DCR B
JNZ LOOP Repeat comparisons till count = 0
STA 4300 Store the smallest value at 4300
HLT

OBSERVATION/RESULTS:

Input: 05 (4200) ----- Array Size


0A (4201)
F1 (4202)
1F (4203)
26 (4204)
FE (4205)

Output: 0A (4300)

CONCLUSION:

Thus the program to find the smallest number in an array of data was executed
EXPERIMENT-6
LARGEST NUMBER IN AN ARRAY OF DATA

AIM:

To find the largest number in an array of data using 8085 instruction set.

ALGORITHM:

1) Load the address of the first element of the array in HL pair


2) Move the count to B – reg.
3) Increment the pointer
4) Get the first data in A – reg.
5) Decrement the count.
6) Increment the pointer
7) Compare the content of memory addressed by HL pair with that of A - reg.
8) If Carry = 0, go to step 10 or if Carry = 1 go to step 9
9) Move the content of memory addressed by HL to A – reg.
10) Decrement the count
11) Check for Zero of the count. If ZF = 0, go to step 6, or if ZF = 1 go to next
step.
12) Store the largest data in memory.
13) Terminate the program.

THEORY:

In this program the data are stored at location 4201H onwards. The 4200H is
containing the size of the block. After executing this program, it will return the largest
number and store it at location 4300H.
Logic is simple, we are taking the first number at register B to start the job. In each
iteration we are getting the number from memory and storing it into register A. Then
if B < A, then we simply update the value of B with A, otherwise go for the next
iteration. Thus we can find the largest number in a block of bytes.

PROGRAM:

LXI H,4200 Set pointer for array


MOV B,M Load the Count
INX H
MOV A,M Set 1st element as largest data
DCR B Decrement the count
LOOP: INX H
CMP M If A- reg > M go to AHEAD
JNC AHEAD
MOV A,M Set the new value as largest
AHEAD: DCR B
JNZ LOOP Repeat comparisons till count = 0
STA 4300 Store the largest value at 4300
HLT

OBSERVATION/RESULTS:

Input: 05 (4200) ----- Array Size


0A (4201)
F1 (4202)
1F (4203)
26 (4204)
FE (4205)

Output: FE (4300)

CONCLUSION:

Thus the program to find the largest number in an array of data was executed
EXPERIMENT-7
BCD TO HEX CONVERSION

AIM:

To convert two BCD numbers in memory to the equivalent HEX number using
8085 instruction set

ALGORITHM:

1) Initialize memory pointer to 4150 H


2) Get the Most Significant Digit (MSD)
3) Multiply the MSD by ten using repeated addition
4) Add the Least Significant Digit (LSD) to the result obtained in previous step
5) Store the HEX data in Memory

THEORY:

In this problem we are taking a BCD number from the memory and converting
it to its binary equivalent. At first we are cutting each nibble of the input. So if
the input is 52 (0101 0010) then we can simply cut it by masking the number by
0FH and F0H. When the Higher order nibble is cut, then rotate it to the left
four times to transfer it to lower nibble.
Now simply multiply the numbers by using decimal adjust method to get final
decimal result.

PROGRAM:

LXI H,4150
MOV A,M Initialize memory pointer
ADD A MSD X 2
MOV B,A Store MSD X 2
ADD A MSD X 4
ADD A MSD X 8
ADD B MSD X 10
INX H Point to LSD
ADD M Add to form HEX
INX H
MOV M,A Store the result
OBSERVATION/RESULTS:

Input: 4150 : 02 (MSD)


4151 : 09 (LSD)

Output: 4152 : 1D H

CONCLUSION:

Thus the program to convert BCD data to HEX data was executed.
EXPERIMENT- 8
HEX TO BCD CONVERSION

AIM:

To convert given Hexa decimal number into its equivalent BCD number using
8085 instruction set

ALGORITHM:

1) Initialize memory pointer to 4150 H


2) Get the Hexa decimal number in C - register
3) Perform repeated addition for C number of times
4) Adjust for BCD in each step
5) Store the BCD data in Memory

THEORY:

Here we are taking a number from the memory, and initializing it as a counter.
Now in each step of this counter we are incrementing the number by 1, and adjust
the decimal value. By this process we are finding the BCD value of binary number
or hexadecimal number.
We can use INR instruction to increment the counter in this case but this
instruction will not affect carry flag, so for that reason we have used ADI 10H

PROGRAM:

LXI H,4150 Initialize memory pointer


MVI D,00 Clear D- reg for Most significant Byte
XRA A Clear Accumulator
MOV C,M Get HEX data
LOOP2: ADI 10H Count the number one by one
DAA Adjust for BCD count
JNC LOOP1
INR D
LOOP1: DCR C
JNZ LOOP2
STA 4151 Store the Least Significant Byte
MOV A,D
STA 4152 Store the Most Significant Byte
HLT
OBSERVATION/RESULTS:

Input: 4150 : FF

Output: 4151 : 55 (LSB)


4152 : 02 (MSB)

CONCLUSION:

Thus the program to convert HEX data to BCD data was executed.
EXPERIMENT-9
HEX TO ASCII CONVERSION

AIM:

To convert given Hexa decimal number into its equivalent ASCII number
using 8085 instruction set.

ALGORITHM:

1. Load the given data in A- register and move to B – register


2. Mask the upper nibble of the Hexa decimal number in A – register
3. Call subroutine to get ASCII of lower nibble
4. Store it in memory
5. Move B –register to A – register and mask the lower nibble
6. Rotate the upper nibble to lower nibble position
7. Call subroutine to get ASCII of upper nibble
8. Store it in memory
9. Terminate the program.

THEORY:

The logic behind HEX to ASCII conversion is very simple. We are just checking
whether the number is in range 0 – 9 or not. When the number is in that range,
then the hexadecimal digit is numeric, and we are just simply adding 30H with it to
get the ASCII value. When the number is not in range 0 – 9, then the number is
range A – F, so for that case, we are converting the number to 41H onwards.

PROGRAM:

LDA 4200 Get Hexa Data


MOV B,A
ANI 0F Mask Upper Nibble
CALL SUB1 Get ASCII code for upper nibble
STA 4201
MOV A,B
ANI F0 Mask Lower Nibble
RLC
RLC
RLC
RLC
CALL SUB1 Get ASCII code for lower nibble
STA 4202
HLT
SUB1: CPI 0A
JC SKIP
ADI 07
SKIP: ADI 30
RET

OBSERVATION/RESULTS:

Input: 4200 E4(Hexa data)

Output: 4201 34(ASCII Code for 4)


4202 45(ASCII Code for E)

CONCLUSION:

Thus the given Hexadecimal number was converted into its equivalent ASCII Code.
EXPERIMENT-10

ARRANGE AN ARRAY OF DATA IN ASCENDING


ORDER

AIM:

To write a program to arrange an array of data in ascending order

ALGORITHM:

1. Initialize HL pair as memory pointer


2. Get the count at 4200 into C – register
3. Copy it in D – register (for bubble sort (N-1) times required)
4. Get the first value in A – register
5. Compare it with the value at next location.
6. If they are out of order, exchange the contents of A –register and Memory
7. Decrement D –register content by 1
8. Repeat steps 5 and 7 till the value in D- register become zero
9. Decrement C –register content by 1
10. Repeat steps 3 to 9 till the value in C – register becomes zero

THEORY:

In this program we will arrange the numbers in bubble sorting technique. In this sorting
technique, it will be executed in different pass. In each pass the largest number is stored at
the end of the list. Here we are taking the numbers from location 4201H . The array size is
stored at 4200H.

PROGRAM:

LXI H,4200
MOV C,M
DCR C
REPEAT: MOV D,C
LXI H,4201
LOOP: MOV A,M
INX H
CMP M
JC SKIP
MOV B,M
MOV M,A
DCX H
MOV M,B
INX H
SKIP: DCR D
JNZ LOOP
DCR C
JNZ REPEAT
HLT

OBSERVATION/RESULTS:

Input: 4200 05 (Array Size)


4201 05
4202 04
4203 03
4204 02
4205 01

Output: 4200 05(Array Size)


4201 01
4202 02
4203 03
4204 04
4205 05

CONCLUSION:

Thus the given array of data was arranged in ascending order.

You might also like