# ALP for searching

Discussion in 'Assembly Language Programming (ALP) Forum' started by mangup, Jan 27, 2009.

1. ### mangupNew Member

Joined:
Jan 27, 2009
Messages:
10
0
Trophy Points:
0
dear alll

I am beginner in ALP 8085. So please help in solving my following prob.

Suppose there are 10 eight bit numbers stored at memory location starting from 3050h. store the numbers that are less than 91h in memory location starting from 3060h, else store them in memory location starting from 3070h.

what i did is:
LXI H,3050h
LXI B,3050h
LXI D,3070h

now how to initialize the loop counter coz there is no any register left for that as 8085 have only B,C,D,E,H and L register as i know.
Please help me , I will appreciate every help. Thanks u a lot in advance. direct e-mail responses are also welcomed at: mang_almi@yahoo.com/hotmail.com

2. ### mangupNew Member

Joined:
Jan 27, 2009
Messages:
10
0
Trophy Points:
0
hello all..
please help ....u are the expert....and i am a learner........

3. ### xpi0t0sMentor

Joined:
Aug 6, 2004
Messages:
3,009
203
Trophy Points:
63
Occupation:
Senior Support Engineer
Location:
England
What's your algorithm? Can you write out in pseudocode what the program will do? This is a good first step as it will give you an overview as to what storage is needed.
If you're short on registers why have you loaded B and H with the same info?
How many variables do you think you need to implement a search?

4. ### mangupNew Member

Joined:
Jan 27, 2009
Messages:
10
0
Trophy Points:
0

Thanks a lot ..and sorry for that type mistake that instead of
LXI B,3050h, there is LXI B,3060h.

Ok the detail question once again...
A set of 10 bytes is stored in memory starting with the address 3050h. Write a program to check each byte and save the bytes that are higher than 91h at address starting from 3060h and lower than or equal to 91h at memory address starting from 3070h.
what i did
Code:
```START:  LXI H,3050h
LXI B,3060h
LXI D,3070
LOOP:MOV A,M
CPI 91H
JC NEXT
STAX B
INX B
INX H
JMP LOOP
NEXT: STAX D
INX D
INXH
IMP LOOP
HLT```
But i guess, this is in an infinite loop because there is no any loop terminating condition. So how to solve this prob.

Last edited by a moderator: Jan 30, 2009
5. ### mangupNew Member

Joined:
Jan 27, 2009
Messages:
10
0
Trophy Points:
0
can any one help me please........

<<<<<<<<<THERE IS AT LEAST ONE EXPERT FOR EVERY PROBLEM>>>>>>>>>>

6. ### xpi0t0sMentor

Joined:
Aug 6, 2004
Messages:
3,009
203
Trophy Points:
63
Occupation:
Senior Support Engineer
Location:
England
Well, what's your algorithm? You always need to start with an algorithm otherwise you have no chance of getting the code right.
Something like:
Code:
```ptr=3050
a=0 b=0
while ptr<305a
if M>91 store M at 3060+a; increment a
else store M at 3070+b; increment b
end while
```
Checking an 8085 reference I found in Google:
http://cavehill.uwi.edu/fpas/cmp/online/el21c/lesson18.html

looks like we can use STAX B and STAX D to effect "store M at 3060+a" and "store M at 3070+b" and INX B, INX D to increment, in effect, a and b.

We can use HL to start out at 3050 and we should bail out after testing and storing the contents of address 305a. It doesn't look like there is a 16 bit compare (for something like "if HL=305a jump to end of program") so how do you think you might accomplish that? (cryptic hint: 6F, or BD)

7. ### mangupNew Member

Joined:
Jan 27, 2009
Messages:
10
0
Trophy Points:
0
dear sir...
could you please do it with the exact solution rather than the hint. I will appreciate if be helped coz i am the beginner so its hard to catch the word "how to bail out the contents of 3050". Also can we make use of stack register which also can hold 16 bit, instead of H or D. Please sir, for me , i hope step by step help and solution. I hope u can do it and u are far more expert than me (a learner). I followed the above link but no exact answer is found. so...plzzzzz....

8. ### xpi0t0sMentor

Joined:
Aug 6, 2004
Messages:
3,009
203
Trophy Points:
63
Occupation:
Senior Support Engineer
Location:
England
No, because programming is a skill learnt by doing, not by reading other people's examples of completed programs. Otherwise a programming course would simply comprise "lesson 1, here read this code; lesson 2, here read this code", wouldn't it?

So have a go and see how far you get. It doesn't matter if it doesn't work first time. Work through the algorithm I presented line by line and see if you can decide what code it should generate. In the algorithm I used variables ptr, a, b and M. What registers could you use for these?

"Bail out" just means ending the loop. At some point in the program you need to compare HL with 305a and jump to the next instruction after the loop if it's equal or greater.

Don't try to use the stack register. It has a specific use that you'll come across later. BC, DE and HL are register pairs that can hold 16-bit values and you'll see at the above reference instructions that operate on them, e.g. DAD, DCX, INX, LXI. I found six others; can you find four of them (and for extra credit, six, and for a gold star, see if I missed any)?

9. ### mangupNew Member

Joined:
Jan 27, 2009
Messages:
10
0
Trophy Points:
0

thanks a lot .....
now my exams are finished ,, so i will resume the same question again ..... and want to finish now.....

So i will write the question once again..
A table having starting address 3060h contains 10 number of 8 bit data. Write a program in 8085 that transfer the data to the next table having starting address 3070h if the data is less than 90h. else store into next table at 3080h.

I have done this much.....please check if i am right ....and also hoping for the suggestion.....i will appreciate if i get the solution....

LXI H 3060h
LDAX H
LXI H, 3070h
LXI D,3080h
MVI B,0Ah

LOOP:CPI 90h
JC NEXT
STAX D
INX D
DCR B
JZ END
JMP LOOP

NEXT: STAX H
INX H
DCR B
JZ END
JMP LOOP

END:HLT

I know there is something wrong with this program, but would u please rectify that and can i hope for the best solution. I am hanging up with this since you know sir.....

10. ### xpi0t0sMentor

Joined:
Aug 6, 2004
Messages:
3,009
203
Trophy Points:
63
Occupation:
Senior Support Engineer
Location:
England
> please check if i am right

Well, does it do what you expect?
If not, what does it do wrong?
Where do things start going wrong?

> I know there is something wrong with this program

How do you know there is something wrong? Does it do something you didn't expect, and if so precisely what?

Have you tried dry running the code? What that means is that you take a piece of paper and a pencil and you play the part of the CPU and execute the code manually, writing down changes that take place and comparing that with what you think should happen.

For example you might have a box labelled HL. The command "LXI H 3060h" would result in you writing 3060 in that box. Then go on to the next line.

{thread review} Hmm, it seems you're ignoring the helpful hints I am giving you and just repeating the question. NO I AM NOT GOING TO GIVE YOU THE ANSWER SO STOP ASKING. But I *will* help you figure it out by giving you the relevant guidance. PROGRAMMING IS A SKILL LEARNT BY DOING, not by asking for complete code samples; if the latter is all you want to do then I suggest you give up programming and start doing something a lot easier.

11. ### mangupNew Member

Joined:
Jan 27, 2009
Messages:
10
0
Trophy Points:
0
thanks sir..
but i am still struggling to accomplish this. don't know how to do this. I think , Its too much difficult for me ....
So ...lets see what happens...
I will try to ask to my frens ....if they know....but i don't think that they can also do it.....so I tried the forum....Any way, I now know that this is not the place for me....If i will know the exact answer , I will post ...thanks again....for this much help....

12. ### xpi0t0sMentor

Joined:
Aug 6, 2004
Messages:
3,009
203
Trophy Points:
63
Occupation:
Senior Support Engineer
Location:
England
Fair enough, but if you look at my questions they are all designed to help you solve this problem. You could try looking at each one I've asked and try answering it.

If you just want someone to give the answer so you don't have to solve it yourself then yes this probably is the wrong place for you. Go4Expert is not a free homework service.

13. ### mangupNew Member

Joined:
Jan 27, 2009
Messages:
10
0
Trophy Points:
0
dear sir..
thanks for the inspiration. I understand all the solved problems that u have posted here. And I can even do such problem my self. But I am hanging -up in this problem because I am not getting any idea about "if I assign 16 bit address in three register pairs, then there is no any register to assign the loop counter. So if I directly load the accumulator from HL, then how to load the remaining address of HL pair in the accumulator and how to increment the same. I think there is no any instruction as INXA to increment accumulator." So this is my problem. If i be guided about this, then I can find the solution. So i m looking in the forum.

thanking you...
mangup.....

Joined:
Aug 6, 2004
Messages:
3,009