Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Assembly Language Programming (ALP) Forum (http://www.go4expert.com/forums/assembly-language-programming-forum/)
-   -   ALP for searching (http://www.go4expert.com/forums/alp-for-searching-t15960/)

mangup 27Jan2009 17:14

ALP for searching
 
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

mangup 28Jan2009 12:52

Re: ALP for searching
 
hello all..
please help ....u are the expert....and i am a learner........

xpi0t0s 28Jan2009 13:35

Re: ALP for searching
 
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?

mangup 29Jan2009 10:58

Re: ALP for searching
 
Quote:

Originally Posted by xpi0t0s (Post 42091)
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?



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.
Please help...

mangup 30Jan2009 13:41

Re: ALP for searching
 
Quote:

Originally Posted by mangup (Post 42138)
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
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.
Please help.....

can any one help me please........

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

xpi0t0s 30Jan2009 14:42

Re: ALP for searching
 
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
read memory M at address ptr
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/onl.../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)

mangup 1Feb2009 10:01

Re: ALP for searching
 
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....
thanks in advance....

xpi0t0s 1Feb2009 14:54

Re: ALP for searching
 
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)?

mangup 2Mar2009 10:59

Re: ALP for searching
 
Quote:

Originally Posted by xpi0t0s (Post 42258)
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)?


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.....
thanks in advance............

xpi0t0s 2Mar2009 17:14

Re: ALP for searching
 
> 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.


All times are GMT +5.5. The time now is 01:47.