Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C Programming (http://www.velocityreviews.com/forums/f42-c-programming.html)
-   -   Assembly in C Standard (http://www.velocityreviews.com/forums/t596569-assembly-in-c-standard.html)

CJ 03-06-2008 05:22 PM

Assembly in C Standard
 
Some compilers support __asm{ } statement which allows integration of C
and raw assembly code. A while back I asked a question about such
syntax and was told that __asm is not a part of a C standard. My
question now is:

Is there a chance that such statement will become a part of C standard
in the future? In some cases using asm language is the best way to
acomplish some small task, hence integration of C and asm would greatly
enhence C, or atleast it would in my opinion.

Is there a good reason why __asm is not a part of current C standard?

I have bumped into compilers that support and others that ignore __asm
statement so obviously it is still not a part of C standard.

Putting it in the C standard would let programmers include assembly for
optimization while maintaining maximal portability.


santosh 03-06-2008 05:37 PM

Re: Assembly in C Standard
 
CJ wrote:

> Some compilers support __asm{ } statement which allows integration of
> C and raw assembly code. A while back I asked a question about such
> syntax and was told that __asm is not a part of a C standard. My
> question now is:
>
> Is there a chance that such statement will become a part of C standard
> in the future?


I don't think so, at least from the reactions I got when I brought up
this subject a while back.

> In some cases using asm language is the best way to
> acomplish some small task, hence integration of C and asm would
> greatly enhence C, or atleast it would in my opinion.


That's the problem. Not everyone views adding an "asm" keyword as a
great enhancement to C. The fact is, even if the *keyword* were added,
most other details about it's actual usage might not be easily
standardisable. This is because:

1. Assembler is inherently different (syntactically and semantically for
different architectures)

2. Most complers already have an "asm" extensions which is well
understood and has been used a good deal. Thus any standardisation
would have to take care to not break the preexisting usages.

> Is there a good reason why __asm is not a part of current C standard?


One reason that was given was that the details are too different and
system specific and the benefit of standardising a keyword too little
to be worth the effort.

> I have bumped into compilers that support and others that ignore __asm
> statement so obviously it is still not a part of C standard.


Yes. But C++ has an asm keyword.

> Putting it in the C standard would let programmers include assembly
> for optimization while maintaining maximal portability.


Maximal portability in what way. Unless it's *usage* details are also
fairly rigorously and exhaustively specified, I don't see how one
instance of an "asm" block for one compiler is going to be "maximally
portable" to another.

The usage of an asm block is going to remain tightly system specific, so
the benefit of standardising the construct is not going to be very
significant. That's why in current code, we have conditional
compilation blocks specifying separate asm blocks for each compiler
targeted.


Walter Roberson 03-06-2008 05:54 PM

Re: Assembly in C Standard
 
In article <slrnft0a2u.9q3.nospam@nospam.invalid>, CJ <no@spam.invalid> wrote:
>Some compilers support __asm{ } statement which allows integration of C
>and raw assembly code. A while back I asked a question about such
>syntax and was told that __asm is not a part of a C standard. My
>question now is:


>Is there a chance that such statement will become a part of C standard
>in the future?


Personally, I would think it -highly- unlikely. The C89 Rationale
says,

The keywords entry, fortran, and asm have not been included
since they were either never used, or are not portable. Uses of
fortran and asm as keywords are noted as common extensions.

Thus the matter was evaluated 20 years ago and found not
persuasive then, at a time when there were fewer architectures to
consider and at a time when C compiler optimization was much
weaker and so there was much more to gain by including assembly.
If it was not persuasive then, then it is even less persuasive now.

>In some cases using asm language is the best way to
>acomplish some small task, hence integration of C and asm would greatly
>enhence C, or atleast it would in my opinion.


>Is there a good reason why __asm is not a part of current C standard?


Standardizing asm or __asm would require defining the interaction
between C compilers and assembly. For example, some model would
have to be developed and adhered to by compilers in order to
allow assembly statements to locate and reference variables
(the internal mechanisms for which can vary according to optimization
level, program size, and the scope of the variable). This must
be done because, by definition, the assembly statements will
each consist of -single- assembly statements, each of which will
need to know exactly which addressing mode to specify to reference
the variable. The alternative, that would allow the asm (or __asm)
statements to generate all necessary prologs to load the value
of the variable, would imply that asm (or __asm) would no longer
be coded in assembler and would instead be coded in a macro language...
and then you have to define the characteristics of the macro language
and you have to lock down which machine registers are available to
the macro language to create the steps to load variables properly,
and so on.

It would, in short, be a mess, and would have the perverse effect
of requiring the generated code to *not* be as optimized as it
would otherwise be. Keep in mind sequence points and as-if rules
and movement of variables completely into registers, and
code movement out of loops, and so on: having asm (or __asm)
present would have to require that such optimizations be
turned off in the compiler, or else that a flexible asm macro
language be provided that had access to meta information about
which optimizations had been performed and which not so that it
would know which exact assembler statements to generate.

IMHO, "This Is A Bad Idea (TM)"
--
"To all, to each! a fair good-night,
And pleasing dreams, and slumbers light" -- Sir Walter Scott

Willem 03-06-2008 06:54 PM

Re: Assembly in C Standard
 
santosh wrote:
) 1. Assembler is inherently different (syntactically and semantically for
) different architectures)

Even for different compilers on the same architecture.


SaSW, Willem
--
Disclaimer: I am in no way responsible for any of the statements
made in the above text. For all I know I might be
drugged or something..
No I'm not paranoid. You all think I'm paranoid, don't you !
#EOT

Kenneth Brody 03-06-2008 07:06 PM

Re: Assembly in C Standard
 
CJ wrote:
[...]
> Is there a good reason why __asm is not a part of current C standard?
>
> I have bumped into compilers that support and others that ignore __asm
> statement so obviously it is still not a part of C standard.
>
> Putting it in the C standard would let programmers include assembly for
> optimization while maintaining maximal portability.


Consider that, even if it were to be part of the Standard, I can't
imagine it saying anything beyond:

The syntax is:

asm {
implementation-specific code
};

Given that everything between "asm {" and "};" is 100% implementation-
specific, I don't see what it gains, and I certainly don't see how it
can "maintain maximal portability". You will already need to #if the
source to select the proper assembly code, so what does it gain to
have the syntax standardized?

In other words, is it really "better" to have:

asm {
#if PLATFORM == SYSTEM1
... Code for System 1 here ...
#elif PLATFORM == SYSTEM2
... Code for System 2 here ...
#endif
};

as opposed to:

#if PLATFORM == SYSTEM1
asm {
... Code for System 1 here ...
}
#elif PLATFORM == SYSTEM2
__asm (
... Code for System 2 here ...
);
#endif

--
+-------------------------+--------------------+-----------------------+
| Kenneth J. Brody | www.hvcomputer.com | #include |
| kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer.h> |
+-------------------------+--------------------+-----------------------+
Don't e-mail me at: <mailto:ThisIsASpamTrap@gmail.com>


CBFalconer 03-06-2008 08:10 PM

Re: Assembly in C Standard
 
CJ wrote:
>

.... snip ...
>
> Is there a good reason why __asm is not a part of current C standard?


Yes. Assembly language is system peculiar. C is system independent.

--
[mail]: Chuck F (cbfalconer at maineline dot net)
[page]: <http://cbfalconer.home.att.net>
Try the download section.



--
Posted via a free Usenet account from http://www.teranews.com


Default User 03-06-2008 08:34 PM

Re: Assembly in C Standard
 
santosh wrote:

> CJ wrote:
>
> > Some compilers support __asm{ } statement which allows integration
> > of C and raw assembly code. A while back I asked a question about
> > such syntax and was told that __asm is not a part of a C standard.
> > My question now is:
> >
> > Is there a chance that such statement will become a part of C
> > standard in the future?

>
> I don't think so, at least from the reactions I got when I brought up
> this subject a while back.
>
> > In some cases using asm language is the best way to
> > acomplish some small task, hence integration of C and asm would
> > greatly enhence C, or atleast it would in my opinion.

>
> That's the problem. Not everyone views adding an "asm" keyword as a
> great enhancement to C. The fact is, even if the keyword were added,
> most other details about it's actual usage might not be easily
> standardisable. This is because:
>
> 1. Assembler is inherently different (syntactically and semantically
> for different architectures)
>
> 2. Most complers already have an "asm" extensions which is well
> understood and has been used a good deal. Thus any standardisation
> would have to take care to not break the preexisting usages.
>
> > Is there a good reason why __asm is not a part of current C
> > standard?

>
> One reason that was given was that the details are too different and
> system specific and the benefit of standardising a keyword too little
> to be worth the effort.
>
> > I have bumped into compilers that support and others that ignore
> > __asm statement so obviously it is still not a part of C standard.

>
> Yes. But C++ has an asm keyword.


True. Here's what the C++ standard says:

An asm declaration has the form
asm-definition:
asm ( string-literal ) ;
The meaning of an asm declaration is implementation-defined. [Note:
Typically it is used to pass information through the implementation to
an assembler. ]


I'm not sure how that's any more useful than leaving it out and
allowing implementations that wish to have assembly support to offer it
strictly as an extension.




Brian


Default User 03-06-2008 08:36 PM

Re: Assembly in C Standard
 
Kenneth Brody wrote:

> CJ wrote:
> [...]
> > Is there a good reason why __asm is not a part of current C
> > standard?


> > Putting it in the C standard would let programmers include assembly
> > for optimization while maintaining maximal portability.

>
> Consider that, even if it were to be part of the Standard, I can't
> imagine it saying anything beyond:
>
> The syntax is:
>
> asm {
> implementation-specific code
> };
>
> Given that everything between "asm {" and "};" is 100% implementation-
> specific, I don't see what it gains, and I certainly don't see how it
> can "maintain maximal portability". You will already need to #if the
> source to select the proper assembly code, so what does it gain to
> have the syntax standardized?


That's basically the approach C++ took (see my reply to Santosh).
Minimal standardization or no standardization, I'm not sure what the
real difference is.




Brian

Jean-Marc Bourguet 03-06-2008 08:39 PM

Re: Assembly in C Standard
 
"Default User" <defaultuserbr@yahoo.com> writes:

> I'm not sure how that's any more useful than leaving it out and
> allowing implementations that wish to have assembly support to offer it
> strictly as an extension.


Not much but it reserves the keyword and probably describing an existing
usage at the time of standardization. BTW, don't forget the catch 22
situation: you don't want to standardize something which is not already a
common usage, you don't want to use something which is not standardized.

Yours,

--
Jean-Marc

Harald van Dijk 03-06-2008 09:17 PM

Re: Assembly in C Standard
 
On Thu, 06 Mar 2008 15:10:16 -0500, CBFalconer wrote:
> CJ wrote:
>>

> ... snip ...
>>
>> Is there a good reason why __asm is not a part of current C standard?

>
> Yes. Assembly language is system peculiar. C is system independent.


C is not system independent. There is a system independent subset of C,
but C contains a lot of system dependent areas. For the easiest example,
look at the system function.


All times are GMT. The time now is 04:15 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.