This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

MSP430 inline assembly shift

Hi, everyone, I am currently working on a project which requires to shift the register file, for instance, R4.  I am trying to use asm("shl R4, 2") to logically shift R4 2 units on left. However, the compiler (IAR) just told me this is a "Bad label".

Does anyone has any idea about the correct expression for "shift left"?

  • I think the inline assembler tried to interpret "shl" as an assembly instruction. But it is not, and there is no white space in front of it, thus it tries to interpret "shl" as a label. And there is no such label, thus it must be a bad label.

    Follow the logic? Please look into User's Guide and find the assembly instruction that you want.
  • There is no shl 2 instruction.

    there is a rla that is actually just add r4,r4 (single shift left) 

    or rlc that is actually just addc r4,r4 if you want to shift carry in.
    if you do a bit #BITF,r4 before a rlc, you have your emulated rol

  • The syntax for shifting left a register left one step is "RLA.W R4". If you want to shift two steps you will need to emit two such instructions. Alternatively, if you are using a MSP430X device, you can use "RLAM.W #2, R4".

    Having said that, I'm curious to why you would like to do that in inline assembly. You can do the same in C using "x << 2".

        -- Anders Lindgren, IAR Systems

  • Thanks for you guys, the RLA and RLAM do works!

    However, there is still problem with my project. My initial is to load register file into fram, yet the register I observe from IAR is 20 bits like R4=0xAABDC. Each time when I try "mov", only the lower 16 bits "0xAADC" being loaded into Fram. I couldn't find way to load the first 4 bits "A" into Fram, so I want to use shift operation.

    When I try RLA or RLAM today, the data shifts, yet the first "A" of R4 turns into 0. Do you guys have any idea of what's wrong with this or how to load the first 4 bits into memory? Thanks!
  • You really need to read the Chapter about CPUX in the User's Guide.
  • You can use RLA.A and RRAL.A to work with the register as a 20 bit entity.

    As an alternative, you can use MOVA or MOVX.A to store a 20 bit value to memory, so there will be no need to shift anything.

    However, I'm still not convinced that this is the solution (even though it's not clear to me what you are trying to achieve). One way to store 20 bit values it to use intrinsic functions __data16_read_addr() -- see the compiler manual for more information.

        -- Anders Lindgren, IAR Systems

  • Thanks! I will read it.
  • Thanks! I have tested it and MOVX.A works. BTW, where can I find these assembly language that can be used on MSP430. Is it the same to 8050 Instruction Set?
  • chen pan said:
    where can I find these assembly language that can be used on MSP430. Is it the same to 8050 Instruction Set?

    You can find it in the Users Guide. There is one for each family of MSP430 devices which can be downloaded from the Ti web site, for example, www.ti.com/lit/ug/slau208o/slau208o.pdf

    And, no, the instruction of the MSP430 is not the same as the 8051. In fact, each microcontroller family typically has their own instruction set.

        -- Anders Lindgren, IAR Systems

  • Got it. Thanks a lot!

**Attention** This is a public forum