Let us suppose that we have 10 data’s which are stored from
memory address 9000H to 9009H. We find the smallest number from these data’s
and store the value in 9100H.
Algorithm:
- Start.
- Load into register pair HL from memory location 9000H.
- Move 09 into register C.
- Move the contents of memory M into accumulator A.
- Increment register pair HL by 1.
- Compare the contents of memory M with the contents of the accumulator A.
- If carry is present go to step 9 else go to 8.
- Move the contents of memory M into accumulator A.
- Decrement register C by 1.
- If no zero is present, go to step 5.
- Store the contents of accumulator A into memory location 9100H.
- Terminate the program.
Program Code:
LXI H,9000H
MVI C, 09H
MOV A,M
UP:
INX H
CMP M
JC DOWN
MOV A,M
DOWN:
DCR C
JNZ UP
STA 9100H
HLT
Register pair HL is loaded from the memory location 9000H.
09 is moved into register C to use it as counter as we need to make 9
comparisons. The content of memory is moved into the accumulator A (meaning
that the first data is now in accumulator A). The register pair HL is
incremented by 1(meaning that HL now points to the next data). The content of
accumulator is compared with the content of memory. During comparison, if
accumulator A < (is less than) content of memory M then the carry flag is
set. So if carry flag is not set then the content of memory is moved into
accumulator A, else this instruction is skipped and register C is decreased by
1. We again increment the register pair HL by 1 and perform these same
instructions as long as the counter is greater than 0. Then the content of
accumulator A, which is the smallest number, is stored in memory location
9100H.
Output:
Example 1 |
In this example we can see that the smallest number (i.e. in
address 9100) is 01. If we see the data’s then the smallest number is 00. But
since we compare only 10 data’s i.e. data’s from address 9000 to 9009 so we don’t
compare 00. Therefore, 01 is the smallest data.
I recommend to all This article To every One.
ReplyDeleteHow to Check Diode Working condition
Here You Can Find Unlimited Whatsapp group Name For Promoting Your group
Also You can see This Online Money Earning Ways
Top 25 Tamil Movies Download Website
இதுவும் உங்களுக்கு உதவியாக இறுக்கும் நீங்கள் வளர வாழ்த்துக்க்கள் தமிழ் படங்களை பார்க்க 25 website Tamil Movies Website
You Need Governement Job Then Go to This Link Ind Govt job
CLICK HERE to download Free books
ReplyDelete