News:

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

Macros

Started by AeroASM, June 18, 2005, 04:25:59 PM

Previous topic - Next topic

AeroASM

I want to make a macro that takes a string as an argument, and loops through each character in the string and for each character, assembles different instructions according to what the character is.

I fully understand the concept of macros, but I have no idea of where to start with this.

What MASM directives should I use?

Clueless

Hi Aero,
Just to help me understand, does this mean that if an 'm' is encountered, it might type 'mov' into the buffer?

Paul

AeroASM

Something like this:

DoStuff macro TheString
... this bit assembles as follows:
... "m" -> mov eax,ebx
... "n" -> mov ebx,eax
... "c" -> nop
endm

Then:

DoStuff "mmnccmn"
;becomes
mov eax,ebx
mov eax,ebx
mov ebx,eax
nop
nop
mov eax,ebx
mov ebx,eax

Clueless

So you want to create an index into a table.  Not hard to do but the macro will have a lot of if statements.  Not a problem, though.  Your idea has the potential to be a real finger saver!

Paul

Jeff

you could use the FORC macro directive.  it iterates through each literal character in a string (including quotes) so that you may do stuff with it.  remember, using macro special characters (!&<>) require a preceeding escape character (!).

so i guess you could try somthing like this:
DoStuff MACRO string
    FORC char,<string>
        IFIDNI <char>,<">
            ;Do nothing
        ELIFIDNI <char>,<m>
            MOV eax,ebx
        ELIFIDNI <char>,<n>
            MOV ebx,eax
        ELIFIDNI <char>,<c>
            NOP
        ENDIF
    ENDM
ENDM

AeroASM

Thanks! Just what I needed.

daydreamer

cool, so if you have max of 256 chars on a line, you could write a small program on one line, with max 255 opcodes
at the same time contain data in that string
:bdg
you could also combine it with a macro/proc library that simulates, highlevel statements and each char writes one of these macros/calls to proc


AeroASM

Problem: DoStuff !> fails to work.

Jeff

Quote from: AeroASM on June 19, 2005, 09:21:09 AM
Problem: DoStuff !> fails to work.
try DoStuff <!>>.  if that fails, i'm not sure what to do.