title: Printing values of arrays in MASM assembly
body: <p>I'm new to writing assembly code and I'm having trouble printing out the values of my array using a loop. The code I have prints out the value of the counter and the not the values in the array, can someone please explain what I'm doing wrong, also how do I point to the top of the array? I have tried using different registers, but nothing seems to be working. My professor asks that I do it this way (if it seems inefficient):</p>
  
  <pre><code>           .386
             .model flat
  ExitProcess PROTO NEAR32 stdcall, dwExitCode:dword
  Include io.h
  cr         equ 0DH
  Lf         equ 0AH
             .stack 4096
             .data
  newline    byte CR, LF, 0
  whitespace byte 32,32,0     
  arr        dword 10 dup(?)
  n          dword 2
  string     byte  40 dup(?)
  prompt     byte "Please enter a value: ", 0
  origArr    byte "Original Array", 0
             .code
  _start:
             mov    ecx,n         ; number of values in the array
             lea    ebx,arr       ; address of the array
             sub    edi, edi
  top:       cmp    ecx, 0
             je     done
             output prompt
             input  string, 40
             atod   string
             mov    [arr+edi], ecx
             add    edi, 4
             loop   top
  done:      output origArr
             mov    ecx, n
             call   myproc
  
           INVOKE ExitProcess, 0
  
  PUBLIC  _start
  myproc proc near32
         .data
  val_str byte 11 dup(?), 0
         .code
          push eax
          push edi 
          push ecx
          sub edi,edi              ; index register
  top2:   mov eax, [ebx+edi]
          dtoa val_str, eax
          output val_str
          add edi,4                ; modify esi rather than ebx
          loop top2
          pop ecx 
          pop edi
          pop eax
          ret
  myproc endp
  
           END    
  </code></pre>
  
  <p>Any suggestions are appreciated.</p>