title: Assembly NASM x86 - Putting char into array
body: <p>I need to make a program that  open a file, read it character by character and save it into an array in Assembly NASM x86. Currently, the program is able to open a file using stdin and read the character by using getchar(). However, i am stuck on the saving the char into an array and need help on this part. </p>
  
  <p>Thank you </p>
  
  <pre><code>; Run it this way:
  ; test &lt; (input file)
  ; Build using these commands:
  ; nasm -f elf -g -F stabs test.asm
  ; gcc –m32 -o test.o  test
  ;
  
  SECTION .bss ; Section containing uninitialized data
  
      TextLenght EQU 1024 ; Define length of a line of  text data
      Text resb TextLenght ; Define array
  
  SECTION .data ; Section containing initialised data
  
  fileFmt: db "%c",0
  
  SECTION .text ; Section containing code
  
  extern putchar 
  extern getchar
  extern printf
  
  global main; Linker needs this to find the entry point!
  
  main :
  
  start:
      nop ; This no-op keeps gdb happy...
      mov eax, 0
      mov edx, 0
      mov ecx, 0
      mov ebx, 0
  
  ; Read a buffer full of text from stdin:
  read:
      call getchar ; call getchar to get input from stdin, char is save in eax 
      cmp al, -1
      jle Done     ; if return -1, we at EOF
  
      cmp eax, 97  ; get rid of 'enter' char
      jl read
  
      ;mov Text, eax; try to save char in eax into array, don;t work
  
      push eax      ;push eax to print  
      push fileFmt
      call printf
      add esp, 8   ; clear the stack
      jmp read
  
  Done:
      mov eax,1 ; Code for Exit Syscall
      mov ebx,0 ; Return a code of zero
      int 80H ; Make sys_exit kernel call 
  </code></pre>