Question: Write a procedure named Get_frequencies that constructs a character frequency table. Input to the procedure should be a pointer to a string and a pointer

Write a procedure named 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 of 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,

.data target BYTE "AAEBDCFBBC",0 freqTable DWORD 256 DUP(0)

.code INVOKE Get_frequencies, ADDR target, ADDR freqTable Figure 9-6 shows a picture of the string and entries 41 (hexadecimal) through 4B in the frequency table. Position 41 contains the value 2 because the letter A (ASCII code 41h) occurred twice in the string. Similar counts are shown for other characters. Frequency tables are useful in data compression and other applications involving character processing. The Huffman encoding algorithm, for example, stores the most frequently occurring characters in fewer bits than other characters that occur less often.

FIGURE 9-6 Sample character frequency table. Target string: A A E B

FIGURE 9-6 Sample character frequency table. Target string: A A E B D C F B B C 0 ASCII code: 41 41 45 42 44 43 46 42 42 43 0 Frequency table: 2 3 2 1 Index: 41 42 43 14 15 0 0 0 0 0 44 45 46 47 48 49 4A 4B etc.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Implementing Programming Languages Questions!