delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/03/16/20:57:47

Date: Mon, 16 Mar 1998 17:57:22 -0800 (PST)
Message-Id: <199803170157.RAA24172@adit.ap.net>
Mime-Version: 1.0
To: Fabrice ILPONSE <fabrice AT trash DOT lip6 DOT fr>, djgpp AT delorie DOT com
From: Nate Eldredge <eldredge AT ap DOT net>
Subject: Re: inline assembly

At 02:00  3/16/1998 +0100, Fabrice ILPONSE wrote:
>Hi!
>
>    I'd like to specify a memory reference in assembly. I mean, for eg.,
>I go a variable 'O'. I use it in inline assembly modifying its value and
>than return it. 

See GCC's info node "Extended Asm". It's a bit complicated but works really
well. In this case:

asm("addl $4, %0" : "=g" (O) : "0" (O));

adds 4 to O. (Make sure you distinguish between zeros (0) and O's (O) here!)

>Pb: when -O, there's no more variable O but a register.
>As i push and pop all the registers,

Btw: You shouldn't push and pop things in inline asm. It leads to problems
when you use -fomit-frame-pointer (GCC doesn't expect %esp to change).

> the good value is not kept. How can
>i specify to gcc not to put O in a register but keep it as a memory
>cell?

The method above will work regardless of where O is. But if, for some
reason, it *must* be in memory, you can do:

(void)&O;


Nate Eldredge
eldredge AT ap DOT net



- Raw text -


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