* [Fwd: Re: Reading user input related question]
@ 2007-02-22 3:30 Joshua Roys
0 siblings, 0 replies; only message in thread
From: Joshua Roys @ 2007-02-22 3:30 UTC (permalink / raw)
To: linux-assembly
[-- Attachment #1: Type: text/plain, Size: 388 bytes --]
Oops. Forgot to 'reply all.' Here's a copy for the list.
Charles O'Neil wrote:
> Hi! I am a newbie to gas and I want to know whether it is possible to
> read input
> from keyboard(after the enter key is pressed) using read syscall but
> not using c function? if yes how this can be accomplished?
>
> Thanks.
Yep. I use nasm, but here's what I've got.
You're welcome!
Joshua Roys
[-- Attachment #2: test1.asm --]
[-- Type: text/plain, Size: 927 bytes --]
section .bss
c resb 1
section .text
global _start
_start:
read_again:
mov eax, 3 ; sys_read for read() in eax.
mov ebx, 0 ; int fd in ebx. STDIN_FILENO = 0 in unistd.h
mov ecx, c ; void * buf in ecx
mov edx, 1 ; size_t count in edx
int 80h ; syscall
test eax, eax
jz eof ; jump if zero (EOF)
js error ; jump if signed
mov edx, eax ; number of bytes read returned in eax, save in edx (should be 1)
mov eax, 4 ; sys_write for write() in eax.
mov ebx, 1 ; int fd in ebx. STDOUT_FILENO = 1 in unistd.h
; const void *buf in ecx. still set from above.
; size_t count in edx.
int 80h ; syscall
jmp read_again
eof: ; we know eax is 0 (EOF), which is the success exit value.. so just use `error' to exit
error:
mov ebx, eax ; errno returned in eax, save in ebx
mov eax, 1 ; sys_exit for exit()
; errno in ebx
int 80h ; syscall
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2007-02-22 3:30 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-02-22 3:30 [Fwd: Re: Reading user input related question] Joshua Roys
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).