title: Printing an entire array on a single line using printf asm nasm
body: <p>I am using NASM for compiling my ASM program and I am having trouble figuring out how to print an entire array on a single line (without necessarily knowing how big the array is) using a loop.  Whenever I create a loop with printf it prints the values on multiple lines instead of one line.  Any idea how to make printf print multiple values of an array on a single line using a loop? I get values 1-9 but all on a different line instead of the same line. This is to be done without using external libraries other than: the printf c library.  Any help would be most appreciated.  The code I have is below.</p>
  
  <pre><code>  extern    printf  
  
   SECTION .data              ; Data section, initialized variables
  
  array: dd 1, 2, 3, 4, 5, 6, 7, 8, 9, 0; this is a test array for testing purposes
  
  arrayLen: dd 9  ; length of array 
  
  aoutput: db "%d", 10, 0 ; output format
  
  SECTION .text               ; Code section.
  
  global main             ; the standard gcc entry point
  
  main:                   ; the program label for the entry point
      push    ebp         ; set up stack frame
      mov     ebp,esp
  
      mov ecx, [arrayLen] ; loop counter set up
      mov esi, 0      ; counter to increment set up for looping through array
  .loop:
  
      push ecx                                    ; make sure to put ecx (counter) on stack so we don't lose it when calling printf)
      push dword [array + esi]                    ; put the value of the array at this (esi) index on the stack to be used by printf
      push dword aoutput                          ; put the array output format on the stack for printf to use
      call printf                                 ; call the printf command
      add esp, 8                                  ; add 4 bytes * 2
      pop ecx                                     ; get ecx back
  
      add esi, 4
      loop .loop
  
      mov     esp, ebp    ; takedown stack frame
      pop     ebp         ; same as "leave" op
  
      mov     eax,0       ; normal, no error, return value
      ret                 ; return
  </code></pre>