#1
|
||||
|
||||
How to inline x64 asm in vs2017 ?
Hi
Can I use inline x64 asm in vs 2017 ? When I use inline asm in x64 , this error show up : nonstandard extension used: '__asm' keyword not supported on this architecture Last edited by Mahmoudnia; 06-17-2018 at 15:36. |
#2
|
||||
|
||||
There is no x64 inline assembly with the Microsoft compiler.
Quote:
|
The Following 2 Users Say Thank You to deepzero For This Useful Post: | ||
Mahmoudnia (06-17-2018), tonyweb (06-18-2018) |
#3
|
|||
|
|||
http://masm32.com/board/index.php?topic=4211.0
maybe useful in check options. |
The Following 2 Users Say Thank You to user1 For This Useful Post: | ||
Mahmoudnia (06-17-2018), tonyweb (06-18-2018) |
#4
|
||||
|
||||
You have several options.
1. Switch to some other compiler like intel or GCC. You can still use Visual Studio, just a different compiler, they don't have inline asm restrictions. 2. Compile a separate .asm and link with other compiled .cpp files. This can be configured, so it's done automatically when the solution is built. 3. Sometimes it's enough to use intrinsics. But of course they don't cover all asm instructions. |
The Following 2 Users Say Thank You to Archer For This Useful Post: | ||
Mahmoudnia (06-18-2018), tonyweb (06-18-2018) |
#5
|
||||
|
||||
@Archer
I am trying to use GCC x64 |
#6
|
|||
|
|||
Or as a fourth option since it has yet to be mentioned, write a tool which at compile time extracts all inline code from C modules intended for x64 compilation, put them in an .asm file with some type of label or function definition, compile them, replace the C code with an appropriate control flow transfer, and so forth.
Unfortunately, nothing will be exactly equivalent mentioned so far in MSVC as the control flow transfer is pretty hard to avoid. Best yet might be to keep requesting MS to make the long overdo change as a developer feedback or feature request. |
#7
|
|||
|
|||
Two ways:
- Intrinsics https://msdn.microsoft.com/en-us/library/26td21ds.aspx - As above suggested, .asm linking here a tutorial on how to setup VS + MASM http://lallouslab.net/2016/01/11/introduction-to-writing-x64-assembly-in-visual-studio/ Best Regards, Evilcry |
The Following 2 Users Say Thank You to Evilcry For This Useful Post: | ||
Mahmoudnia (06-18-2018), tonyweb (06-18-2018) |
#8
|
|||
|
|||
But since you are not linking the .asm inline, there are excessive call or jump statements emitted. The best would be if MS were to add it.
|
#9
|
|||
|
|||
Does one call or jump really matter?
I mean, if you said you couldn't easily access local variables or structures, I'd agree... but "excessive call", it sounds like you are trying to optimize something. In that case inline assembler is hardly any good - it's a blackbox for the compiler (at least for the Microsoft's) so it has to dump the values from registers into local variables and after the inline assembly load them back. In other words, a piece of inline assembly heavily breaks the optimization of the surrounding C code - so it's usually not worth it, it does more damage than one call would (so it's better to write the whole CPU intensive piece of code in assembler as a separate function). |
The Following User Says Thank You to gigaman For This Useful Post: | ||
tonyweb (06-20-2018) |
#10
|
|||
|
|||
It matters because its very convenient to program like this. By having to call/return or jump/jump or what have you (also don't forget all the stack setup and cleanup), it forces calling conventions and requires the parameters to be dealt with and such. Yes the MS implementation is not as clever as in GCC/GAS where you can really customize details of the behavior. I agree for optimization its a lame point as you would better be off with pure asm or optimized C rather than a mix and match without sophisticated inline-ing support.
Further its easier to write portable 64/32 bit code without calling conventions and clever use of macros, as the calling conventions are so different you have to use different assembly instructions (registers vs stack). A C function can modify itself in memory also using clever tricks with inline assembler which has its obfuscation or other uses. But I suppose this discussion is easily already documented: Quote:
Quote:
|
The Following User Says Thank You to chants For This Useful Post: | ||
tonyweb (06-20-2018) |
#11
|
||||
|
||||
While you can't use inline asm, you can link ASM files into your program and use a separate compiler such as MASM to build .asm files with your project. Visual Studio has support for this built-in.
If you absolutely need inline asm you can use a different compiler/linker. |
#12
|
|||
|
|||
Well it looks like it will not happen anytime either. Unless we all get together to vote it to the top. Difficult to reason about proving correctness in the compiler I suppose
Quote:
Quote:
|
The Following User Says Thank You to chants For This Useful Post: | ||
Newbie_Cracker (07-11-2018) |
#13
|
|||
|
|||
Just create a .ASM file, change the build rule to MASM, define the subroutine and call it from the C file.
masm.asm Quote:
Quote:
Last edited by Avalon; 07-17-2018 at 04:05. |
The Following User Says Thank You to Avalon For This Useful Post: | ||
niculaita (07-17-2018) |
#14
|
||||
|
||||
@avalon
Typo... ChangeRaxRoutine PROC mov rax, 0x4141 ChangeRcxRoutine ENDP .... .code public ChangeRaxRoutine ChangeRaxRoutine proc mov rax, 04141h ChangeRaxRoutine endp end
__________________
Computer Forensics |
The Following User Says Thank You to Insid3Code For This Useful Post: | ||
niculaita (07-17-2018) |
#15
|
||||
|
||||
Just an example, hope can help you: https://github.com/vic4key/MS-Mix-Cpp-n-Asm-in-64-bit
|
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
inline patche | hp3 | Source Code | 3 | 06-04-2021 14:48 |
X64 inline asm | Fyyre | x64 OS | 48 | 08-10-2014 16:50 |
Inline Patching | MaRKuS-DJM | General Discussion | 1 | 01-24-2004 23:03 |