1
votes

I'm learning assembler and I've found this instruction

ADD     R0, R0, R0, LSL #1

I know that it multiplies by 3 the contents of R0 but I don't understand how it works (I don't know what LSL does in this case).

Thank you for your time

2
operands: Dest, Src1, Src2, optional shift. The operation is R0 = R0 + (R0 << 1) LSL = Logical Shift LeftBitBank
The forms and syntax of operands are pretty much the first thing any decent ARM assembly reference covers. Unless of course, given the title, you're looking at something entirely specific to Cortex-M0, since that doesn't understand this instruction either (it only supports a small subset of Thumb instructions, not including shifted-register forms).Notlikethat
@BitBank Thank you for your explanationCypert

2 Answers

6
votes

LSL means shift left.

So it does:

R0 = R0 + (R0 << 1) = R0 + R0 * 2
3
votes

LSL is a left shift operation which is performed by barrel shifter. Barrel shifter is a hardware provided in arm architecture and it is used to combine such operation to increase code density and execution speed.

For example in this case if addition and shifting (first left shift and then addition) is performed by two instruction then it will decrease the code density ( one extra instruction) and also on extra instruction to execute.

In this instruction both the operations are performed in same cycle.