BBC BASIC for Windows
Programming >> Assembly Language Programming >> Testing if MSB of 32-bit word is < 255
http://bb4w.conforums.com/index.cgi?board=assembler&action=display&num=1294904598

Testing if MSB of 32-bit word is < 255
Post by David Williams 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.






Re: Testing if MSB of 32-bit word is < 255
Post by admin 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.

Re: Testing if MSB of 32-bit word is < 255
Post by David Williams 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.

Re: Testing if MSB of 32-bit word is < 255
Post by admin 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.