format ELF executable 3
entry start

segment readable executable

BYTES = 255            ;- number of byte read at time max a 255

start:
  nop

;- read a char from input
char_read:
  mov eax,3
  mov ebx,0           ;- 0 stdin, 1 stdout, 2 stderr
  mov ecx,chBuf
  mov edx,BYTES
  int 0x80

;- save number of byte read and check if EOF
save_and_eof:
  mov [inChRead],al    ;- save number of byte read cause return in eax
  mov ecx,eax          ;- make ecx a counter
  cmp eax,0x0          ;- if read syscall return EOF in eax then exit
  je  exit

;- cypher all byte read until counter ecx is zero
cypher:
  not [chBuf+ecx-1]
  dec cl
  cmp cl,0x0
  jne cypher

;- write cyphered byte read to output
char_write:
  mov eax,4
  mov ebx,1
  mov ecx,chBuf
  mov dl,[inChRead]
  int 0x80

  jmp char_read

;- exit from program
exit:
  mov eax,1             ; System call 'exit'
  xor ebx,ebx           ; 'xor ebx,ebx' saves time
  int 0x80

segment readable writeable

  ;chBuf db ?
  chBuf db BYTES dup(0)
  inChRead db 1

