Creating a Hello World library function in assembly and calling it from C#

Posted by Filip Ekberg on Stack Overflow See other posts from Stack Overflow or by Filip Ekberg
Published on 2010-05-18T11:10:46Z Indexed on 2010/05/18 11:30 UTC
Read the original article Hit count: 324

Filed under:
|
|
|
|

Let's say we use NASM as they do in this answer: how to write hellow world in assembly under windows.

I got a couple of thoughts and questions regarding assembly combined with c# or any other .net languages for that matter.

First of all I want to be able to create a library that has the following function HelloWorld that takes this parameter:

  • Name

In C# the method signature would looke like this: void HelloWorld(string name) and it would print out something like

Hello World from name

I've searched around a bit but can't find that much good and clean material for this to get me started. I know some basic assembly from before mostly gasthough.

So any pointers in the right direction is very much apprechiated.

To sum it up

  • Create a function in ASM ( NASM ) that takes one or more parameters
  • Compile and create a library of the above functionality
  • Include the library in any .net language
  • Call the included library function

Bonus features

  • How does one handle returned values?
  • Is it possible to write the ASM-method inline?

When creating libraries in assembly or c, you do follow a certain "pre defined" way, the c calling convetion, correct?

© Stack Overflow or respective owner

Related posts about .NET

Related posts about c#