Sometimes when I'm reading stuff, usually in C++ / Ojective-C, I see people say that for speed increase (etc), if necessary, you as the programmer can drop down to Assembly. How do you actually do that? Do you write some Assembly and compile it, and then... ? How do you link the two together? Do you have to link the objects together when linking? Could someone provide an example, maybe of the main function of a simple C++ hello app calling, say a function written in Assembly?
Thanks.
It differs by compiler, but in Visual C++:
__asm
{
int 3;
}
Which triggers the debug-interrupt. Everything enclosed in that __asm block is, well, assembler.
As far as I know, most compilers allow for inline assembler. Some assemblers produce object files that are compatible with those produced by a related C++ compiler which it can then link with it's linker.
However, typically, inline assembler produces a speed decrease, not a speed increase. This is because the compiler has no optimization information about what's going on in the assembler block, and a modern compiler typically produces faster assembler than written by a human hand. Most assembly language functionality is available in C++, either through direct language features or intrinsics (like the Interlocked intrinsics in Visual Studio).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With