Omnimaga
General Discussion => Technology and Development => Computer Projects and Ideas => Topic started by: harold on July 17, 2011, 02:16:19 pm
-
I don't know how many people here use C# (not many, going by the Programming Help topics..)
But this might be interesting anyway.
SharpAsm is a small library I wrote that lets you write a function in assembly and use it directly from C#.
It's very easy to use, for example:
Asm asm = new Asm(@"
bsr rax, rcx
ret");
Log2Delegate fastLog = asm.GetDelegate<Log2Delegate>();
// now use fastLog like any normal delegate
Obviously assembling the code takes a little time. When I use this library, I usually create all asm routines in a static constructor and then keep reusing the same delegate for all instances.
Source (the assembler): http://dl.dropbox.com/u/27035142/SharpAsm/Assembler.cs
Source (executable memory manager): http://dl.dropbox.com/u/27035142/SharpAsm/ExecutableMemory.cs
The assembler uses string manipulation instead of actual parsing, and is kind of kludgy. It also doesn't include all opcodes and doesn't always use the smallest encoding (eg not the special eax forms).
edit: almost all of SSE, SSE2, SSE3, SSSE3 and SSE4.1 is now supported. Just redownload the files. Please report any bugs .. if anyone actually uses this (uhm no)
-
Cool.
I know you can use asm from C, then compile your C/Asm code as a dll, then use it as unmanaged code in your C# program, but this would be easier.
-
Ooo, I do, I do! I use C#! It's my favorite programming language! ;D
So this is kind of like a C#-ASM interpreter?
-
Ooo, I do, I do! I use C#! It's my favorite programming language! ;D
So this is kind of like a C#-ASM interpreter?
Looks more like a way to embed asm code inside of C# programs. I don't normally use C# but this is pretty cool to see. It really helps with speeding up the bottlenecks while keeping the simplicity of the language
-
To clarify, the code is stored in the executable as a string, and will only be assembled when the constructor of the relevant Asm object is ran. You don't have you use it like that though - it can also take an array of bytes, which saves you the overhead of assembling the code at runtime, but it's less convenient.
-
Huge update: tons of instructions added, mostly vector instructions. Also some bugs fixed, where sometimes you could use instructions with mmx operands when the instruction doesn't support that, and sometimes using 16bit operands would actually crash the assembler. 16bit and 8bit stuff still doesn't really work and I probably won't bother too much with it anyway unless someone asks.
-
Hi,
May I know how to apply SharpAsm directly from c#? I would like to use it for Emotion detection.
Im fresh to ASM and C#. Could you please kindly guide me step by step.
Thank you very much
-
In what way are you trying to detect emotion? Most likely, depending upon what you're trying to detect emotion from, say like, text, you could probably do it in C# with reasonable efficiency.
-
Hi,
It's recognizing basic facial expression using ASM in C#.
Im looking for Active shape model in C# (SharpASM). Any idea?
Thanks
-
Well, it seems like you would write the assembly in an Asm object.
https://sourceforge.net/projects/sharpassembler/ (https://sourceforge.net/projects/sharpassembler/)
There's the sourceforge project which includes a readme. It should help. :)