flat assembler
Message board for the users of flat assembler.

Index > Linux > fasm and using Linux' resources

Author
Thread Post new topic Reply to topic
Ton



Joined: 06 Jan 2005
Posts: 22
Ton
Okay I new to assembly, browsed a while, finding my way, and have some questions:

1) If I invoke an ELF program, where can I find the argc, and argv (to speak in C).
2) Are all registers available to me? What is common practice?
3) Where can I find examples on how to invoke system calls. Primarily to have access to stdin, stdout, stderr, and file access.
4) Suppose I want to let talk two fasm programs, what is preferred?
(shmem, pipes). Or a Perl program to a fasm compiled daemon.

(3) and (4) can be regarded as a tiny libc. Is this already done?

In one line: how lays a fasm compiled program in Linux?

Thanks a lot.

Best Regards,
Ton
Post 06 Jan 2005, 20:09
View user's profile Send private message Reply with quote
Dryobates



Joined: 13 Jul 2003
Posts: 46
Location: Poland
Dryobates
Ton wrote:
Okay I new to assembly, browsed a while, finding my way, and have some questions:

1) If I invoke an ELF program, where can I find the argc, and argv (to speak in C).

argc - first on stack
argv - next elements on stack until NULL apear.
Quote:
2) Are all registers available to me? What is common practice?

I don't know how it is on Linux (I use FreeBSD) but probably all generall registers are for your usage.
Quote:
3) Where can I find examples on how to invoke system calls. Primarily to have access to stdin, stdout, stderr, and file access.

eax - syscall number
ebx, ecx, edx, esi, edi, ebp - parameters (first in ebx, second in ecx etc.)
int 80h
stdin = 0
stdout = 1
stderr = 2
stdcall:
3 - read
4 - write
5 - open
6 - close
I'm sure that there's something like syscalls.master on linux too. Just search for it.

Quote:
4) Suppose I want to let talk two fasm programs, what is preferred?
(shmem, pipes). Or a Perl program to a fasm compiled daemon.

If in one way then pipes. If two ways I would use sockets.undefined

_________________
There's one more bug... Smile
Image
Post 06 Jan 2005, 20:57
View user's profile Send private message AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
gunblade



Joined: 19 Feb 2004
Posts: 209
gunblade
Hey,

What Ton said was right Smile

For question 3, read the file /usr/include/asm/unistd.h (default location)
it has a list of every syscall you can make, and next to it, a number which you put into eax, when calling int 0x80 (put simply Very Happy )
(These arent api calls.. if you actually want api calls, you'll have to call the functions in glibc.. then link your program with ld.. but its really uneccessary, the interupt call method calls the kernel directly, (smaller file size, no requirement for an external library, faster))

For question 4, you could always use TCP/UDP/RAW sockets.. make one listen on the localhost, and make the other connect.. or if you want something more direct, use threads, or pipes.

good luck, Cool
gunblade
Post 20 Jan 2005, 15:22
View user's profile Send private message Reply with quote
Ton



Joined: 06 Jan 2005
Posts: 22
Ton
I aware of TCP/UDP, sockets, and pipe. I will look into this with fasm. I think it is also time to look into threads. Smile

I think it is a bad idea to link libc, not I realize I have direct access to the kernel. One might better link in the dld, and dynamically load what is wanted. For now this is above my capabilities.

Thanks for the answers. I can enjoy this new knowledge.

Ton
Post 20 Jan 2005, 18:34
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar.

Powered by rwasa.