Archived

This topic is now archived and is closed to further replies.

goldsword

ASM question (IMUL, MUL etc)

Recommended Posts

Hi, I''m trying to code my alpha blending routine in inline ASM on MVS 6 and I''m run into a little problem... When I multiply my RGB values the result is far from right, i know its the imul command I use which causes the problem since I can do an additive blending in ASM... Heres a little bit of the code... mov edx, dwAlpha; // Store the alpha value in edx (0 - 255) mov eax, isr; // The red channel of the source mov ebx, idr, // The red channel of the dest sub eax, ebx; // Subtract the dest from the source store in eax shr eax, 8; // Divide by 256 imul eax, edx; // Multiple alpha with eax... Now, shouldnt eax contain the finnished value? I think I should use imul since eax is an integer... because of the subtraction it can be negative (signed) and imul should be able to handle signed values right? Please, I really suxs at asm... I''m also very dissapointed... my ASM routine is actully not faster then the asm generated by the compiler, should I store my values in other registers (like MMX register?) What are the names of MMX registers? Or is it just impossible to perform a full screen alpha blend in software on 640x480x32? Must I switch to 16 bit color to get a somewhat decent performance? Thanks!

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
> shr eax, 8; // Divide by 256
> imul eax, edx; // Multiple alpha with eax...

That''s the problem. You shift an 8 bit value (the difference in eax) by 8 bits to the right, you''re in fact zeroing it out. Just inverse both lines:

imul eax, edx; // Multiple alpha with eax...
shr eax, 8; // Divide by 256
Now the multiply will generate a 16bit value, and this gets divided by 256 by the shr.

Don''t forget to add your dest value to the result afterwards:
add eax, ebx

To the speed: yes, that''s a slow way of doing it. You should use lookup tables to speed up alphablending. There are tutorials about that here on Gamedev in the reference section.

- AH

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Oh, forgot to mention: don''t use SHR, use SAR, since the difference value can get negative.

- AH

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Have a look at FBlend (http://sf.net/projects/fblend/ ) for doing fast alpha blending (it''s the "trans" blender). The MMX code should be ~3 times faster then the C code (2x for larger sprites - memory bandwith problem).

Share this post


Link to post
Share on other sites