1

How can i write the output to the screen?

 SECTION .data
 x:
   dd 1
   dd 5
   dd 2
   dd 18
 sum:
   dd 0
 SECTION .text
  mov eax,4 ; EAX will serve as a counter
  mov ebx,0 ; EBX will store the sum
  mov ecx, x ; ECX will point to the current
 top:
  add ebx, [ecx]
  add ecx,4 ; move pointer to next element
  dec eax ; decrement counter
  jnz top ; if counter not 0, then loop again
 done:
  mov [sum],ebx ; done, store result in "sum"
Ed Heal
  • 59,252
  • 17
  • 87
  • 127
Figen Güngör
  • 12,169
  • 14
  • 66
  • 108
  • 1
    Possible duplicate of: http://stackoverflow.com/questions/8194141/how-to-print-a-number-in-assembly-nasm – Asblarf Dec 18 '12 at 23:41
  • Some discussion here: http://forum.nasm.us/index.php?topic=1514.0 – Frank Kotler Dec 19 '12 at 00:46
  • The links that you have given have information for 32 bit system but I use 64 bit system so can you tell me how I can compile those for 64 bit? – Figen Güngör Dec 19 '12 at 10:21
  • I'm still running 32-bit hardware, so I'd be guessing. I would have guessed(!) that your `mov ecx, x` would cause ld (not Nasm) to barf with a "relocation truncated to fit". Perhaps not. Shortly after upgrading to 64-bit, I might have an answer for ya. :) – Frank Kotler Dec 19 '12 at 17:01
  • Compiling for x86_64: `nasm -f elf64 yourapp.asm` and then use the usual `ld yourapp.o -o yourapp` linker command. – Asblarf Dec 19 '12 at 18:02
  • I have solved my problem, thank you. All i needed was to install multilib to run 32-bit code under 64-bit. – Figen Güngör Dec 19 '12 at 18:53

0 Answers0