title: Scan array in x86 assembly
body: <p>I am stuck with trying to scan and store an double word array in x86-64.
  I have looked all over and can't seem to find anything that I understand.
  My program should scan and print all the elements of a dword array.</p>
  
  <p>I have looked at many examples but I can't seem to use them - they give me compilation errors.
  Furthermore, I can't seem to use something like - movq %rsi, [array + 8]</p>
  
  <p>Here is my code:</p>
  
  <pre><code>.data
  .comm   arr, 800                # int arr[100];
  .comm   p, 8                    # int pointer;
  .comm   c, 8
  .comm   c2, 8
  .comm   c3, 8
  arr     dd 100 DUP(0)
  .text
  format1:
          .string "Enter integers followed by EOF\n"
  
  format2:
          .string "%ld"
  
  format3:
          .string "a is %ld\n"
  
  .globl main
  main:                                   # main()
          movq    $format1, %rdi          #   printf("Enter integers followed by E
          movq    $0, %rax                #
          call    printf                  #
          movq    $arr, %r8
          movq    $0, c
          movq    $0, c2
  
          whileloop:
          movq    $format2, %rdi          #   scanf("%ld",&amp;a);
          movq    $p, %rsi                #
          movq    %rsi, %r8
          movq    $0, %rax                #
          call    scanf                   #
          cmpq    $0, %rsi                #   if(arr[ptr] == 0)
          je      endwhileloop
          addq    $8, %r8
          addq    $1, c
          jmp     whileloop
          endwhileloop:
          movq    $format3, %rdi #   printf("a=%ld",a);
          movq    $p,%rsi       #
          movq    (%rsi),%rsi    #
          movq    $0, %rax       #
          call    printf         #
          ret
  </code></pre>
  
  <p>This isn't storing the array properly for a fact in 'arr'.
  Thanks!</p>