Hello,  :)

I know c programming, and im currently learning asm (masm).  Im interested in combining asm with c, but its still new to me and i dont know which direction to take on it to start learning.  Im wondering would it matter which asm assembler i learn because the syntax is different in each?

-also  i hear there are some different opinions on masm, that it isnt as fast as others, etc.  If i learn masm, and decide to move onto an other assembler; would it be easy to code in the other one and still remember much about masm?
Posted on 2006-06-22 18:12:58 by Macleon
How do you wish to combine them?

You can use inline assembly in your C compiler. Or you can utilize a linker to combine the object files into the overall binary.

The first method is "easier", but not necessarily "clean". The second method is "clean", but can get tedious.
Posted on 2006-06-23 01:39:23 by SpooK
I actually use ASM with C alot on various projects. You're question would probably be easier to answer if you defined the C compiler you are planning to use. If you plan to use a GCC based compiler (MingW or DJGPP) then you are in for an uphill battle when converting between MASM and inline assembly. Truth be told, once you learn Assembly, the various syntaxes aren't that hard to adjust to, but can be tedious depending on skill level.

I honestly find the easiest way is to write a library file (.lib) using assembly then link it into the C object file using it's linker. When starting out this is generally the prefered method, and keeps your assembly code seperated from your C code. The alternative is to use the __asm keyword to include the assembly code directly into your source. I use PellesC for most of my Win32 C programming needs so doing such is as simple as:

#include <stdio.h>

int g_count = 70;

int main ( int argc, char * argv[] ) {
  printf ( "Looping %d times...", g_count );
  __asm { mov ecx, g_count };
again:
  __asm {
      dec ecx
      or ecx, 0
      jne again
  };
  puts ( "done" );
  return ( 0 );
}


But you should note that this style of programming is compiler specific as some compilers use different syntaxes and different forms of the __asm keyword. The best place to find information on this would be the compiler's user manual or emailing the authors for links to help groups. You can also (sometimes) find usefull information on various newsgroups.

Regards,
Bryant Keller
Posted on 2006-06-23 03:07:22 by Synfire
I would advice you to use external .asm modules and mostly forget about inline asm. That way you can use the full features of whatever assembler you choose, and it's easier to switch to a different C compiler should you want to do that.

Posted on 2006-06-23 06:45:49 by f0dder
oh thats going to be stressful if each c compiler uses different syntax.  Im going to stick with asm assembler for now; best option.  thank you guys. :)  Is masm a good choice for sticking with?

I was curious what did you mean by this:
"you can utilize a linker to combine the object files into the overall binary."
Posted on 2006-06-23 10:05:56 by Macleon

Is masm a good choice for sticking with?

It's a pretty decent assembler, yes.


I was curious what did you mean by this:
"you can utilize a linker to combine the object files into the overall binary."



cl /c program.c
ml /c module.asm
link program.obj module.obj

Posted on 2006-06-23 10:57:44 by f0dder