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.

Byte manipulation

Hi,

When I tried move a byte, as shown below

MOV.B           R12, R13

The upper byte of R13 is cleared, but I need to move lower byte of R12 to R13 without effecting upper byte of R13, is it possible?

Similarly, what is the difference of CLR.B and CLR, both clears full word!

Thanking You,

Ras

  • Hi Ras, 

    before you move the lower byte of R12, save its value in a different register. So to say, make a copy of it and you will have both upper and lower byte. 

    I have never used this clr instructions, but i think clr.b clears one bit and other entire word!!

    Hope it helps. 

    Vidya

  • Hi,

    MOV.B moves the lower byte to destination and also clears upper byte of destination, Similarly both clr.b and clr.w clears the full word. I would like to know if there was any mistake from my side.

    Yes, there are different methods to do this job, by using 'AND' / 'OR' instructions.

    Regards

    Ras

  • Ras said:
    I need to move lower byte of R12 to R13 without effecting upper byte of R13

    Well, the equivalent operation in C woudl be

    [code]R13 = (R13 & 0x00FF) || (R12 & 0xFF00);[/code]

    You see, this are three operations. And two intermediate results. You won't get away with less in assembly.

    MOV.B R12, R14; clear upper byte of R12 and move it into R14
    BIC #0xFF, R13;  clear lower byte of R13
    BIS R14, R13 ; add the two

    If you don' tneed R12 anymore after this, you can excahnge the first isntruction by MOV.B R12, R12 adn then do a final  BIS R12, R13.

    Ras said:
    Similarly, what is the difference of CLR.B and CLR, both clears full word!

    There is no CLR instruction. It's an emulated one and replaed with a MOV #0, dst (which is a one-word, one-cycle instruction due to the constant generator)

    And MOV is available as .W or .B, even if it has the same result with #0 as source. Hence the two CLR derivates. It's logical. After a CLR, the target is clear - not just half of it. The CLR.B is just there for completeness. Or "orthogonality".

    If you just want to clear the lower byte and not both, use BIC #0xFF, dst

**Attention** This is a public forum