Write Assembly code in C#
-
You can't directly. .NET uses a form of intermediate language which is intended to be target neutral. If you want to use assembly code, you need to look at writing your application either in assembly, or in C/C++. .NET is entirely the wrong choice here.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith
As Braveheart once said, "You can take our freedom but you'll never take our Hobnobs!" - Martin Hughes.
Yeah, can't be done directly, but I would guess it can be done. Create a C++ project that uses "__asm {...}", reference that project from a managed C++ project, then reference that project from a C# project. Might have to mark some functions as "unsafe" or something, but I would guess something like that would work.
-
Yeah, can't be done directly, but I would guess it can be done. Create a C++ project that uses "__asm {...}", reference that project from a managed C++ project, then reference that project from a C# project. Might have to mark some functions as "unsafe" or something, but I would guess something like that would work.
-
how i can use Assembly code in C# ?
yes it can be done using c++ project wrapper then you would add reference to that dll into .net , but be careful , when you do so , you lose the portability that microsoft struggles for when it creates .NET technology , it can't be run on different OS because your embedded assembly code will be targetted for specific platform . Requirements to create the c++ wrapper dll 1 - Decorate the method in c++ as "extern" to stop the compiler from changing the method name when you compile your DLL . 2 - you can even call the dll methods without using unsafe declaration , because it will be treated like any dll referenced in .NET project. i hope this helps
Human knowledge belongs to the world.
-
how i can use Assembly code in C# ?
Strictly speaking, you can't as others have said. However this thread[^] says that you can use simple assembler instructions inline. WARNING You have to register to download the code. No personal details are required though. I also doubt that it compiles down to a binary file, don't know because I haven't looked at it myself yet. Still it might be fun even if not actually useful.
Henry Minute Do not read medical books! You could die of a misprint. - Mark Twain Girl: (staring) "Why do you need an icy cucumber?" “I want to report a fraud. The government is lying to us all.” Why do programmers often confuse Halloween and Christmas? Because 31 Oct = 25 Dec.
-
how i can use Assembly code in C# ?
-
Wouldn't there be a more direct way? Such as doing the __asm part in C++/CLI and merging it with the compiled C# with ILMerge? (would that work?)
I thought ILMerge only worked for IL assemblies. C++ with assembly code would compile directly to machine code. Would ILMerge still work then? And even if it did work then, I don't understand how that would make things more direct than creating a few projects and having a couple references in Visual Studio.
-
I suggest you stop trying to write your piece of malware (which is really the only thing it can be, if you want to disable interrupts)
Why in the world do you think the OP is creating malware or is trying to disable interrupts? Did the OP modify the question, because I don't see any mention of disabling interrupts. There are many uses for assembly language in higher level languages, usually relating to performance. For example, at the bottom of my SlimList article, I mention that I can use BSR (an assembly command) to do a quicker base 2 integer log calculation than would be possible using plain C#.
-
Why in the world do you think the OP is creating malware or is trying to disable interrupts? Did the OP modify the question, because I don't see any mention of disabling interrupts. There are many uses for assembly language in higher level languages, usually relating to performance. For example, at the bottom of my SlimList article, I mention that I can use BSR (an assembly command) to do a quicker base 2 integer log calculation than would be possible using plain C#.
Did you miss this[^]? Maybe you where occupied in darker areas? ;P
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
-
Did you miss this[^]? Maybe you where occupied in darker areas? ;P
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]
I only read formatted code with indentation, so please use PRE tags for code snippets.
I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).
Luc Pattyn wrote:
Did you miss this[^]?
Yep.
Luc Pattyn wrote:
Maybe you where occupied in darker areas?
QuickAnswers... a dark place indeed. ;P
-
I thought ILMerge only worked for IL assemblies. C++ with assembly code would compile directly to machine code. Would ILMerge still work then? And even if it did work then, I don't understand how that would make things more direct than creating a few projects and having a couple references in Visual Studio.