title: Assembly program that writes an array to a disk file
body: <p>I'm trying to write an doubleword array to a disk file using <code>CreateOutputFile</code>, <code>WriteToFile</code> and <code>CloseFile</code> Irvine32 procedures. Here is my code.</p>
  
  <pre><code>INCLUDE Irvine32.inc
  
  .data
  
       count = 45 
       BUFFER_SIZE = 188
       filename BYTE "Fibonacci.txt",0
       fileHandle DWORD ?
       array DWORD 47 DUP(?)
       num1 = 1
       num2 = 1
       temp1 DWORD ?
       temp2 DWORD ?
  .code
  
       main PROC
       mov edx,OFFSET filename
       call CreateOutputFile
  
       mov fileHandle,eax
       mov esi,0
       mov array[esi],num1
       mov eax,array[esi]
       mov temp1,eax
       add esi,4 
       mov array[esi],num2
       mov eax,array[esi]
       mov temp2,eax
       add esi,4
       mov ecx, count
  
  L1:
  
       mov eax,0
       mov ebx,0
       mov eax,temp1
       mov ebx,temp2
       add eax,ebx
       mov array[esi],eax
       mov temp1,ebx
       mov temp2,eax
       add esi,4
       loop L1
  
       mov eax,fileHandle
       mov edx,OFFSET array
       mov ecx,BUFFER_SIZE
       call WriteToFile
  
       mov eax,fileHandle
       call CloseFile
       exit
  main ENDP
  
  END main
  </code></pre>
  
  <p>After I debugging it every time, a text file is created successfully, but it turns to be some unrecognizable codes in the text file. I think it should have been the array shown in hexadecimal.</p>
  
  <p>I really don't know where I make mistakes. Please help me! Thanks!</p>