Search code examples
assemblyarmcortex-m

Shift right and Add in one command


I am learning assembly language for ARM Cortex and I have the following problem:

Write one line of assembly instruction for the following calculation: Apply Arithmetic Shift Right on the content of R2, then add the contents of R1 and R2 and store the result in R0.

I understand the Arithmetic Shift Right as:

ASR R0, R2, #9

And to do an add is simply:

ADD R0, R1, R2

But i am unsure how to combine these into one command. So far I have come up with the following from an example i saw that looked as if they were doing two commands on one line in a similar way:

ASR R0, R2, #9, [ADD R1, R2]

I know this is probably wrong, so can anyone explain to me how this should be done?


Solution

  • It seems that you are on the right track now.

    add rd, rn, rm, asr #n