title: Floating-point division on AT&T
body: <p>I have a program and there I should calculate the average value
  For that, I'll need to divide sum to n
  But they are integers and I want the result in floating-point
  How can I do it in at&amp;t syntax</p>
  
  <p>Let's say</p>
  
  <pre><code>.data
      Sum: .quad 2212
      N:      .quad 20
  </code></pre>
  
  <p>Now how should I declare avg and do the calculation</p>
  
  <pre><code>         .global _start
       .data
      message: .string "Elements of the list: \n"
      message1: .string "Sum of elements in the list= %d \n"
      message2: .string "Average of elements in the list= %lf \n"
      message3: .string "Key %d is found at location %d in the list\n"
      message4: .string "Key occurs %d times in the list \n"
      formatd: .string "%ld\n"
      buf: .skip 1024
      a: .float 5.0
      b: .float 2.0
      sum: .quad 0
      avg: .double 0
      key: .quad 32
      N: .quad 20
      count: .quad 0
      list:   .quad 12
              .quad 23
              .quad 32
              .quad 84
              .quad 121
              .quad 34
              .quad 23
              .quad 32
              .quad 93
              .quad 22
              .quad 56
              .quad 32
              .quad 949
              .quad 123
              .quad 99
              .quad 23
              .quad 32
              .quad 289
              .quad 99
              .quad 34
  </code></pre>
  
  <p>this is an array and i am traversing through it and finding the sum and average also i am searching for the key</p>
  
  <pre><code>       .text
      _start:
      movq $1, %rax           
      movq $1, %rdi
      movq $message, %rsi
      movq $24, %rdx
      syscall
  
      xorq %rcx, %rcx
      loop:
      pushq %rax
      pushq %rbx
      pushq %rcx
      movq $0, %rax
      movq $formatd, %rdi  
      movq $list, %rbx
      movq (%rbx,%rcx,8), %rsi
      addq %rsi, sum
      call printf
      popq  %rcx
      popq  %rbx
      popq  %rax
  
      inc %rcx
      cmp $20,%rcx
      jl loop
  
  
  
      pushq %rax
      pushq %rbx
      pushq %rcx
      movq $0, %rax
      movq $message1, %rdi  
      movq sum, %rsi
      call printf
      popq  %rcx
      popq  %rbx
      popq  %rax
  </code></pre>
  
  <p>up to here i am calculating the sum and displaying each element</p>
  
  <pre><code>    #here i want to find avg
      #
  
      pushq %rax
      pushq %rbx
      pushq %rcx
      movq $0, %rax
      movq $message2, %rdi  
      movq  avg, %rsi
      call printf
      popq  %rcx
      popq  %rbx
      popq  %rax
  </code></pre>
  
  <p>here i want to find the average and display it</p>