this is about using assembly to optimize some program in another language. I was under the impression this was easily done in c/c++.
Reading Reading https://msdn.microsoft.com/en-us/library/4ks26t93.aspx it says inline assembly is not supported in x64 computers anymore.
really ? is this true? :(
Removed [Resolved] :P
Bullshit ^^
I've a x64 system and inline assembly works flawlessy :)
Msdn is talking about special processors I think.
MSDN means it's not supported in latest releases of Visual Studio and Visual C++. The X64 processor will of course run .exe's developed with inline assembly using some other C++ compiler; it doesn't know what the source code was. And, most other C++'s do support inline
Disclaimer: I don't use C++, so if u know different I apologize; but I think I've got this right. I figure, yq8, you're not using 64-bit MS VS and VC++
MS VC++ doesn't support inline assembly in X64 anymore.
Well you have 2 options :
1. Write both C/C++ and assembly code separately, and then link them together
2. Switch to X86. Inline assembly is still supported.
Or, use a non-MS C++ 64-bit compiler, that does support inline. There must be plenty of them
thank you all :)
FWIW, for x64 Pelles C does not support inline assembly.
They try to avoid the assembly language. This the reason of the lack of the inline asm support.
Fortunately, "the Intel C Compiler 15 has inline capability in 64bit too." - according to Silvio at stackoverflow.com (http://stackoverflow.com/questions/6166437/64bit-applications-and-inline-assembly). Unfortunately it costs big bucks
Inline assembly is not the best approach to programming
In MSVC you can combine asm sources with C++ sources and run at the same time and you can debug it on a source level
You can use JWasm with JWasm targets
It took a long time for me to discover all of the necessary details, but Intel-syntax inline assembly works with a recent 64-bit version of gcc. Note that I did not bother determining if the processor actually supports RDRAND.
#include <stdlib.h>
#include <stdio.h>
#include <conio.h>
unsigned long long int rval;
int main(void)
{
int i;
printf("%d\n\n",sizeof(rval));
for(i=0;i<100;i++)
{
__asm__
(
"0:"
"rdrand rax;"
"jnc 0b;"
"mov rval, rax;"
);
printf("%I64x\n",rval);
}
getch();
}
set path=C:\Program Files\mingw-w64\x86_64-4.9.2-win32-seh-rt_v4-rev2\mingw64\bin
gcc.exe -std=c99 -pedantic -Os -m64 -masm=intel test.c -o test.exe
pause
I specified Intel syntax in my batch file, but it's also possible to do it directly in the inline assembly by bracketing the inline assembly with appropriate directives:
{
__asm__
(
".intel_syntax noprefix;"
...
".att_syntax prefix;"
);
getch();
}
And I started out to do this as inline assembly in a "naked" function (no compiler-generated prologue or epilogue), but while that capability is supported for some hardware platforms, it's not supported for x86 or x86-64.
Edit: Added a zip file that includes the C source, my batch file, the assembly output, and the EXE.