Reading from STDIN and printing to STDOUT with nasm assembly?
<p>As the title suggest I seem to be having a hard time converting the below code to do the exact same thing, which is to read from stdin and stdout. My professor wants us to stop using int 80h and switch over to using gcc. I've had no problems with reading input with the below code however, switching over to gcc is where I start getting segmentation core dump errors.</p>

<pre><code>section .bss
   buf      resb 1                  ; 1000-byte buffer (in data section)

section .text
    global _start
_start:
loop1:   mov  edx, 1             ; max length
         mov  ecx, buf           ; buffer
         mov  ebx, 0             ; stdin
         mov  eax, 3             ; sys_read
         int  80h

         cmp  eax, 0             ; end loop if read &lt;= 0
         jle  lpend1

         mov  edx, eax           ; length
         mov  ecx, buf           ; buffer
         mov  ebx, 1             ; stdout
         mov  eax, 4             ; sys_write
         int  80h

         jmp  loop1              ; go back for more
lpend1: 
         mov    eax, 1
         mov    ebx, 0
         int    80h
</code></pre>

<p>My attempt at converting the above to perform the same task</p>

<pre><code>SECTION .data
    format: db "%c",0
SECTION .bss
    buff: resb 1
SECTION .text
extern printf
extern scanf
global main
main:

loop1:
    push buff       ;buff will hold the characters in the string/file
    push format     ;expect character for every buff
    call scanf      
    add esp, 8      ;clear stack

    cmp eax, 0      ;if eax is equal to 0 then EOF
    je lpend1       ;jump to end main func

    xor eax, eax        ;clear eax
    mov eax, buff       ;mov buff to eax register
    push eax        ;push eax onto the stack
    mov eax, format     ;mov the string format to eax
    push eax        ;push onto the stack
    call printf     ;call printf, prints to screen
    add esp, 8      ;clear the stack
    jmp loop1       ;jump back to top and repeat

lpend1:
    ret         ;end of main
</code></pre>