I tried writing a Macro that does the same thing as the RGB macro in C.

Here is what I did - doesn't work, maybe you guys can point out the flaw

RGB MACRO red,green,blue
mov eax, red
mov ebx, green
mov ecx, blue
shl ebx, 16
shl ecx, 8
or ecx,ebx
or eax,ecx

I would like to use the Macro in a way similar to that of C

ie. mov wc.hbrBackground, RGB 255,255,255

is this possible or do I do the RGB seperately then mov eax into the struct member?

RGB 255,255,255
mov wc.hbrBackground, eax

Posted on 2001-12-31 15:15:00 by Rockinronstar
sorry, using Masm 6.15
Posted on 2001-12-31 15:15:45 by Rockinronstar
Sure its possible! (Tip) Spend some time are *learn* macros if you really like MASM!, they are the best tool you can have :)

Back to your question:

You can streamline your macro a bit by avoiding the extra registers (this was ripped from Iczelions' tutorial #5 (above links in main)):

RGB macro red,green,blue
xor eax,eax
mov ah,blue
shl eax,8
mov ah,green
mov al,red

Now this is used as:

RGB 2,4,6
mov Here, eax

But to continue your question, you can also make it "inline" as i like to call it by using one more macro directive called exitm < .... >

Exitm means Exit Macro with <> . Remember the <> braces indicate a stinge of ascii information for the compiler to interperet. So for your uses, you would want to exit the macro with a string saying "eax" such that it will work properly in your mov command.

The ammendments:

RGB macro red,green,blue
xor eax,eax
mov ah,blue
shl eax,8
mov ah,green
mov al,red
EXITM <eax>

Now after the macro scpit is ran, the macro RBG itself will be replaced with "eax" where ever it is found... so now it will be easily used as you wanted it to be:

mov SomeColorValue, RGB( 4, 6, 8 ) ; best to use brackets with EXITM

Hope this helps!
Posted on 2001-12-31 15:42:52 by NaN
thanx Nan. Big help. I actually saw one of my problems why my Macro wasn't working, kina embarrasing actually, haha

i was trying to move a color value into wc.hbrBackground
when it actually requires a handle to a brush, woops!!

I used your optimized macro though. I expect it is going to be very useful!!

I even used it in creating the brush ie.
invoke CreateSolidBrush, RGB(255,255,255)

definately gonna be useful.
thanx for that return value info. I was reading the MASM 6.1 doc and I thought it said that you can only use the EXITM <> with a nested macro, ie
RGB2 MACRO r,g,b
EXITM <eax>

glad you cleared that up or I may never have used it
Posted on 2001-12-31 16:30:44 by Rockinronstar
If the values are all constants:
cRGB macro red,green,blue

EXITM %((red SHL 16) OR (green SHL 8) or blue)

mov eax,cRGB(128,128,128)
mov Color,cRGB(192,128,64)
+ No code generated.
- No error checking on the range, but you could add it too the macro. ;)
Posted on 2001-12-31 21:06:35 by bitRAKE
thanx BitRake - added both to my Macro File
both Macros will be useful. I have changed my code to use yours since they were constant values. No sense using cycles to calc stuff that can be precalculated in compile time.

The other Macro will be good for my palette cycling stuff

thanx guys
Posted on 2001-12-31 21:36:25 by Rockinronstar