www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1995/07/22/05:11:10

Xref: news-dnh.mv.net comp.os.msdos.djgpp:1069
Newsgroups: comp.os.msdos.djgpp
Path: news-dnh.mv.net!mv!news.sprintlink.net!gatech!europa.chnt.gtegsc.com!howland.reston.ans.net!news-e1a.megaweb.com!newstf01.news.aol.com!uunet!in2.uu.net!psinntp!psinntp!psinntp!psinntp!netrixgw.netrix.com!jasmine!ld
From: ld AT jasmine DOT netrix DOT com (Long Doan)
Subject: Re: Inline assembler
To: Roberto Alsina <ralsina AT ultra4 DOT unl DOT edu DOT ar>
Sender: ld AT jasmine (Long Doan)
Reply-To: ld AT netrix DOT com
Organization: Netrix Corporation
References: <DC2Kw5 DOT ns AT jade DOT mv DOT net>
Date: Fri, 21 Jul 1995 21:18:10 GMT
Lines: 33
Dj-Gateway: from newsgroup comp.os.msdos.djgpp

In article <DC2Kw5 DOT ns AT jade DOT mv DOT net>, Roberto Alsina <ralsina AT ultra4 DOT unl DOT edu DOT ar> writes:
|> I have a small assembler routine that waits for a vertical retrace of the 
|> screen, something very useful for graphics, and two little problems:
|> 
|> 1) The routine makes a jump to a label, that's ok, but when compiling whit 
|> -O3, it gets inlined, so the label gets duplicated everywhere the 
|> function is called, and the program won't compile. Is there something like a 
|> "not_inline" directive to tell the compiler NOT to inline that function?, 
|> or a way to define a local label? (i saw it on the info files, but i  
|> couldn't make it work, if somebody has, please send me an example).

Try __volatile__ func ();

|> 2) How do i reference a local variable (or label) or an argument passed to a 
|> function from an asm? _varname only seems to work with globals.

You'll have to look at their orders (some might be optimized away!),
and the offset them from %ebp.

Ex:
void test (int a, int b)
{
  int c, d;

  a = b = c = d = 0;
  asm ("movl $3, 8(%ebp)    \n\  /* a */
        movl $4, 12(%ebp)   \n\  /* b */
        movl $1, -4(%ebp)   \n\  /* c */
        movl $2, -8(%ebp)   \n\  /* d */
       ");
  printf ("You should see 1 2 3 4 if your program is NOT optimized.\n");
  printf ("1 2 3 4 : ", %d %d %d %d\n", c, d, a, b);
}

- Raw text -


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