From: Jack Dennon <jdennon@seasurf.net>
To: rodrigobaroni@yahoo.com.br
Cc: linux-assembly@vger.kernel.org
Subject: Re: int 16 ?
Date: Sat, 15 Feb 2003 13:36:34 -0800 [thread overview]
Message-ID: <3E4EB2E2.7DA23F1@seasurf.net> (raw)
In-Reply-To: 20030215181726.56630.qmail@web11101.mail.yahoo.com
[-- Attachment #1: Type: text/plain, Size: 1 bytes --]
[-- Attachment #2: sysread.txt --]
[-- Type: text/plain, Size: 1984 bytes --]
Here is an assembly language routine to call
the system read function via int 0x80:
-------------------------------------------------
#/* void asm_sysread(
# int filedescriptor,
# char *buffer,
# int buffer_length)
#
# invoke syscall __NR_read = 3
# */
.file "asm_sysread.s"
.text
.global asm_sysread
.align 4
SIZE = 16
BUFF = 12
FILE = 8
asm_sysread:
pushl %ebp
movl %esp,%ebp
movl FILE(%ebp),%ebx #file descriptor
movl BUFF(%ebp),%ecx #buffer fwa
movl SIZE(%ebp),%edx #buffer size
movl $3,%eax # __NR_read
int $0x80
cmpl $-126,%eax #check return code
jbe .L1 #if no error
#
negl %eax #complement eax
movl %eax,%ecx
movl $-1,%eax #on error, return -1
.L1:
movl %ebp,%esp
popl %ebp
ret
.type asm_sysread,@function
.size asm_sysread,.-asm_sysread
--------------------------------------------------------
And here is a C program to call the above function:
---------------------------------------------------------
/* sysread.c: test the read system call
*/
#include <stdio.h>
#define BUFSIZE 16
extern void asm_sysread(int fd, char *buff, int bufsize);
main()
{
int i;
int fd = 0; /* stdin */
char buff[BUFSIZE]; /* input buffer */
for (i = 0; i < BUFSIZE; i++)
buff[i] = '\0';
asm_sysread(fd,buff,1); /* read one char */
for (i = 0; i < BUFSIZE; i++)
printf("%02x ",buff[i]);
printf("\n");
}
----------------------------------------------------------
If you put these in separate files named, for example,
asm_sysread.s and sysread.c, then you can compile,
assemble, and link with the command
gcc -o sysread sysread.c asm_sysread.s
When called with the command
sysread
it somewhat works, but it does not do what we want;
the routine asm_sysread does not return after just
one key has been pressed, it returns only after we
hit [Enter]. So the question is, how do we modify
this code to do exactly what we want: fetch the
next keyboard entry and return immediately with it?
Having stalled out on this, I use curses.
next prev parent reply other threads:[~2003-02-15 21:36 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-02-14 5:23 int 16 ? dAvId KeDrOsKy
2003-02-14 8:07 ` Rudolf Marek
2003-02-14 20:10 ` Jack Dennon
2003-02-15 18:17 ` Rodrigo F. Baroni
2003-02-15 21:36 ` Jack Dennon [this message]
2003-02-16 6:29 ` Pea Jay
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=3E4EB2E2.7DA23F1@seasurf.net \
--to=jdennon@seasurf.net \
--cc=linux-assembly@vger.kernel.org \
--cc=rodrigobaroni@yahoo.com.br \
/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.