If someone could help me optimizing the following code, I would be very greatful :



xor eax,eax

mov al, byte ptr[oldcolor+0];
add eax,intens
cmp eax,0
jnl @rOK1
xor eax,eax
@rOK1:
cmp eax,255
jna @rOK2
mov eax,255
@rOK2:
mov BYTE PTR[newcolor],al

mov al, byte ptr[oldcolor+1];
add eax,intens
cmp eax,0
jnl @gOK1
xor eax,eax
@gOK1:
cmp eax,255
jna @gOK2
mov eax,255
@gOK2:
mov BYTE PTR[newcolor+1],al

mov al, byte ptr[oldcolor+2];
add eax,intens
cmp eax,0
jnl @bOK1
xor eax,eax
@bOK1:
cmp eax,255
jna @bOK2
mov eax,255
@bOK2:
mov BYTE PTR[newcolor+2],al


The above code adds the value of "intens" to the r,g and b values of "oldcolor" and saves the new value to "newcolor" (newcolor==a ligther/darker version of oldcolor). r,g & b must be between 0h and FFh.

I read somewhere that some MMX-intructions handles the range check automaticly when adding numbers, but I don't know anything about MMX so I thought someone could help me with this (if it's possible).

/Delight
Posted on 2002-06-03 14:18:19 by Delight
Posted on 2002-06-03 14:40:57 by bitRAKE