I am taking an introduction to Assembly Language Course and I am stuck on a project.  This same problem was posted on this forum in 2004 but it looks like it was never resolved.

We are using the text book Kip R. Irvine Assembly Language for x86 Processors, Sixth Edition.

Here is what we are supposed to do:

"Write a procedure name Get_frequencies that constructs a character frequency table.  Input to
the procedure should be a pointer to a string and a pointer to an array for 256 doublewords
initialized to all zeros.  Each array position is indexed by its corresponding ASCII Code.  When
the procedure returns, each entry in the array contains a count of how many times the
corresponding character occurred in the string.  For example,
freqTable DWORD 256 DUP(0)
INVOKE Get_frequencies, ADDR target, ADDR freqTable"

I'm not asking anyone to write the program for me.  I just want to see if someone can point me in the right direction. 

My understanding of the basic idea, step by step:
1. Load character array
2. Look at first character's hex value (e.g. A equals 41h)
3. Go to address in table equal to the hex value
4. Increment the value in that address by 1
5. Repeat steps 2 through 4 until end of character array

Here is what I have so far:

testString         BYTE "ABBCCC",0 ;sample string we are going to get the character frequency count for
freqTable DWORD 256 DUP(0)  ;array for frequency table

Get_frequencies PROC uses edi tString, fTable
mov eax,0
        mov edi,fTable 
mov ecx,256    ;set counter to number of elements in fTable (freqTable)
rep stosd        ;set each value in fTable to 0
mov edi,fTable
mov edx,tString
        mov ecx,SIZEOF tString ;set counter to number of elements in tString
mov al,  ;move the value of the character array into al
inc edx    ;increment edx to the next element of the character array
inc dword ptr ;increment the value stored in the fTable address of character's hex equivalent by 1
        Loop L1
Get_frequencies ENDP

main proc
INVOKE Get_frequencies, ADDR testString, ADDR freqTable
main endp

Posted on 2010-10-31 16:05:04 by Chris12
Hi Chris :)
Be aware that sizeof(string) will include the zeroterminator!
Aside from this minor problem, you should be pretty right.
Posted on 2010-10-31 17:19:47 by Homer

Thank you for taking the time to look and the response!
Posted on 2010-10-31 21:21:19 by Chris12