Click to See Complete Forum and Search --> : inline asm
emyztik
Dec 16th, 2005, 07:24 PM
is it possible to use inline asm in C# like in C++?
C++ Example:
_asm
{
push 0
push title
push message
push 0
call blah
}
possible?
emyztik
Dec 18th, 2005, 09:24 PM
yes? no? maybe so?
jmcilhinney
Dec 18th, 2005, 10:51 PM
It appears not, in so far as every reference to "inline assembly" I can find in the help relates to C++. I've also never heard anyone mention doing it previously. I'd guess that you'd have to write your assembly code in a C++ library and reference that from your C# app.
Girvo911
Dec 18th, 2005, 10:56 PM
Not sure whether this will help but,
http://www.thecodeproject.com/csharp/Inline_ASM_for_C_.asp
Girvo911
Dec 18th, 2005, 10:59 PM
Also, i found something on a site that might be interesting:
C# has a magical "unsafe" keyword that lets me write assembly language inline in a method body
/**
* Manipulates the stack directly. Note the use
* of the unsafe keyword which allows us to use
* the __asm keyword.
*/
private unsafe string[] listFiles(string path) {
__asm {
push path
push 1 // number of arguments
push "mFile"
getv // get the mFile global object
push "listFiles"
callm // call mFile.listFiles method
}
}
http://www.darronschall.com/weblog/archives/000162.cfm
wossname
Dec 19th, 2005, 04:12 PM
Hang your head in shame. That is not assembly.
And no, C# doesn't do inline ASM. Or at least not natively. You can get a few crappy tools that let you fake it out but its still not the real deal.
If you want to get a benefit from ASm in a C# app then you'd be better off writing a DLL in ASM and linking it directly into your C# program. This has more or less the same effect as inline ASM anyway, both ways are a compromise in the "Managed code" paradigm.
C# and ASM are not designed to be used together. C++ and ASM are (sort of).
Hey, at least you aren't using VB.net ;)
emyztik
Dec 19th, 2005, 08:30 PM
wossname, that's exactly what I wanted to know, thanks. I'll stick with C++ I guess :thumb:
Thanks guys.
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.