Hi,
i am trying to write inline assembly in my C code using asm(" ");
but it is not accepting the variable names as inputs.
Is it possible to write inline assembly which accepts variables as
arguments?
func()
{
int a,b;
asm(" add a,b,a"); //it is not accepting this format
}
Thank You,
Hiten
|
|
0
|
|
|
|
Reply
|
Hithendra
|
1/8/2010 12:57:29 PM |
|
Hithendra wrote:
> Is it possible to write inline assembly which accepts variables as
> arguments?
>
> func()
> {
> int a,b;
> asm(" add a,b,a"); //it is not accepting this format
>
> }
No, it is not.
The compiler will just copy all the inline assembler that you write into
the assembler-source verbatim.
Variable names don't exist during the assemble stage anymore, and the
variable you're refering to may exist on the stack or inside several
registers at the same time.
Since the optimizer is very aggressive there is no way to guess where
the variable is.
If you really need assembler (why? - the compiler is excellent) put your
code into an external assembler file. There are two kinds of them:
linear (easier to write) and scheduled assembler.
Check the SPRU187.pdf file for more details.
Cheers,
Nils Pipenbrinck
|
|
0
|
|
|
|
Reply
|
Nils
|
1/8/2010 1:24:57 PM
|
|
Hithendra wrote:
> Hi,
> i am trying to write inline assembly in my C code using asm(" ");
> but it is not accepting the variable names as inputs.
>
> Is it possible to write inline assembly which accepts variables as
> arguments?
>
> func()
> {
> int a,b;
> asm(" add a,b,a"); //it is not accepting this format
>
> }
1. Inline assembler is misnomer. It should never be used. If you need to
code something in assembly, make a separate assembly module.
2. Usually, the inline assembler supports GNU style argument passing:
#define fubar(fu, bar, blablabla)
asm ("r0=%1;"
"r1=%2;"
"%0=r0+r1;"
: "=d" (result)
: "d" (x), "d" (y)
: "r0", "r1");
Ugly, isn't it?
3. RTFM
Vladimir Vassilevsky
DSP and Mixed Signal Design Consultant
http://www.abvolt.com
|
|
0
|
|
|
|
Reply
|
Vladimir
|
1/8/2010 3:03:09 PM
|
|
On Fri, 08 Jan 2010 09:03:09 -0600, Vladimir Vassilevsky wrote:
> Hithendra wrote:
>
>> Hi,
>> i am trying to write inline assembly in my C code using asm(" ");
>> but it is not accepting the variable names as inputs.
>>
>> Is it possible to write inline assembly which accepts variables as
>> arguments?
>>
>> func()
>> {
>> int a,b;
>> asm(" add a,b,a"); //it is not accepting this format
>>
>> }
>
> 1. Inline assembler is misnomer. It should never be used. If you need to
> code something in assembly, make a separate assembly module.
I could argue with that -- specifically it sometimes makes sense to put
inline assembly as the only content in a function, and let the compiler
deal with proper linkage &c.
> 2. Usually, the inline assembler supports GNU style argument passing:
>
> #define fubar(fu, bar, blablabla)
> asm ("r0=%1;"
> "r1=%2;"
> "%0=r0+r1;"
> : "=d" (result)
> : "d" (x), "d" (y)
> : "r0", "r1");
>
> Ugly, isn't it?
In my experience you can't count on this -- I see Gnu-style parameter
passing about 30% of the time.
> 3. RTFM
Or at least it's your only hope. Compiler manufacturers dedication to
inline assembly varies wildly, the 'FM' often falls flat at giving
sufficient information, and if you _do_ need to use inline assembly you
often have to experiment around quite a bit.
Mostly I do with you say, though I'll often start by compiling a small
'c' program with an "empty" function to assembly, then I'll use that
output as a starting point for my code (be sure to recognize and strip
the debugging directives, though).
--
www.wescottdesign.com
|
|
0
|
|
|
|
Reply
|
Tim
|
1/8/2010 3:44:44 PM
|
|
Nils wrote:
> Hithendra wrote:
>
>> Is it possible to write inline assembly which accepts variables as
>> arguments?
>>
>> func()
>> {
>> int a,b;
>> asm(" add a,b,a"); //it is not accepting this format
>>
>> }
>
> No, it is not.
>
> The compiler will just copy all the inline assembler that you write into
> the assembler-source verbatim.
> Variable names don't exist during the assemble stage anymore,
Not even as _a and _b ?
> and the
> variable you're refering to may exist on the stack or inside several
> registers at the same time.
>
> Since the optimizer is very aggressive there is no way to guess where
> the variable is.
>
> If you really need assembler (why? - the compiler is excellent) put your
> code into an external assembler file. There are two kinds of them:
> linear (easier to write) and scheduled assembler.
>
> Check the SPRU187.pdf file for more details.
>
> Cheers,
> Nils Pipenbrinck
--
Les Cargill
|
|
0
|
|
|
|
Reply
|
Les
|
1/8/2010 10:13:27 PM
|
|
|
4 Replies
496 Views
(page loaded in 0.06 seconds)
Similiar Articles: How to use Inline assembly on C64x+ - comp.dspHi, i am trying to write inline assembly in my C code using asm(" "); but it is not accepting the variable names as inputs. Is i... how to use __cpuid intrinsic - comp.lang.asm.x86How to use Inline assembly on C64x+ - comp.dsp how to use __cpuid intrinsic - comp.lang.asm.x86 Hi, I need to port win32 app. on AMD64 for which I need to remove inline ... icc inline assembly - comp.lang.asm.x86How to use Inline assembly on C64x+ - comp.dsp icc inline assembly - comp.lang.asm.x86 Inline Assembly, use-msasm and fasm-blocks - Intel® Software Network Intel C++ ... Intel C++ Compiler (Linux x86_64) - "GNU-style Inline Assembly ...How to use Inline assembly on C64x+ - comp.dsp Intel C++ Compiler (Linux x86_64) - "GNU-style Inline Assembly ... Hello, Could anyone suggest some resources freely ... MinGW and Inline Assembler - comp.os.ms-windows.programmer.win32 ...How to use Inline assembly on C64x+ - comp.dsp Assembly in mingw G++- C Programming. Visit Dev Shed to discuss Assembly in mingw G++ ... I "don't" want to use inline ... Sliding Goertzel of Jacobsen&Lions correct? - comp.dspHow to use Inline assembly on C64x+ - comp.dsp Sliding Goertzel of Jacobsen&Lions correct? - comp.dsp In Eric Jacobsen and Richard Lyons excellent article in the IEEE ... Writing Assembly Code in x64 - comp.lang.asm.x86How to use Inline assembly on C64x+ - comp.dsp Writing Assembly Code in x64 - comp.lang.asm.x86 I'm very new to this & now facing problems with 32-bit Inline assembly code. DSP Libraries using C - comp.dspHow to use Inline assembly on C64x+ - comp.dsp Hi, i am trying to write inline assembly in my C code using asm(" "); but it is ... RTFM Vladimir Vassilevsky DSP and Mixed ... Use Ring0 mode in Visual Studio .NET - comp.lang.asm.x86 ...Hi I'm using inline assembly in Visual Studio .NET, to make programs that use DOS interrupts. Problem : when I use "int" asm instruction, I get a GP... passing a FH to a module then writing to it - comp.lang.perl ...How to use Inline assembly on C64x+ - comp.dsp Hi, i am trying to write inline assembly in ... in assembly, make a separate assembly module. 2. How to use Inline assembly on C64x+ - comp.dsp | Computer GroupHi, i am trying to write inline assembly in my C code using asm(" "); but it is not accepting the variable names as inputs. Is i... Inline Assembler (C++) - Microsoft Corporation: Software ...Microsoft Specific. Assembly language serves many purposes, such as improving program speed, reducing memory needs, and controlling hardware. You can use the inline ... 7/22/2012 4:27:26 AM
|