views:

63

answers:

2

disclaimer : I'm an asm newbie. I probably need to review my 2s complement or something to fully comprehend :(

I'm confused as to the purpose of the following:

....
BL some_func
MOV R3, R0,LSL#16
MOVS R3, R3,LSR#16
....

why the shift back? and the movs?

+2  A: 

In the left-shift, the bits overflowed will be lost. So all bits above 32-16 = 16th digit will be zeroed out after right-shift.

     r0 =                   aaaabbbbccccdddd eeeeffffgggghhhh
lsl, 16 -> aaaabbbbccccdddd eeeeffffgggghhhh 0000000000000000
             (overflowed)
        ->                  eeeeffffgggghhhh 0000000000000000
lsr, 16 ->                                   eeeeffffgggghhhh

The instruction is equivalent to

r3 = r0 & 0xffff;
KennyTM
that mostly answers my question ... at least the one I asked ;)One piece of data I left out was that r0 is a small value at that point so I dont see what is gained ... ive updated the question
fatbeard the pirate
nevermind ... coffee not working yet ... i get it :)
fatbeard the pirate
+2  A: 
dwelch
thanks for the detailed response...im still trying to grok it all ... i didn't write the original code, it is the result of a disassembly
fatbeard the pirate