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 routine 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?
Something like this should get you a working DLL:
You then just need to call the ‘hello’ function using P/Invoke. It doesn’t clean up after itself, so you need to set CallingConvention to Cdecl; you also need to tell it you’re using ANSI strings. Untested, but it should work fine.