D
deostroll
Is the c language designed to execute assembly language instructions?
Is it in the standard?
--deostroll
Is it in the standard?
--deostroll
deostroll said:Is the c language designed to execute assembly language instructions?
Is it in the standard?
deostroll said:Is the c language designed to execute assembly language instructions?
Is it in the standard?
[...]cr88192 said:I would have to say no...
yes and no...
the standard reserves a keyword ('asm') for use for this purpose, but says
little more on the subject.
cr88192 said:I thought it was a keyword, and I had remembered seeing it in the standard,
only that I had not remembered it saying much more on the subject...
cr88192 said:deostroll said:Is the c language designed to execute assembly language instructions?
I would have to say no...
Is it in the standard?
yes and no...
the standard reserves a keyword ('asm') for use for this purpose, but says
little more on the subject.
the actual syntax of asm blocks, as well as any behavior/... they may
exhibit, is a matter left up to the implementation.
so, as a general rule, I don't use inline assembler...
going OT:
[...]
inline asm is less of a hassle than external ASM, but then it is compiler
specific (and, in the GCC case, forces use of GAS syntax, ...).
now, if gcc's inline assembler was like Borland's or Microsoft's
inline ASM (AKA: much nicer looking, and Intel syntax), I would
probably use inline ASM...
Is the c language designed to execute assembly language instructions?
Is it in the standard?
Antoninus Twink said:To be honest, that one seemingly trivial difference is enough to make me
use externally assembled asm on the rare occasions I need it. Though I
vaguely remember reading somewhere that gcc is doing an increasingly
good job of accepting Intel syntax - I don't know if it's reached the
stage of being really usable yet?
Exactly. Not one of the GNU folks' better design decisions IMO.
Antoninus Twink said:To be honest, that one seemingly trivial difference is enough to make me
use externally assembled asm on the rare occasions I need it. Though I
vaguely remember reading somewhere that gcc is doing an increasingly
good job of accepting Intel syntax - I don't know if it's reached the
stage of being really usable yet?
Exactly. Not one of the GNU folks' better design decisions IMO.
Is the c language designed to execute assembly language instructions?
Is it in the standard?
I hadn't heard of it, I may go look into this...
yep...
oddly, my compiler doesn't really support inline ASM at present...
then again, if it did, I would probably use the Borland or MS style...
Inline assembly is (IMO) a pretty bad idea in general.
consider:
_asm mov ax, 0xf ; move 15 into the AX register of our 8086
I hadn't heard of it, I may go look into this...
yep...
oddly, my compiler doesn't really support inline ASM at present...
then again, if it did, I would probably use the Borland or MS style...
I like NASM...
from what I looked at, I will guess the syntax is about the same
between them...
I also like using my own assembler as well, but FWIW mine is sort of a
subset/variant of NASM's syntax (its macro facilities and a few other
things are different, as I had used a C-style preprocessor, and there
are some other differences, but close enough...).
Inline assembly is (IMO) a pretty bad idea in general.
consider:
_asm mov ax, 0xf ; move 15 into the AX register of our 8086
_asm mov eax, 0xf; move 15 into the EAX register of our P4
_asm mov rax, 0xf; move 15 into the RAX register of our AMD 64
You will notice something strange about the above instructions which
all accomplish the same purpose. The names of the registers have
changed over time. So assembly code ages until it becomes useless.
Back in the bad old days, we had to calculate segments and offsets to
make an address. Now we have easier ways due to the larger address
space. So the techniques change over time. Also, the clever things
like XOR ax,ax to put a zero in ax fastest are not as clever as they
used to be since mov rax,0 is just as good now-days. And the
registers also widen over time. The ax register only held 16 bits.
In short, inline assembly is a mistake. It will obsolete your code
totally in a few years. And when the new whiz-bang chip comes out,
you will be doing a full rewrite.
BartC said:I put inline asm into a language which more or less *was* NASM. The rest
of the language was translated into NASM anyway and the inline stuff
(after some symbol fixups) was just copied over. There was no need to
write an assembler
I never found this a problem. There's quite a few years between 16, 32
and 64-bit machines, so probably they will need new software anyway, and
the asm code will be updated or replaced by something else.
cr88192 said:I hadn't heard of it, I may go look into this...
yep...
oddly, my compiler doesn't really support inline ASM at present...
then again, if it did, I would probably use the Borland or MS style...
<
Inline assembly is (IMO) a pretty bad idea in general.
<snip>
but it is pretty damn useful sometimes...
[...]
I never found this a problem. There's quite a few years between 16, 32 and
64-bit machines, so probably they will need new software anyway, and the asm
code will be updated or replaced by something else.
And often my inline asm code exists next to a high-level version that is
commented out (although usually for the purpose of debugging by disabling
the risky asm for something safer).
BTW that's quite a nifty asm syntax; which compiler is that from?
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.