Wednesday, October 14, 2015

8085 Program To Add Two 8 Bit Numbers


Let us suppose that we store the two 8 bit numbers that are to be added in the memory location 9000H and 9001H. Now the sum of the numbers is to be stored in 9100H and the carry is to be stored in 9101H.

Algorithm:

  1. Start
  2.  Initialize one register (suppose C) to 00 to store the carry value.
  3. Load the first data (stored in 9000H) into accumulator A.
  4. Load the second data (stored in 9001H) into register pair HL.
  5. Move the content of memory into register B.
  6. Add the content of register B with the content of accumulator.
  7. If carry is present go to step 8 else go to step 9.
  8. Increment the value of register C by 1.
  9. Store the value present in Accumulator (i.e. sum value) in address 9100H.
  10. Move the content of register C into accumulator.
  11. Store the value present in accumulator (i.e. carry va) in address 9101H.
  12. Terminate the program.

Program Code:


MVI C,00H
LDA 9000H
LXI H,9001H
MOV B,M
ADD B
JNC DOWN
INR C
DOWN:
STA 9100H
MOV A,C
STA 9101H
HLT


The register C is initialized with value 00 at the beginning to store the value of carry. The value stored in memory location 9000H is then loaded into the accumulator which is the first 8 bit number to be added. The value stored in memory location 9001H is loaded into the register pair HL which is the second 8bit number to be added. M is the memory that points the content of L register. So the content of M is moved into register B meaning that the second 8 bit number is now moved to register B. The content of the accumulator A is added with the content of register B and the result is stored in the accumulator. On addition, if carry is generated then the value of register C is incremented by 1 but if no carry is present the flow jumps to “DOWN” (skips the increment of register C i.e. INR C). The content of the accumulator (i.e. the sum value)  is stored in memory location 9100H. The content of register C is moved to register A and the content of accumulator (i.e. the carry value) is stored in memory location 9101H. As 8085 is an accumulator based microprocessor so the results are first transferred to the accumulator and then from the accumulator to the desired destination.

Output:


Example: 1

Here, 03 is the first 8 bit number and 05 is the second 8 bit number. These numbers are added and stored to memory location 9100H. Here,
  03
+05
-----
 08

Since no carry is generated in this case so 9100H has 00 value.


Example: 2

Here, FF is the first 8 bit number and FF is the second 8 bit number. These numbers are added and stored to memory location 9100H. Here,
  FF
+FF
-----
1FE


Here, 1 is the carry value that is generated by the addition of the numbers so 9100H stores the sum value i.e. FE and 9101H has the carry value i.e. 01.

No comments:

Post a Comment