Re: HELP! >MASM CALLING C FUNCTIONS.. FROM ASM :)

From: hutch-- (hutch_at_movsd.com)
Date: 11/23/03


Date: 22 Nov 2003 21:25:55 -0800

steve),

> > .386
> > .387
> > .model FLAT,STDCALL
> > .code
> > org 100
> >
> > ;sections below commented out would not LINK!!!!!!!
> > _start_code:
> > ;extern func1:far
> > mov eax,00abcdefh
> > ;call func1
> >
> > end _start_code

There are a number of things you must get right first, to use a C
library you need to use the "includelib" syntax so the assembler knows
where to find the library.

includelib My_C_Library.lib

To call a function in the C library you must write a prototype for it
and specify the calling convention. It will usually be C but it can
also be STDCALL.

MyCfunc PROTO C :DWORD,:DWORD

Then you can call it using the INVOKE syntax.

invoke MyCfunc,arg1,arg2

To terminate the program, you need to use the API call ExitProcess.

invoke ExitProcess,0

If you don't have the MASM32 include files, you need a prototype and a
library for that API call.

include kernel32.lib
ExitProcess PROTO :DWORD

I would recommend you get the MASM32 project at www.masm32.com as it
has all of the include files and a lot of other toys that are useful
in writing assembler projects.

Regards,

hutch at movsd dot com



Relevant Pages

  • Re: My view on this "Is blah an assembler"
    ... > means it would be an Assembler. ... Assembly language lacks higher-level logical ... inconsistent and ambiguous syntax (that directly ... > mov eax MySymbolic; Adress ...
    (alt.lang.asm)
  • Re: To C.
    ... to the member's label inside the structure ... relative offset of the data from the start of the structure... ... As NASM or any other "real assembler", as you like to put it, ... whatever strange syntax is accepted... ...
    (alt.lang.asm)
  • Re: HLA is a text converter (text to object code)
    ... I don't mind the HLA variable declarations and function ... They exist to help allow beginning programmers to write ... > syntax, newcomers can apply all the style guidelines they've used ... > who already use another assembler. ...
    (alt.lang.asm)
  • Re: Why there are so many assemblers.
    ... "Intel Syntax" means that the assembler uses the language grammar ... NASM doesn't use that grammar. ... it is not an "Intel Syntax" assembler. ...
    (alt.lang.asm)
  • Re: HLAs
    ... Uh, first of all it was Intel, not Microsoft. ... Intel devised this syntax, that's why we call it an "Intel-syntax" ... assembler rather than a "Microsoft-syntax" assembler (though ...
    (comp.lang.asm.x86)