Mail Archives: djgpp/1999/04/05/15:43:45
Mark E. (snowball3 AT usa DOT net) wrote:
: I'm experimenting with inline assembly by trying to create an alias to a
: libc function, but so far I've been unsuccessful.
:
: Here's my code:
: #include <stddef.h>
:
: inline const void *
: memchr_alias (const void *_s, int _c, size_t _n)
: {
: asm ("jmp _memchr; ");
: }
:
: int main()
: {
: char buffer[16];
:
: memchr_alias (buffer, 'a', 15);
: return 0;
: }
:
: What I want is for memchr_alias to contain just the instruction "jmp
: _memchr", but instead egcs 1.1.2 produces for memchr_alias:
:
: _memchr_alias__:
: pushl %ebp
: movl %esp,%ebp
: movl 8(%ebp),%eax
: movl 12(%ebp),%edx
: movl 16(%ebp),%ecx
: /APP
: jmp _memchr;
: /NO_APP
: jmp L2
: jmp L1
: .p2align 2
: L2:
: L1:
: movl %ebp,%esp
: popl %ebp
: ret
:
: All I wanted was the 'jmp' instruction, not extra stack code. I've read the
: extended assembly portion of the gcc manual and I've tried out some of the
: constraints, but nothing gets rid of the extra code. Is there a way to tell
: asm() to output just the 'jmp' or am I out of luck?
The extra slack is because your memchr_alias() function takes
arguments.
Try
asm("
.text
.align 2,0x90
.globl _memchr_alias
_memchr_alias:
jmp _memchr
");
but note that my version of memchr_alias() doesn't take any
arguments. Hence some massaging is necessary.
Also remember I'm a assembly neophyte.
My Dying Bride, Like Gods of the Sun,
MartinS
- Raw text -