Use this, all you like but remember who wrote it. I want credit. Big Bad Bob/Bobby/Robert Kolski rkolski@socal.rr.com -websiteless for now- It is very important to make you programs readable. This way you know what your program is doing. (If you know of anything else that can be done please post) MACROs are an important key in doing this. I wrote a few loop macros and such that make code more readable. Also I wrote some FUNCTION macros that return a value and use parenthesis. What? Parenthesis around Parameters? In assembly? YES Let's take a look at the RGB macro can it be rewritten? Yes!

RGB MACRO red, green, blue
   xor eax, eax
   mov al, blue    ; blue
   rol eax, 8
   mov al, green   ; green
   rol eax, 8
   mov al, red     ; red
ENDM

RGBFunc MACRO red, green, blue
   LOCAL Value
   Value = blue * 10000h + green * 100h + blue
   EXITM %Value
ENDM
It may be used like this:
mov   eax,RGBFunc(255,0,0) ;eax=red
Not only does this provide flexibility, you can now MOVe the result into any register you want or even use it for initializing data in your data section, but now the mov is one instruction instead of 6! Now lets look at how to use this to make a standard to call functions that return: - 4 bytes (DWORD/UINT/LONG/etc. in eax) - nothing (void) - A real number in FPU stack The prefix F_ should denote a function that returns something in eax The prefix S_ should denote a void functnion also known as a subroutine. The prefix R_ should denote a function that returns a real number Trick:
mov wc.hIcon,F_LoadIcon(hInst,IconID)

F_LoadIcon MACRO hInst,IconID
   Invoke LoadIcon,hInst,IconID
   EXITM 
ENDM
Look! eax is returned as a result of putting the macro in your code, first the corresponding api call is Invoked and then eax is sent to the instruction that is at the beginning of the line. This makes the mov look very similar to how would look in a hll. The advantage is it looks more intuitive and you would be invokeing the function and useing eax or passing eax to your next invoke anyway. i.e.
Invoke func,a,b,F_somefunc(params)
The code assembled looks identical but your source is easier to read. How about a for loop?
ForLoop ,,
   repeat this
EndFor
just like in c/c++ but init and inc take assembly mnemonics. the test works just like in .IF statements all of these parameters must be enclosed in angle brackets so when using <,<=,>,>=,!=, and ! it might look weird i.e. !<,!<=,!>,!>=,!!=, and !!. This is because of the <>. ex)
ForLoop ,,
it keeps going until ecx=10 The macros:
ForLoop MACRO init,testcond,incr
   LOCAL SkipOver
   &init&
   jmp SkipOver
   .While TRUE
      &incr&
    SkipOver:
ENDM

EndFor MACRO
   .ENDW
ENDM
Thank you for being interested! Questions, Comments, etc. Please Post.
Posted on 2001-04-10 19:00:00 by BigBadBob
I also use MACROs for register renaming. In complex algorithms, late at night, you can lose track of that one letter difference between 'eax' and 'ecx'! Most of the debug I've done was in finding dumb typing errors. You could combine your RGB MACROs into one! :) Why have many names for the same thing?

    RGB eax, 128, 128, 128  ;doesn't this look pretty?
    RGB edx, eax, esi, edi
    RGB esi,  96,  ah, ecx  ;how much flexiblity?
When the parameters are all constant the macro should conbine them internally. It wouldn't be too hard to allow any combination of registers and constants, and produce optimal code in all cases. :P
Posted on 2001-04-11 13:56:00 by bitRAKE