Say we have a 32-bit value in a register: r0 = 0x12345678; The task is to get the low half-word part, which is 0x5678 (or alternatively nullify the high half-word).
In terms of C code that's equivalent to: r0 = r0 & 0xFFFF;
Limitations: it needs to be done in a single ARM7TDMI instruction without using other registers. This is motivated by the fact that getting the high half is just a right shift like LSR r0, r0, #16
.
So far I can do it either in 2 instructions: left shift + right shift, rotate + shift; or by using an additional register containing a mask 0xFFFF and AND-ing.
On ARM7TDMI it's not possible to just AND with a constant like 0xFFFF, because it doesn't fit into the immediate value scheme.
In addition it looks like that modern ARM-s have "MOVT" which solves it by doing MOVT r0, #0
, but ARM7TDMI doesn't have it!
I want to believe that it's possible without MOVT, because it's such a basic thing.
0x0000FFFF
in another register that you set up outside a loop? – Peter Cordes