Author |
Topic: Testing if MSB of 32-bit word is < 255 (Read 1225 times) |
|
David Williams
Developer
member is offline

meh

Gender: 
Posts: 452
|
 |
Testing if MSB of 32-bit word is < 255
« Thread started on: Jan 13th, 2011, 06:43am » |
|
This is probably embarassingly trivial.
I have a 32-bit ARGB pixel stored in a register, EDX:
EDX = &AaRrGgBb
I'd like to test if the MSB (&Aa) is less than 255 without having to copy (preserve) EDX then shift it:
Code:
mov ebx, edx ; copy EDX
shr edx, 24 ; shift alpha value to range 0 - 255
cmp edx, &FF ; is alpha < 255 ?
jl blendpxl ; branch if so...
Incidentally, I expected cmp dl, &FF to be equivalent (in this case) to cmp edx, &FF, and it's the not realising this fact that resulted in over an hour of frustrating bug-hunting in the early hours of this morn!
Regards, David.
|
|
Logged
|
|
|
|
admin
Administrator
member is offline


Posts: 1145
|
 |
Re: Testing if MSB of 32-bit word is < 255
« Reply #1 on: Jan 13th, 2011, 10:13am » |
|
on Jan 13th, 2011, 06:43am, David Williams wrote:I have a 32-bit ARGB pixel stored in a register, EDX: EDX = &AaRrGgBb I'd like to test if the MSB (&Aa) is less than 255 without having to copy (preserve) EDX then shift it: |
|
This is what I'd do:
Code: cmp edx,&FF000000
jb MSbytelessthan255 Richard.
|
« Last Edit: Jan 13th, 2011, 10:48am by admin » |
Logged
|
|
|
|
David Williams
Developer
member is offline

meh

Gender: 
Posts: 452
|
 |
Re: Testing if MSB of 32-bit word is < 255
« Reply #2 on: Jan 13th, 2011, 10:58am » |
|
on Jan 13th, 2011, 10:13am, Richard Russell wrote:This is what I'd do:
Code: cmp edx,&FF000000
jb MSbytelessthan255 Richard. |
|
Thanks for that, Richard.
|
|
Logged
|
|
|
|
admin
Administrator
member is offline


Posts: 1145
|
 |
Re: Testing if MSB of 32-bit word is < 255
« Reply #3 on: Jan 15th, 2011, 09:35am » |
|
on Jan 13th, 2011, 06:43am, David Williams wrote:Incidentally, I expected cmp dl, &FF to be equivalent (in this case) to cmp edx, &FF |
|
I expect you realise this now, but the reason they differed is that you used an unsigned shift (shr) followed by a signed compare (jl).
Had you paired them correctly (both signed: sar and jl, or both unsigned: shr and jb) they would indeed have been equivalent.
Richard.
|
|
Logged
|
|
|
|
|