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:
- Start
- Initialize one register (suppose C) to 00 to store the carry value.
- Load the first data (stored in 9000H) into accumulator A.
- Load the second data (stored in 9001H) into register pair HL.
- Move the content of memory into register B.
- Add the content of register B with the content of accumulator.
- If carry is present go to step 8 else go to step 9.
- Increment the value of register C by 1.
- Store the value present in Accumulator (i.e. sum value) in address 9100H.
- Move the content of register C into accumulator.
- Store the value present in accumulator (i.e. carry va) in address 9101H.
- 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