Well I finally had some free time to download the manuals heh.

I remember a thread on this, but all my searches are coming up with junk.
Doesnt matter I guess. Been playing around with macros again and I seem
to have come up with one possible solution steming from an interesting
side effect (depends on how you look at it). This perhaps is common knowledge
but its new to me and I havnt seen it discussed before so I thought I would
just throw it out there.

test MACRO arg1, arg2 arg3
ENDM

Doing alot of poking around, turns out that if you include parenths in the
call they end up in the parameters to the macro itself...

ie -> test( 1, 2, 3 )
arg1 "( 1"
arg2 "2"
arg3 "3 )"

which, normally, will create alot of errors... for those interested in this sort of
thing I have some cut and paste code for ya.

:notsure:
Goes in Windows.inc


; #########################################################################
; STCALL MACRO

stcall MACRO funcname:REQ,param,p1,p2,p3,p4,p5,p6,p7,p8,p9,p10,p11,p12,p13,p14,p15,p16,p17,p18,p19,p20
LOCAL pos,counter
counter=0
FOR arg,<p20,p19,p18,p17,p16,p15,p14,p13,p12,p11,p10,p9,p8,p7,p6,p5,p4,p3,p2,p1>
IFNB <arg>
counter=counter+1
pos=@InStr(1,arg,<ADDR>) OR @InStr(1,arg,<addr>) OR @InStr(1,arg,<Addr>)
IF pos
IF (OPATTR(@SubStr(arg,%pos+5))) EQ 98
lea eax,@SubStr(<arg>,%pos+5)
push eax
ELSE
push OFFSET @SubStr(<arg>,%pos+5)
ENDIF
ELSE
push arg
ENDIF
ENDIF
ENDM
IF counter NE param
tmp TEXTEQU %(@Line)
% echo Line : tmp , funcname , invalid number of parameters
.ERR
ENDIF
call funcname
ENDM

; #########################################################################
; INLINESTR MACRO

InlineStr MACRO Quoted_Text:VARARG
LOCAL Local_Text
DATA segment
ALIGN 4
Local_Text db Quoted_Text,0
ALIGN 4
DATA ends
EXITM <OFFSET Local_Text>
ENDM

; #########################################################################
; IMPLEMENTCFUNC MACRO

ImplementCFunc MACRO linkto:REQ, numargs:REQ, args:VARARG
LOCAL Temp,Pos
LOCAL BuildStr,ArgIter,CharIter,Count

IF numargs EQ 0 ;; function call w/ no args
stcall linkto, numargs, 0
ELSE
BuildStr TEXTEQU <>
Count = 0
FOR ArgIter:REQ, <args>
Temp TEXTEQU <ArgIter>
Count = Count + 1

;; strip opening parenth from function call
IF Count EQ 1
Temp TEXTEQU @SubStr( <%Temp>, 2 )
ENDIF
;; strip closing parenth from function call
IF Count EQ numargs
Temp TEXTEQU @SubStr( <%Temp>, 1, @SizeStr(<%Temp>)-1 )
ENDIF

;; strip leading spaces from params (if any)
% FORC CharIter, <Temp>
IFIDN <CharIter>, < >
Temp TEXTEQU @SubStr( <%Temp>, 2 )
ELSE
EXITM
ENDIF
ENDM

;; check for string and declare if needed
% FORC CharIter, <Temp>
IFIDN <CharIter>, <">
Temp TEXTEQU @CatStr( <InlineStr!(>, <%Temp>, <!)> )
ELSEIFIDN <CharIter>, <&>
Temp TEXTEQU @CatStr( <ADDR >, <@SubStr(<%Temp>,2)> )
ENDIF
EXITM
ENDM

BuildStr TEXTEQU @CatStr( <%BuildStr,>, <%Temp> )
ENDM

% stcall linkto,numargs&BuildStr
ENDIF
ENDM

; #########################################################################
; DEFINECFUNC MACRO

DefineCFunc MACRO funcname:REQ, linkto:REQ, numargs:REQ
EXTERNDEF linkto:PROC
funcname MACRO args:VARARG
ImplementCFunc linkto, numargs, args
ENDM
ENDM

; #########################################################################


:notsure: Goes in the other inc's (examples)
Note: You should comment out the regular declarations to prevent dup errors

User32.inc


DefineCFunc MessageBox, MessageBoxA@16, 4


Kernel32.inc


DefineCFunc ExitProcess, ExitProcess@4, 1


With these mods, it allows more C like calls in your code (if you really want this kinda thing).
Modified minimum.asm code from examples.


; #########################################################################

.386
.model flat, stdcall
option casemap :none ; case sensitive

; #########################################################################

include \masm32\include\windows.inc
include \masm32\include\user32.inc
include \masm32\include\kernel32.inc

includelib \masm32\lib\user32.lib
includelib \masm32\lib\kernel32.lib

; #########################################################################

.code

start:
jmp @F
szMsg db "Assembler Pure and Simple", 0
@@:

MessageBox( 0, "Minimum MASM", &szMsg, MB_OK )
ExitProcess( 0 )
end start


I plan on piddling with this some more so perhaps its not quite done yet. Oh yeah.
I have shamelessly cut and pasted some of the open source code from the board
to get this working. I do not have the original authors names so please excuse me
if your not properly credited for any snipplits that are yours.

The only new macro of interest that I filled in with is ImplementCFunc.

Enjoy.
:alright:
Posted on 2004-04-17 10:16:25 by Graebel
Hi,

So look like you are one that looked into my suggestion :grin:
Take a look at

http://www.asmcommunity.net/board/index.php?topic=17566
Posted on 2004-04-17 10:22:45 by roticv
Ahha! I knew that post was somewhere. Thanks for the link back =) just couldnt find it.

Once I figured out what the parser was doing, it wasnt really too hard to implement. I dont think I will personally use this, but who knows. If it can be extended enough it might not be so bad. A completely customizable language even down to the parser rules and operators would rock =)
Posted on 2004-04-17 11:51:15 by Graebel
Graebel,

Dou you need any extra information about the stcall macro? :)
Posted on 2004-04-18 03:55:54 by Vortex
Noop,
I know exactly what its doing and why. Just didnt see a need to reinvent the wheel... 8)
Posted on 2004-04-18 20:04:04 by Graebel