Author Topic: SharpAsm - use assembly directly from C#  (Read 6904 times)

0 Members and 1 Guest are viewing this topic.

Offline harold

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 226
  • Rating: +41/-3
    • View Profile
SharpAsm - use assembly directly from C#
« 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:
Code: [Select]
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)
« Last Edit: April 02, 2012, 08:17:32 am by harold »
Blog about bitmath: bitmath.blogspot.nl
Check the haroldbot thread for the supported commands and syntax.
You can use haroldbot from this website.

Offline Juju

  • Incredibly sexy mare
  • Coder Of Tomorrow
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 5730
  • Rating: +500/-19
  • Weird programmer
    • View Profile
    • juju2143's shed
Re: SharpAsm - use assembly directly from C#
« Reply #1 on: July 18, 2011, 01:13:51 am »
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.

Remember the day the walrus started to fly...

I finally cleared my sig after 4 years you're happy now?
THEGAME
This signature is ridiculously large you've been warned.

The cute mare that used to be in my avatar is Yuki Kagayaki, you can follow her on Facebook and Tumblr.

Offline BlakPilar

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 734
  • Rating: +44/-1
    • View Profile
Re: SharpAsm - use assembly directly from C#
« Reply #2 on: July 18, 2011, 01:24:20 am »
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?

Offline z80man

  • Casio Traitor
  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 977
  • Rating: +85/-3
    • View Profile
Re: SharpAsm - use assembly directly from C#
« Reply #3 on: July 18, 2011, 02:58:55 am »
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

List of stuff I need to do before September:
1. Finish the Emulator of the Casio Prizm (in active development)
2. Finish the the SH3 asm IDE/assembler/linker program (in active development)
3. Create a partial Java virtual machine  for the Prizm (not started)
4. Create Axe for the Prizm with an Axe legacy mode (in planning phase)
5. Develop a large set of C and asm libraries for the Prizm (some progress)
6. Create an emulator of the 83+ for the Prizm (not started)
7. Create a well polished game that showcases the ability of the Casio Prizm (not started)

Offline harold

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 226
  • Rating: +41/-3
    • View Profile
Re: SharpAsm - use assembly directly from C#
« Reply #4 on: July 18, 2011, 02:59:37 pm »
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.
Blog about bitmath: bitmath.blogspot.nl
Check the haroldbot thread for the supported commands and syntax.
You can use haroldbot from this website.

Offline harold

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 226
  • Rating: +41/-3
    • View Profile
Re: SharpAsm - use assembly directly from C#
« Reply #5 on: April 02, 2012, 08:20:03 am »
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.
Blog about bitmath: bitmath.blogspot.nl
Check the haroldbot thread for the supported commands and syntax.
You can use haroldbot from this website.

Offline felice

  • LV0 Newcomer (Next: 5)
  • Posts: 2
  • Rating: +0/-0
    • View Profile
Re: SharpAsm - use assembly directly from C#
« Reply #6 on: October 27, 2012, 11:29:37 am »
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
« Last Edit: October 27, 2012, 11:37:00 am by felice »

Offline Scipi

  • Omni Kitten Meow~ =^ω^=
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1547
  • Rating: +192/-3
  • Meow :3
    • View Profile
    • ScipiSoftware
Re: SharpAsm - use assembly directly from C#
« Reply #7 on: October 28, 2012, 01:52:58 am »
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.

Imma Cat! =^_^= :3 (It's an emoticon now!)
Spoiler For Things I find interesting:
Spoiler For AI Programming:
Spoiler For Shameless advertising:

Spoiler For OldSig:





Spoiler For IMPORTANT NEWS!:
Late last night, Quebec was invaded by a group calling themselves, "Omnimaga". Not much is known about these mysterious people except that they all carried calculators of some kind and they all seemed to converge on one house in particular. Experts estimate that the combined power of their fabled calculators is greater than all the worlds super computers put together. The group seems to be holding out in the home of a certain DJ_O, who the Omnimagians claim to be their founder. Such power has put the world at a standstill with everyone waiting to see what the Omnimagians will do...

Wait... This just in, the Omnimagians have sent the UN a list of demands that must be met or else the world will be "submitted to the wrath of Netham45's Lobster Army". Such demands include >9001 crates of peanuts, sacrificial blue lobsters, and a wide assortment of cherry flavored items. With such computing power stored in the hands of such people, we can only hope these demands are met.

In the wake of these events, we can only ask, Why? Why do these people make these demands, what caused them to gather, and what are their future plans...

Offline felice

  • LV0 Newcomer (Next: 5)
  • Posts: 2
  • Rating: +0/-0
    • View Profile
Re: SharpAsm - use assembly directly from C#
« Reply #8 on: October 29, 2012, 05:29:58 am »
Hi,

It's recognizing basic facial expression using ASM in C#.

Im looking for Active shape model in C# (SharpASM). Any idea?

Thanks
« Last Edit: October 29, 2012, 05:34:04 am by felice »

Offline Scipi

  • Omni Kitten Meow~ =^ω^=
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1547
  • Rating: +192/-3
  • Meow :3
    • View Profile
    • ScipiSoftware
Re: SharpAsm - use assembly directly from C#
« Reply #9 on: October 29, 2012, 12:51:32 pm »
Well, it seems like you would write the assembly in an Asm object.

https://sourceforge.net/projects/sharpassembler/

There's the sourceforge project which includes a readme. It should help. :)

Imma Cat! =^_^= :3 (It's an emoticon now!)
Spoiler For Things I find interesting:
Spoiler For AI Programming:
Spoiler For Shameless advertising:

Spoiler For OldSig:





Spoiler For IMPORTANT NEWS!:
Late last night, Quebec was invaded by a group calling themselves, "Omnimaga". Not much is known about these mysterious people except that they all carried calculators of some kind and they all seemed to converge on one house in particular. Experts estimate that the combined power of their fabled calculators is greater than all the worlds super computers put together. The group seems to be holding out in the home of a certain DJ_O, who the Omnimagians claim to be their founder. Such power has put the world at a standstill with everyone waiting to see what the Omnimagians will do...

Wait... This just in, the Omnimagians have sent the UN a list of demands that must be met or else the world will be "submitted to the wrath of Netham45's Lobster Army". Such demands include >9001 crates of peanuts, sacrificial blue lobsters, and a wide assortment of cherry flavored items. With such computing power stored in the hands of such people, we can only hope these demands are met.

In the wake of these events, we can only ask, Why? Why do these people make these demands, what caused them to gather, and what are their future plans...