The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: korte on March 05, 2007, 09:45:51 AM

Title: macro definition
Post by: korte on March 05, 2007, 09:45:51 AM

I want to define C styile function with macro.

sample:

    FunctionName (param1,param2)

how to filter bracket ( )?

FunctionName macro p1,p2
  push p2
  push p1
  call myfunct
endm


Title: Re: macro definition
Post by: sinsi on March 05, 2007, 10:54:50 AM
Just omit the brackets

FunctionName macro p1,p2
  push p2
  push p1
  call myfunct
endm

.code

...
FunctionName eax,OFFSET blah
...

This is the simplest form - there are many, many different ways (angle brackets, returning a value, ...)
Title: Re: macro definition
Post by: korte on March 05, 2007, 11:05:14 AM
ok.

But I want to use bracket macro calling.

FunctionName (par1,par2)

I want C style  code

CreateWindow(p1,p2,p3,p4)
Title: Re: macro definition
Post by: gfalen on March 05, 2007, 11:09:38 AM

FunctionName macro p1,p2
  push p2
  push p1
  call myfunct
  exitm <>
endm
Title: Re: macro definition
Post by: sinsi on March 05, 2007, 11:19:26 AM
Quote from: korte on March 05, 2007, 11:05:14 AM
I want C style  code

So use C :bg

MASM won't let you use brackets without some fancy stuff...
And really, what's so good about brackets? just more typing
Title: Re: macro definition
Post by: korte on March 05, 2007, 11:46:01 AM
I want to create portable code. ASM betwen C.
Define all procedure to macro.

Perfectly work but missing ugly bracket.
Title: Re: macro definition
Post by: korte on March 05, 2007, 11:47:06 AM
gfalen

exitm <> ???

Title: Re: macro definition
Post by: sinsi on March 05, 2007, 12:00:43 PM
Quote from: korte on March 05, 2007, 11:46:01 AM
I want to create portable code. ASM betwen C.

I can see C being portable (with a lot of conditionals) but ASM (at least MASM/ML) is processor-specific - the Intel x86 instruction set.
AFAIK macros only work with MASM (Macro ASseMbler) but I could be wrong - I can (sort of) figure out C/C++ code but
couldn't write a "Hello World" program in C to save my mother...

Maybe you want to create .obj files in MASM to link with C?
Title: Re: macro definition
Post by: Timbo on March 05, 2007, 08:06:09 PM
Greetings,

Unless I am mistaken, what korte wants to do is to allow his .asm modules to conditionally call C-style functions that are defined elsewhere (a la VS 2005 perhaps?) by the means of macro definition.  Maybe something like the following?
ifdef _DEBUG
DoSomethingCool MACRO p1, p2
push p2
push p1
call MyCoolFunc_d ;debug version of function
endm
else
DoSomethingCool MACRO p1, p2
push p2
push p1
call MyCoolFunc  ;release version
endm
endif
This is just an example.  Hope it helps.
Tim