Hello Paul,
My suggestion is to compile your code above, then look at compiler generated assembly listing.
I have spent many hours studying the ARM and ARM thumb instruction set, and have realized that you cant just load registers with immediate data, and perform logical operations as you would with a CISC processor. ARM is a RISC processor. Sometimes it takes two or more ARM instructions to do simple operations. Also, I have found that the tools for compiling and assembling ARM instruction do some magic in that they encode what appears to be simple instructions, into complex operations. For example, a MOV r0,# instruction can be converted to a LDR instruction if the immediate data can not fit into the operand. With the LDR instructions, the immediate value is converted to a constant in memory, and loaded. Also, I have seen some compilers convert a MOV r0,# to a MOV R0,# followed by and ADD R0,# to load the desired operand.
One thing that puzzled me for some time is that the ARM instruction set shows that the immediate data in a MOV rN,#data can only be 8 bit data, but when I look at dissassembled code from a compiler I see things like :
mov r3, #28672 . How can this be? Its because although the operand is only 8 bits, there can be a 4 bit shift value which rotates the 8 bit value right by the desired amount. For this case its 7 rotated right 4 times. Any value that cannot be loaded with this method is pieced together either with MOV's and ADD's or LDR
Hope this helps
Mike