The MASM Forum Archive 2004 to 2012

General Forums => The Campus => Topic started by: AeroASM on June 18, 2005, 04:25:59 PM

Title: Macros
Post by: AeroASM on June 18, 2005, 04:25:59 PM
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?
Title: Re: Macros
Post by: Clueless on June 18, 2005, 04:30:33 PM
Hi Aero,
Just to help me understand, does this mean that if an 'm' is encountered, it might type 'mov' into the buffer?

Paul
Title: Re: Macros
Post by: AeroASM on June 18, 2005, 04:41:03 PM
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
Title: Re: Macros
Post by: Clueless on June 18, 2005, 04:45:20 PM
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
Title: Re: Macros
Post by: Jeff on June 18, 2005, 05:54:33 PM
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
Title: Re: Macros
Post by: AeroASM on June 18, 2005, 06:18:42 PM
Thanks! Just what I needed.
Title: Re: Macros
Post by: daydreamer on June 18, 2005, 11:02:56 PM
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

Title: Re: Macros
Post by: AeroASM on June 19, 2005, 09:21:09 AM
Problem: DoStuff !> fails to work.
Title: Re: Macros
Post by: Jeff on June 20, 2005, 06:56:38 AM
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.