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.

Using variables in assembly code MSP430

I have two files in a project C_code and assembly code.

well my problem is that I would like to know if this two sentences are identical

unsigned char base; ----this sentence it is declared in C_code

first code sentences

IMPORT base

mov.w R6,&base

mov.w base,R8

second code sentence

mov.w R6,R8

The first sentences and second sentence are the same?

Thanks in advance

Miguel

  • Hi Miguel,

    Are you trying to convert the file from C to assembly for MSP430?

    I suggest referring to the following document on MSP430 Assembly Language Tools
    www.ti.com/.../slau131j.pdf

    Sincerely,
    Sean
  • No, they are not the same.

    The second "sentence" is simpler. It simply copies 16 bits of R6 to the corresponding bits of R8 (and clears its bit-19, 18, and 17 if they exist). This takes 1 MCL to execute.

    The first "sentence" will also copy 16 bits of R6 to the corresponding bits of R8 (and clears its bit-19, 18, and 17 if they exist). But takes 6 or 7 MCLs to execute. In addition, it will copy 8 of those bits into the c unsigned char "base" and the other 8 bits into the RAM location adjacent to that. This could be exactly what the c code expects. But more likely this will cause problems.
  • Hello old_cow_yellow,

    ok but, why it will cause problems?.

    Thank you for your answer

    Miguel

  • When C_code allocates:
    unsigned char base; ----this sentence it is declared in C_code
    It normally expects 8-bit of certain meaningful data to be stored or retried there. If the assembler code stores ether BIT0-BIT7 or BIT8-BIT15 of R6 there, it is probably not very meaningful. More damaging is that the assembly code stored the other 8-bit to the location adjacent to where base is.
    Of course, the programmer could have done this as a stunt deliberately. In that case it is not a problem but part of a trick where the code seems to do one thing but actually does something else.
  • Char is unsigned by default, though that is something you can change 99% of compilers have char set as unsigned.
    Char is a Byte (I guess from that ascii char is a 8bits)

    mov.w R6,&base........ move 16bit value from Register6  to RAM
    mov.w base,R8.......... move 16 bit value from RAM to Register8

    mov.w R6,R8..............move 16 bit value from Register6 to Register8

    it would say mov.b if it was a char.
    Though it's called move, it actually copy as source is left intact.

**Attention** This is a public forum