(Gordon Burditt) wrote:
>> 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.
Be careful: this applies only to a certain version of a certain compiler
suite on a certain machine architecture.
E.g. when compiling on an x86_64 architecture, I find that it p***** the
first 6 arguments in registers rdi, rsi, rdx, rcx(*), r8, and r9 (or
their 32-bit counterparts). The rest is passed on the stack.
(*) The fourth argument of a system call is passed in r10 instead of rcx!
BTW As a caller, you don't have to be aware of a varargs function, e.g.
printf: just pass the arguments as you would for a fixed-argument
function.
--
These are my personal views and not those of Fujitsu Siemens Computers!
Josef Möllers (Pinguinpfleger bei FSC)
If failure had no penalty success would not be a prize (T. Pratchett)
Company Details: http://www.fujitsu-siemens.com/imprint.html


|