user2018648
user2018648

Reputation:

ARM-Assembly: Arithmetic Shift / Logical Shift

I'm a bit stuck finding out in which way those 2 operations are different. So I read that Arithmetic shift is basically the same as Logical with the only difference, that it somehow keeps the highest or signed bit.

So when I do LSL #2 on 101110 assuming that this binary is a unsigned one, the result would be: 111000 and the carry bit would be set in the CPSR, right?

When I perform ASL #2 on the same number, what would be the result and how does it keep the signed bit? What about ASR #2 on the above binary? Would the result be 101011?

Unfortunately I've only found a really rough description about Arithmetic shift. Thanks in advance!

Upvotes: 3

Views: 26587

Answers (2)

Black Mamba
Black Mamba

Reputation: 15535

I had hard time to understand the real difference between LSR and ASR but hope this image helps you to understand the same. In LSR(Logical Shift Right) the MSB(Most Significant Bit) is replaced by 0 where as In ASR(Arithematic Shift Right) MSB is same as the earlier MSB before being shifted .(Similar for Left Shift) ASR is useful in computing with signed values in two-complement representation.

enter image description here

Upvotes: 5

zxxc
zxxc

Reputation: 355

Your examples don't make much sense since your numbers are 6bit only so 31st bit will always be 0.

ASL is a synonym for LSL and you can see shift operations behaviour in official ARM documentation or this ARM reference site.

Upvotes: 0

Related Questions