Is it possible to include assembler code into CSharp?
If yes, could someone give me an example?
Joe 11 1463
Joe DeAngelo <de*******@nortel.com> wrote: Is it possible to include assembler code into CSharp? If yes, could someone give me an example?
No, it's not possible.
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
I'm fairly sure you can't do that. CSharp compiles into intermediate language (IL) + Metadata. From there at runtime the IL is compiled into machine specific code. Writing assembler code would break this chain. You can however, execute other programs from within your C# code. So if you could compile the Assembly code into an executable you should be able to run that from your C# code.
Check out the method 'System.Diagnostics.Process.Start'
HTH
"Joe DeAngelo" wrote: Is it possible to include assembler code into CSharp? If yes, could someone give me an example?
Joe
Ryan Riddell <Ry*********@discussions.microsoft.com> wrote: I'm fairly sure you can't do that. CSharp compiles into intermediate language (IL) + Metadata. From there at runtime the IL is compiled into machine specific code. Writing assembler code would break this chain. You can however, execute other programs from within your C# code. So if you could compile the Assembly code into an executable you should be able to run that from your C# code.
What would occasionally be useful would be the ability to include ILASM
in C# code - but you can't do that, either :(
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
"Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message
news:MP************************@msnews.microsoft.c om... Ryan Riddell <Ry*********@discussions.microsoft.com> wrote: I'm fairly sure you can't do that. CSharp compiles into intermediate language (IL) + Metadata. From there at runtime the IL is compiled into machine specific code. Writing assembler code would break this chain. You can however, execute other programs from within your C# code. So if you could compile the Assembly code into an executable you should be able to run that from your C# code.
What would occasionally be useful would be the ability to include ILASM in C# code - but you can't do that, either :(
Or even link an ILASM program and a C# one in the same module (the same
*assembly* when using VS.NET). I have an entire assembly containing two
methods I couldn't write in C#.
Daniel Jin <Da*******@discussions.microsoft.com> wrote: What would occasionally be useful would be the ability to include ILASM in C# code - but you can't do that, either :(
Jon, I once had thought of this as well. but when I trying to find what I can accomplish in IL that C# doesn't offer, I can't really find anything particularly important. do you have anything in mind where IL is absolutely necessary? very curious on what you can come up with.
Well, two possibilities spring to mind:
1) Sometimes you can handwrite IL which is faster (after JITting) than
what the C# compiler comes up with. Someone posted an example of this
once.
2) You can replace boxed values without unboxing/reboxing. For
instance, in a hashtable mapping string to int, you could increment the
value of the boxed int without all the
int x = (int)table[key];
x++;
table[key]=x;
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too de*******@nortel.com (Joe DeAngelo) wrote: Is it possible to include assembler code into CSharp? If yes, could someone give me an example?
Well, pardon my newbieness, but couldn't you include it as a resource or
DLL?
One of my books gives an example of writing a DLL in C#, but the finished
product - mustn't it be machine code?
The Doormouse
--
The Doormouse cannot be reached by e-mail without her permission.
The Doormouse <do*******@att.net> wrote: de*******@nortel.com (Joe DeAngelo) wrote:
Is it possible to include assembler code into CSharp? If yes, could someone give me an example? Well, pardon my newbieness, but couldn't you include it as a resource or DLL?
Well, it would have to be a separate DLL if you want to compile with
VS.NET.
One of my books gives an example of writing a DLL in C#, but the finished product - mustn't it be machine code?
Nope, it's IL - the JIT compiler turns it into native code at runtime.
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
"Daniel Jin" <Da*******@discussions.microsoft.com> wrote in message
news:6E**********************************@microsof t.com...
"Jon Skeet [C# MVP]" wrote:
Ryan Riddell <Ry*********@discussions.microsoft.com> wrote: I'm fairly sure you can't do that. CSharp compiles into intermediate language (IL) + Metadata. From there at runtime the IL is compiled into machine specific code. Writing assembler code would break this chain. You can however, execute other programs from within your C# code. So if you could compile the Assembly code into an executable you should be able to run that from your C# code.
What would occasionally be useful would be the ability to include ILASM in C# code - but you can't do that, either :(
Jon, I once had thought of this as well. but when I trying to find what I
can accomplish in IL that C# doesn't offer, I can't really find anything
particularly important. do you have anything in mind where IL is absolutely
necessary? very curious on what you can come up with.
You can make non-virtual calls to virtual methods, like the C++ syntax
ptr->definingClass::method()
I needed this in .NET 1.0 to access the System.Object version of
GetHashCode() on arbitrary objects. In .NET 1.1, there's another way to do
this (which I don't offhand recall.)
Jon,
I used to advocate adding "inline ILAsm" support too, but I no longer
think the few situations where it would be useful justifies the
resources it would take to implement it.
To me, the Whidbey VC++ linker's support for linking modules into a
single file assembly is a better solution to the problem. 2) You can replace boxed values without unboxing/reboxing. For instance, in a hashtable mapping string to int, you could increment the value of the boxed int without all the
int x = (int)table[key]; x++; table[key]=x;
If you do that a lot, perhaps you should consider writing a wrapper
class around the int and store that in the hashtable instead, to avoid
the (un)boxing.
class IntWrapper { public int x; }
(table[key] as IntWrapper).x++;
And then in Whidbey, you'd probably use a Dictionary<string,int>
instead.
Mattias
--
Mattias Sjögren [MVP] mattias @ mvps.org http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Mattias Sjögren <ma********************@mvps.org> wrote: I used to advocate adding "inline ILAsm" support too, but I no longer think the few situations where it would be useful justifies the resources it would take to implement it.
Oh I'd certainly have no problem with that argument. I was just giving
examples of where it could be useful had it been implemented.
To me, the Whidbey VC++ linker's support for linking modules into a single file assembly is a better solution to the problem.
Is that available outside VC++ though? Also, can you create ILASM
modules within Whidbey? 2) You can replace boxed values without unboxing/reboxing. For instance, in a hashtable mapping string to int, you could increment the value of the boxed int without all the
int x = (int)table[key]; x++; table[key]=x; If you do that a lot, perhaps you should consider writing a wrapper class around the int and store that in the hashtable instead, to avoid the (un)boxing.
If it were easy to avoid the boxing/unboxing *without* creating a
wrapper, however, I'd do that. There are obviously ways round these
things :)
class IntWrapper { public int x; } (table[key] as IntWrapper).x++; And then in Whidbey, you'd probably use a Dictionary<string,int> instead.
Oh indeed - it was just an example, really. As you say, it would have
been more useful in .NET 1 than .NET 2.
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Jon, Is that available outside VC++ though?
Yes, to anything that can launch link.exe.
Also, can you create ILASM modules within Whidbey?
I haven't tried it myself, but considering how flexible MSBuild is I
don't think it would be a problem to do this if you want to.
Mattias
--
Mattias Sjögren [MVP] mattias @ mvps.org http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Sai Kit Tong |
last post by:
Hi,
I am developing a new application running on Windows platform that needs to
interface with existing legacy code - written in basic C / C++. I am trying
to evaluate Java vs C#...
|
by: Sai Kit Tong |
last post by:
I posted for help on legacy code interface 2 days ago. Probably I didn't
make it clear in my original mail. I got a couple of answers but none of
them address my issues directly (See attached...
|
by: Mark Kamoski |
last post by:
Hi--
Please help.
I need a code sample for bubble sort.
Thank you.
--Mark
|
by: Timothy Shih |
last post by:
Hi, I am trying to figure out how to use unmanaged code using P/Invoke. I
wrote a simple function which takes in 2 buffers (one a byte buffer, one a
char buffer) and copies the contents of the byte...
|
by: light_wt |
last post by:
Hi
I am taking the 2555 class and a lot of the material is over my head. I don't like the MS's book because there is no step-by-step on interacting with the VS.NET
Is there good free resource...
| |
by: Alan Krueger |
last post by:
Is there a way to automatically include C# files (.cs) generated by a
third-party tool into a Visual C# .NET build? It's possible the set
of files generated by this tool might change. Adding...
|
by: news.microsoft.com |
last post by:
Hi:
I work in Csharp's parser files by LEX/YACC.Now I have only CSharp-lex.l
and CSharp.y file,but they not have CSharp'comment Parse. this is a part of
CSharp-lex.l.
........................
|
by: John Burnett |
last post by:
I have an unmanaged dll that I need to include as part of a managed assembly
(it provides functionality that I use via p/invoke).
I came across a blog entry called "Versioning/Deploying unmanaged...
|
by: David Ching |
last post by:
Hello, I am just starting to experiment with VC2005 to create a C++ WinForms
app. I have created a simple form, and it works. Now I want to add a C#
..cs source file containing a new class that I...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |