Asm programming capability?

C

cr88192

Tor Rustad said:
user923005 wrote:

[...]
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

I don't disagree with your message, but my first PC was a 80386, and that
is quite a while ago, but I still have support for IA-32 now. However, the
Turbo C compiler is long gone and so is MS-DOS...

my first PC was an 8088...
granted this was in the time when 386's and 486's were common...
later I got a 386 and then a 486...

So not only does inline asm bind you to a CPU architecture, but also to
the compiler, since inline asm isn't a standard C extension, it suffice to
swap compiler to break the code.

yep...

compiler+CPU+OS...

luckily writing ones' own (at runtime) assembler, largely eliminates 2 of
the 3 dependencies in the ASM...

Another important thing to remember, is that inline assembler disable some
optimizations by the C compiler, so if the intent of the inline assembler
is for speedup, the opposite effect may very well result instead. :)

agreed...

I typically don't use ASM for micro-optimizing, as I have found that, for
general code, the C compiler typically does a fairly good job at optimizing.

C is used for system programming, and certain low-level stuff must be done
architecture dependent.

yes, agreed...

ASM is not, as usually assumed, only used by people trying to optimize their
code (and often for misguided reasons...), rather, it is a tool for getting
around some of the limitations that the C compiler can't address...

system programming is one example.
implementing dynamic native code compilers (as opposed to interpreters), is
another...

as well as little edge cases, which the "establishment" (existing compilers,
runtime libraries, ...) do not address (such as being able to call an
arbitrary C function with arbitrary arguments, ...).

sometimes one wants to be like:
"call the function named 'foo' with this list of datums..." (what, in Scheme
or LISP, would be called 'apply').

this fairly simple task, may actually require a fair amount of internal
"heavy lifting" (being able to fetch the function by name, figure out what
its argument types are, ...), and ASM...

....

 

Ask a Question

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.

Ask a Question

Members online

Forum statistics

Threads
474,160
Messages
2,570,889
Members
47,421
Latest member
StacyTaver

Latest Threads

Top