News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

masm32 macro programming

Started by samk, February 04, 2009, 08:06:50 AM

Previous topic - Next topic

samk

Hi, I'm relatively new to masm32 programming. Below is a minor problem I'm facing ....

@ArgI MACRO index:REQ, arglist:VARARG
   LOCAL count, retstr
   retstr TEXTEQU <>
   count = 0
   FOR arg, <arglist>
      count = count + 1
      IF count EQ index
         retstr TEXTEQU <arg>
         EXITM
      ENDIF
   ENDM
   EXITM retstr
ENDM

.code
GetArgs proc errList:DWORD
   xor ebx,ebx
   .while ebx<10
      @ArgI ebx,errList
      invoke MessageBox,hWnd,eax,NULL,MB_OK
      inc ebx
   .endw
   ret
GetArgs endp

This returns error during compile time. The problem is that the macro @ArgI expects a numerical value and can't handle register ebx in the 'index' parm.

I know that the above proc could be rewritten w/o using the macro, but I faced a similar problem in another macro that I wrote in oop wherein the use of that macro is crucial.

How do I rewrite the macro to change the register 'value' in 'index' into its real numercial value (0,1,2...) before comparing with 'count'?


Jimg

Basically, you have to understand the difference between assembling and executing a program.  Macros happen at assembly time, there is no value in a register that can be compared at assembly time, the values in registers only exist when the program is executed.  When the program starts execution, the macro/assembler instructions, like for, if, eq, etc. have all already been done by the assembler and no longer exist. At execution time, you can only execute cpu intructions, not macro commands.

samk

Thank u for ur reply. Point taken. My earlier query was based on the debug results wherein the compiler is taking 'ebx' as is as text. In the same example, if I use GetArgs to get one argument only, say #5, and replace ebx with 5, it will produce no error. This in a way clarifies ur point.

My example returns an error - 'constant expected' during assembly, hence, I can't compile or execute it. I think I should re-state my query.

What changes should I make to the macro so that it will compile w/o errors?


MichaelW

What is passed to the procedure in errList?
eschew obfuscation

Jimg

As Michael is hinting, you are calling your proc with a single dword, not 10 things, so it all depends upon what "errList" really represents.

I can think of three possibilities immediately, and the code for each is very different, so you'll have to be more precise in your questions, just as you have to be precise in your programming.