www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1999/04/05/15:43:45

From: ams AT ludd DOT luth DOT se (Martin Str|mberg)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: inline asm & jmp
Date: 5 Apr 1999 10:35:42 GMT
Organization: University of Lulea, Sweden
Lines: 71
Message-ID: <7ea3lu$egk$1@news.luth.se>
References: <37084934 DOT 6866274 AT news3 DOT ibm DOT net>
NNTP-Posting-Host: queeg.ludd.luth.se
X-Newsreader: TIN [UNIX 1.3 950824BETA PL0]
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019