simple read char app return wrong value?



Hi group!

so i decided to go with nasm and linux. after reading some portion of PGU i decided to write an app to read a character from keyboard and exit. so here is the code:

; readc.asm - read a character from standard input and exit.
section .text

global _start

_start:
mov ebx, 0h ; standard input
mov ecx, buf ; input array
mov edx, 01h ; 1 character to read
mov eax, 03h ; syatem call number for read
int 080h

mov ebx, eax ; byte read
mov eax, 01h ; syatem call number for exit
int 080h

section .bss

buf resb 01h ; array for input

is everything correct here?
but when i run this everything is okay when i enter single character or i press crtl-d for end of file, but when i enter several characters after my app exits bash somehow reads them and complains. here is some examples.

1.
# ./readc
c
#
#

2.
# ./readc
ctrl-d
#

3.
# ./readc
skjalskj
# kjalskj
bash: kjalskj: command not found
#

what is happened here? how can avoid input to readc from being read by bash? also the exit code for example 1 is 1 and for example 2 is 0 but for example 3 it is 127. does anyone know what 127 means? 1 and 0 seem to be correct as said in man 2 read.


also Duntemann's book mentions setting up "stack frame". is that only for c library or do i have to do that for above program also?

thanks to all.
.



Relevant Pages

  • Re: Simple multiplication program error (beginner help)
    ... mov ax,data ... sub al, 30h; or sub al, 48 ... Here's where we could check to make sure we've got a valid decimal digit. ... We obviously can't print "81" as a single character! ...
    (comp.lang.asm.x86)
  • Re: Which assembler can handle the BIG stuff ?
    ... for counting character occurence in a memory image... ... mov esi,... ... plus just a handful code bytes. ... Takes (w/o filter) 8..10 cycles per iteration, ...
    (alt.lang.asm)
  • Re: simple read char app return wrong value?
    ... mov ebx, 0h; standard input ... 01h; 1 character to read ... buf resb 01h; array for input ... after my app exits bash somehow reads them and complains. ...
    (alt.lang.asm)
  • Re: cpuid
    ... Each bytes represents one character of text, using some character encoding, usually ASCII. ... So to print a 32 bit register in binary, all you have to do is take the bits one by one, check whether each bit is a 1 or a 0, and put either '1' or '0' into a buffer accordingly, and then print the buffer. ... mov %cl, buf# store one char in the buffer ... int $0x80 ...
    (comp.lang.asm.x86)
  • Re: simple read char app return wrong value?
    ... readc.asm - read a character from standard input and exit. ... mov ebx, 0h; standard input ... data was immediately available for reading. ...
    (alt.lang.asm)