this night i was sitting and translated this RGB macro in C++ to assembler:


#define RGB(r, g ,b) ((DWORD) (((BYTE) (r) | \
((WORD) (g) << 8)) | \
(((DWORD) (BYTE) (b)) << 16)))




mRGB MACRO R,G,B
mov eax,R
mov ecx,G
shl ecx,8
or eax,ecx
mov ecx,B
shl ecx,16
or eax,ecx
endm


well, i'm sure about that there are some better (smaller and faster) macro for this but hey, its my first own macro that do something good and is useful for me :tongue:
Posted on 2004-03-20 03:56:05 by bj1500
That macro would need a lot of work to be as flexible as the C macro... anyway, how often are you going to use it with non-constant arguments? If you only need constant arguments, it can be made as efficient as the C macro.

Bitrake posted this constant-only macro in another thread:


RGB MACRO red,green,blue
EXITM %((blue SHL 16) OR (green SHL 8) OR (blue))
ENDM


I think I saw one funky RGB macro that did checks on the argument to generate code if necessary, but I couldn't find it. This macro should be just fine though, unless you want the macro to work with non-constant arguments.
Posted on 2004-03-20 04:25:32 by f0dder
i'm going use it like this:



mRGB 255,255,255
invoke CreateSolidBrush,eax
mov brush,eax
invoke GetClientRect,hWnd,addr rect
invoke FillRect,hhdc,addr rect,brush


and it works perfect. :)
Posted on 2004-03-20 04:42:07 by bj1500
If you're going to use it like this, the RGB macro from bitrake is a lot better...


invoke CreateSolidBrush, RGB(255,255,255)

With *no* code generation overhead, the RGB value is pushed directly.
Posted on 2004-03-20 04:52:41 by f0dder
well, i dont really understand his macro
What does the EXITM do?
how can i make a makro so i can call it like you do here:
invoke CreateSolidBrush, RGB(255,255,255)
with the () ??
Posted on 2004-03-20 05:17:30 by bj1500
EXITM will return the result in-line so you can use the macro in invoke statements etc...
Posted on 2004-03-20 05:22:09 by donkey
BitRakes MACRO dosent work as it should.
RGB(0,0,255) does NOT be blue.
RGB(0,255,255) will be white

my macro works better :/
Posted on 2004-03-20 10:30:39 by bj1500
:(

I remember that thread, there was a typo in the macro but I figured it was self-evident so I didn't comment on it...
It should be like this:


RGB MACRO red,green,blue
EXITM %((blue SHL 16) OR (green SHL 8) OR ([COLOR=red]red[/COLOR]))
ENDM

The error is so silly I didn't realize either until I actually had to use the macro.
Posted on 2004-03-20 10:47:01 by QvasiModo
:mad: so stupid of me, of course it should be red there :(
Posted on 2004-03-20 10:50:29 by bj1500
heh, you didn't catch the obvious flaw ;)


RGB MACRO red,green,blue
EXITM %((blue SHL 16) OR (green SHL 8) OR ([b]red[/b]))
ENDM
Posted on 2004-03-20 10:50:55 by f0dder