All of lore.kernel.org
 help / color / mirror / Atom feed
From: Joshua Roys <TheReader06@comcast.net>
To: linux-assembly@vger.kernel.org
Subject: [Fwd: Re: Reading user input related question]
Date: Wed, 21 Feb 2007 22:30:06 -0500	[thread overview]
Message-ID: <45DD0E3E.5030105@comcast.net> (raw)

[-- 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


                 reply	other threads:[~2007-02-22  3:30 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=45DD0E3E.5030105@comcast.net \
    --to=thereader06@comcast.net \
    --cc=linux-assembly@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.