simple read char app return wrong value?
- From: naunetr <wildgoosechase@xxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 05 Dec 2007 23:45:08 +0530
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.
.
- Follow-Ups:
- Re: simple read char app return wrong value?
- From: Evenbit
- Re: simple read char app return wrong value?
- From: Frank Kotler
- Re: simple read char app return wrong value?
- From: Charles Crayne
- Re: simple read char app return wrong value?
- Prev by Date: Re: Sudoku
- Next by Date: Re: keyboard/mouse programming
- Previous by thread: Need Helping Writing ASM app to read CPUID Features
- Next by thread: Re: simple read char app return wrong value?
- Index(es):
Relevant Pages
|
|