This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Testing LSB/MSB?



I am trying to determine the MSB/LSB in an 8/16 bit (currently unsigned)  number as part of a larger function using assembly operations.  I have done some investigating to try and determine some way to do this but I am still at a loss, could someone please point me in the right direction?

For reference, this is my code/pseudo-code that would implement it:

-------
GET LSB
cmp.b/w, LSB,#1
jeq / jne DESTINATION
___

EDIT:  Would the BIT.B/W instruction suffice?  The issue now becomes, how do I test the LSB and only the lsb?

  • In assembly language, the processor actually doesn't care for signed/unsigned. There are some operations that support signed operation (like sign-extension on 8 bit operations to 16 bit registers) but this difference exists only for this signle instruciton and after this, the value is again just a row of bits.

    To test the LSB, you only need to do BIT #1, target (where target is a memory location or register to test).
    For the MSB, of course you'll need to know whether it is a byte or word value and do BIT #0x80, target for a byte or BIT #0x8000, target for a word value.
    Alternatively you might do TST.W, target or TST.B, target (to get N bit set if MSB is set).
    TST is actually a CMP[.B] #0, target

  • Ok, thank you for clarifying this; until now, I was unclear as to the differences between BIT and CMP.

  • Ben Daniels said:
    I was unclear as to the differences between BIT and CMP.

    BIT is actually an AND operation that discards the resulting value. While CMP is a subtraction, too without writing the result. Both set the status flags according to the operation result.

**Attention** This is a public forum