Article: x86 MASM32 Calling C Functions


09 December 2018

In this example I'll be using C functions, mixed with Windows API functions to write a small assembly game of number guessing. This means the .model language type can stay as stdcall for the Windows functions, however the main procedure denotes a "C" next to it to specify the C calling convention. It's also worth mentioning that there were many Visual C++ 2015 Conformance Changes that will require you to include additional libraries that are NOT included by default by the linker for VS 2017. For clarity, I declared includelib statements in my file for the following:

  • libcmt.lib
  • libvcruntime.lib
  • libucrt.lib
  • legacy_stdio_definitions.lib




Above shows a series of extern definitions and then calling them like you normally would. As I mentioned above, specify the C calling convention next to your PROC; however on your "END main" leave off the "main" as such:



Michael Petch: "Use 'end' on a line by itself. We don't want to use 'end main' as that would make this function our program entry point, effectively skipping by the C runtime initialization".