Go4Expert

Go4Expert (http://www.go4expert.com/)
-   Assembly Language Programming (ALP) Forum (http://www.go4expert.com/forums/assembly-language-programming-forum/)
-   -   Counting number of occurances of a letter in a sentence (http://www.go4expert.com/forums/counting-occurances-letter-sentence-t14937/)

stuckInRainbows 3Nov2008 01:47

Counting number of occurances of a letter in a sentence
 
I'm working on an 8085 program to read sentences typed in by a user and then count the number of occurrences of a specific letter requested by the user.

Program begins with a prompt for a sentence- user can end the sentence by either hitting the return key or typing a period. The program should then ask for a letter. It should then count the number of occurrences of that letter in the sentence and print it to the
screen. User may type either a small or a capital letter. In either of the two cases, occurrences of both the small and the capital letter should be printed.

How does one approach this?

xpi0t0s 3Nov2008 04:12

Re: Counting number of occurances of a letter in a sentence
 
Well, you've got the outline for the program already. You need in general two things for a computer program: (1) some storage; (2) some processing. What kind of each do you think you'll need? Have you done a dry run on paper to see how in detail you might do it?

stuckInRainbows 3Nov2008 06:19

Re: Counting number of occurances of a letter in a sentence
 
Well I want to count the number of letterers in the sentence and then compare each against the input, and eventually output the result.

-define the location of the start of the sentence
-define the location for the count of characters in the sentence.
-define the location to put the letter to be searched for.
-define the location of the result

So I need to input the letter to be searched for, or load the memory location of the first letter of the sentence in a register

Then I guess I should create a loop to count the number of letters, stop the count at the period or carriage return then save the result.

Afterward I need a loop to compare the letter i'm looking for (upper and lowercase) against a letter in the sentence, while simultaneously incrementing two counters.

And i'll also have to take into account what to do if a condition is not met.

I'm just fuzzy on writing the actual code to accomplish these, especially the loops.

xpi0t0s 3Nov2008 13:10

Re: Counting number of occurances of a letter in a sentence
 
Seems a little overcomplicated, you only need one loop that terminates when you get to the end of the sentence, and during the loop you can count the occurrences of the letter and the number of letters in the sentence, if you need that.

The loop variable itself could either be a pointer to the current memory location being considered, or it could be an offset. In C this could be written as
Code:

int i=0;
for(;;)
{
  // look at str[i], which is *(str+i)
}

or
Code:

char *i=str;
for(;;)
{
  // look at *str
}

Do you have an example of a loop in the course notes you've got so far? Can you adapt that loop to do what you want?

If you can't see how, then post what you've got (8085 code isn't one I've met) and we can suggest what you might change to get what you want.


All times are GMT +5.5. The time now is 12:37.