Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Assembly x86 > Re: Calling lib...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 22 Topic 4620 of 4729
Post > Topic >>

Re: Calling libraries from assembler.

by (Gordon Burditt) <spamtrap@[EMAIL PROTECTED] > Apr 18, 2008 at 11:22 PM

>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"
 




 22 Posts in Topic:
Calling libraries from assembler.
SoLo2 <spamtrap@[EMAI  2008-04-18 18:43:51 
Re: Calling libraries from assembler.
(Gordon Burditt) <spam  2008-04-18 23:22:54 
Re: Calling libraries from assembler.
Josef Moellers <spamt  2008-04-21 08:50:12 
Re: Calling libraries from assembler.
Frank Kotler <spamtra  2008-04-19 08:29:23 
Re: Calling libraries from assembler.
SoLo2 <spamtrap@[EMAI  2008-04-19 18:41:12 
Re: Calling libraries from assembler.
Terence <spamtrap@[EM  2008-04-20 15:33:52 
Re: Calling libraries from assembler.
Frank Kotler <spamtra  2008-04-21 00:33:57 
Re: Calling libraries from assembler.
santosh <spamtrap@[EM  2008-04-21 07:31:41 
Re: Calling libraries from assembler.
Robert Redelmeier <red  2008-04-21 02:04:02 
Re: Calling libraries from assembler.
Frank Kotler <spamtra  2008-04-21 05:25:02 
Re: Calling libraries from assembler.
"James Van Buskirk&q  2008-04-21 11:46:30 
Re: Calling libraries from assembler.
"robertwessel2@[EMAI  2008-04-20 19:20:38 
Re: Calling libraries from assembler.
Terence <spamtrap@[EM  2008-04-20 21:12:02 
Re: Calling libraries from assembler.
Frank Kotler <spamtra  2008-04-21 05:49:00 
Re: Calling libraries from assembler.
Robert Redelmeier <red  2008-04-21 14:25:53 
Re: Calling libraries from assembler.
Josef Moellers <spamt  2008-04-22 09:44:41 
Re: Calling libraries from assembler.
Josef Moellers <spamt  2008-04-22 09:42:38 
Re: Calling libraries from assembler.
Terence <spamtrap@[EM  2008-04-22 15:18:31 
Re: Calling libraries from assembler.
David Thompson <spamt  2008-05-05 04:10:33 
Re: Calling libraries from assembler.
"H. Peter Anvin"  2008-05-05 11:06:21 
Re: Calling libraries from assembler.
(Scott Lurndal) <spamt  2008-05-05 23:41:16 
Re: Calling libraries from assembler.
"H. Peter Anvin"  2008-05-12 23:44:56 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Jul 26 2:09:11 CDT 2008.