title: Sum 10 numbers and print result in NASM
body: <p>I have written following assembly code for adding 10 numbers.I am able to compile it and execute it but I am getting wrong result.
  I just wanted to know how do I print the value of <strong>total</strong> on scree.</p>
  
  <pre><code>section .data
  num1: dw 10, 20, 30, 40, 50, 10, 20, 30, 40, 50
  total: dw 0
  msg :  db "sum=%d",10,0
  
  section .text
      extern _printf
      global _main
  _main:
      push ebp
      mov ebp,esp
      mov ebx,num1 ;point bx to first number
      mov ecx,10      ;load count of numbers in ecx
      mov eax,0       ;initialize sum to zero
  loop:
      add eax,[ebx]
      add ebx,2
      sub ecx,1
      jnz loop
      mov [total],eax
  
      push total
      push msg
      call _printf
  
      pop ebp
      mov esp,ebp
      ret
  </code></pre>
  
  <p><strong>solution</strong></p>
  
  <pre><code>section .data
  num1: dd 10, 20, 30, 40, 50, 10, 20, 30, 40, 50,300
  total: dd 0
  msg :  dd "sum=%d",10,0
  
      section .text
          extern _printf
          global _main
      _main:
          push ebp
          mov ebp,esp
          mov ebx,num1 ;point bx to first number
          mov ecx,11     ;load count of numbers in ecx
          mov eax,0       ;initialize sum to zero
      loop:
          add eax,[ebx]
          add ebx,4
          sub ecx,1
          jnz loop
          mov  [total],eax
          push dword [total]
  
          push msg
          call _printf
          mov esp,ebp
          pop ebp
  
          ret
  </code></pre>