>I have tried how simple it is to use
>system calls in Linux from assembler.
>Setting parameters in the registers
>eax/edx and then "int 0x80".
You are not calling a library. You are calling the kernel.
There's a difference.
>I would like to know it there
>is a similar, easy way of calling
>other libraries (specially X windows).
>
>It should be as simple as giving
>the function name in ASCII ! :)
Look at how the C compiler calls C functions. Write a simple
function that does some calls, gcc -S foo.c, and examine foo.s .
Generally, you push a bunch of arguments on to the stack, use a
call instruction to call the function, and adjust the stack to
remove the stuff you pushed on. You need to make the target symbol
an external symbol (e.g. .globl). This should work for both
static-linked libraries and dynamic-linked libraries, but not
dlopen()ed libraries.
And no, you don't use the function name in ASCII, and you can't
use the above method to call a variable-named function based on
an ASCII string.
For example, call.c:
int a()
{
foo(1, 2, 3, 4);
bar(4, 3, 2, 1);
}
Compiles into this (this is on FreeBSD, not Linux, but I believe
the linkages are essentially the same):
.file "call.c"
.text
.p2align 2,,3
...globl a
.type a, @[EMAIL PROTECTED]
%ebp
subl $8, %esp
pushl $4
pushl $3
pushl $2
pushl $1
call foo
addl $16, %esp
pushl $1
pushl $2
pushl $3
pushl $4
call bar
addl $16, %esp
leave
ret
.size a, .-a
.ident "GCC: (GNU) 3.4.6 [FreeBSD] 20060305"


|