x86 ROL on ARM?

Nov 12, 2010 5 Replies

x86 ROL does this:



bit 0 to bit 1... bit 30 to bit 31 bit 31 to both bit 0 and carry flag.



Since I'm new to arm asm, is there a quick way of doing this? Or should I just change the algo to use ARM's ROR?


You can't do exactly the same in one instruction you can do either

"ROR provides the value of the contents of a register rotated by a value. The bits that are rotated off the right end are inserted into the vacated bit positions on the left."

"RRX provides the value of the contents of a register shifted right one bit. The old carry flag is shifted into bit[31]. If the S suffix is present, the old bit[0] is placed in the carry flag."

-p

Paul Gotch --------------------------------------------------------------------

ROR doesn't update the carry flag? (with bit 0)

Are you shifting just one bit at a time?

If so, could you use something like

ADD RO,RO ; shifts left one bit, zero in bit zero ADDC #0, R0 ; put the carry bit into bit zero

If you're shifing multiple bits, I'm not sure what significance the carry bit would have after you're done.

Being unfamiliar with the arm assembly language, I don't know if the above is either valid or proper syntax.

Mark Borgerson

Hmmm, except for the carry, could you you use ROR #31, R0 to get the equivalent of a 1-bit ROL?

Could you generalize that for ROL with more than one bit as something like ROR #(32-shift), RO?

I can see this one is going to cost me a sheet of paper---either that or I give up and just go have a drink while someone else thinks about it! ;-)

Mark Borgerson

Yes, one bit at a time!

My father told me the same thing yesterday, but, comming from the Z80 world, we both concluded that ADC will destroy the final carry flag. But not in ARM, since avery inctruction MAY have S suffix!

So, this should work: adds r2, r2, r2 ; shift & update carry adc r2, r2, #0 ; complete the shift, do not change carry

Thank you

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required