Let us suppose that 10 data’s are stored in memory location
from 9000H to 9009H. These data’s are to be added and let us store the result
in memory location 9100H.
Algorithm:
- Start.
- Load into register pair HL from memory location 9000H.
- Load into register pair DE from memory location 9100H.
- Move 09 into register C as counter.
- Move the content of memory M into accumulator A.
- Increment register pair HL by 1.
- Add content of memory M with the contents of the accumulator A.
- Decrement value of register C by 1.
- If no zero is present, go to step 6 else go to step 10.
- Store the content of accumulator A into memory location pointed by register pair DE.
- Terminate the program.
Program Code:
LXI H, 9000H
LXI D, 9100H
MVI C, 09H
MVI B, 00H
MOV A, M
UP:
INX H
ADD M
JNC DOWN
INR B
DOWN:
DCR C
JNZ UP
STAX D
MOV A, B
STA 9101H
HLT
Register pair HL is loaded from memory location 9000H and
register pair DE is loaded from memory location 9100H (For understanding,
loaded can be referred to as pointed). 09 is moved into register C so as to use
it as counter. Register B is initialized with value 00 to count the carry
generated during the addition. The content of memory M (i.e. the first data
which is stored in memory location 9000H) is moved into the accumulator A.
Register pair HL is incremented by 1 (now it points to the second data i.e.
stored in memory location 9001H) and the contents of memory M is added with the
contents of the accumulator and the result is stored in the accumulator. If
carry is generated during addition then the register B is incremented by 1, if
no carry is generated then the instruction
INR B
is skipped and the content of register C is decremented by
1. The register pair HL in again incremented by 1, content of memory M is added
with accumulator A and the condition of borrow is checked again and the counter
is decreased by 1. These steps are repeated as long as the counter is greater
than 0. When the counter is 0, it means that all the 10 data has been added.
Now, the content of accumulator (which is the sum value) is stored into memory
location pointed by register D. The content of register B is moved into
accumulator and is stored into memory location 9101H which is the carry value.
Output:
Example 1 |
Example 2 |
In these two examples, the data from address 9000 to 9009 is
added and the sum is stored in address 9100 and the carry is stored in 9101.
THANK U
ReplyDeletewrong program
ReplyDeleteKya hoga
ReplyDeleteMGM National Harbor - MapyRO
ReplyDeleteDirections 구리 출장샵 to MGM 삼척 출장마사지 National Harbor (MGM) with MapyR road. The following transit lines have routes that pass 평택 출장안마 near MGM 제천 출장안마 National Harbor. These routes have routes that pass 상주 출장샵 near MGM