BBC BASIC for Windows
« Testing if MSB of 32-bit word is < 255 »

Welcome Guest. Please Login or Register.
Apr 5th, 2018, 10:29pm



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

If you require a dump of the post on your message board, please come to the support board and request it.


Thank you Conforums members.

BBC BASIC for Windows Resources
Online BBC BASIC for Windows documentation
BBC BASIC for Windows Beginners' Tutorial
BBC BASIC Home Page
BBC BASIC on Rosetta Code
BBC BASIC discussion group
BBC BASIC for Windows Programmers' Reference

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Testing if MSB of 32-bit word is < 255  (Read 1225 times)
David Williams
Developer

member is offline

Avatar

meh


PM

Gender: Male
Posts: 452
xx 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.





User IP Logged

admin
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM


Posts: 1145
xx 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 » User IP Logged

David Williams
Developer

member is offline

Avatar

meh


PM

Gender: Male
Posts: 452
xx 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.
User IP Logged

admin
Administrator
ImageImageImageImageImage


member is offline

Avatar




PM


Posts: 1145
xx 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.
User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls