title: frequency table with ascii index and decimal value
body: <p>I write the code to computer each character in a string's frequency, and the array is index is from 0 to 255, which are ascii index and the value is the frequency that the character appear.</p>
  
  <p>I compare each character in the string and add it 1 in the array each time.</p>
  
  <p>But I cannot find the error that the count seem to be not right(too large)?</p>
  
  <p>The result should be <img src="https://i.stack.imgur.com/14dDB.png" alt="enter image description here"></p>
  
  <p>but my result's count is too large.</p>
  
  <p>The error comes in the L1 loop and I don't know why the loop will cause very large number.</p>
  
  <p>Please give me some guidance that what I do wrong.</p>
  
  <p>Thank for your reading.</p>
  
  <pre><code>INCLUDE Irvine32.inc
  
  .data
      testString BYTE "AAEBDCFBBC",0 
      freqTable DWORD 256 DUP(0)
      prompt BYTE 0Dh, 0Ah, 0
      prompt1 BYTE ": ", 0
  .code   
  
  
  Freq PROC uses edi,
          tString:PTR BYTE, 
          fTable:PTR DWORD
  
      mov eax,0
      CLD
  
      mov edi,fTable  
      mov ecx,256
      rep stosd;initialize fTable 0
  
  
      mov edi,fTable;reset edi position
      mov edx,tString
      mov ecx,SIZEOF tString;element number
      dec ecx;remove null character
  
      L1:
      mov al,[edx]  ;character value
      inc edx     ;index ++
      inc dword ptr[edi+eax] ;value ++
          Loop L1
      ret
  Freq ENDP
  
  
  main PROC
  main ENDP
      INVOKE Freq, ADDR testString, ADDR freqTable
      mov ecx, 256
      mov ebx, 0
      mov edi,OFFSET freqTable
      mov eax, 0
  
      L1:
          call WriteHex;index
          mov  edx,OFFSET prompt1
          call WriteString;": "
  
          mov ebx, [edi + eax]
          xchg eax,ebx
          call WriteInt
          xchg eax,ebx
          mov  edx,OFFSET prompt
          call WriteString;endline
          inc eax;index ++
          Loop L1
          ;ret
  END main
  </code></pre>