开发者

Howto define a buffer for IA32 sys_read call

I'm having trouble using the sys_read system call from an IA32 Assembler program on Linux. What is the correct way to defin开发者_运维知识库e a buffer?

This is the relevant part of what I have so far:

    movl $(SYS_read), %eax
    movl $(STDIN), %ebx   
    movl BUFFADDR, %ecx  
    movl 2, %edx
    int $0x80   
    movl $eax, $ebp // number of read bytes

where SYS_read and STDIN are defined at the beginning. Where is the correct place to set up the buffer? (BUFFADDR in the pasted code).

Are there any I/O libraries for IA32 Assembler? Or is that the easiest way to read a value from Stdin? I couldn't find a working example performing such an operation, I hope someone can help.


A "BUFFADDR" is just the address of some region of memory that is large enough to hold the data being read (so two bytes in your case). There are basically two places you can get memory from: the current stack or the heap. For a small buffer you can probably allocate off the stack (just bump the stack pointer to reserve some space), for the heap, see the 'brk' system call.

Here's some details about stack frames (includes stuff about argument passing that you don't need yet, though): http://www.cs.mun.ca/~rod/winter2004/cs3724/notes/frame.html

If you want IO libraries, then pretty much by definition you don't want assembler. The IO library you're looking for is the C library.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜