assemblymsp430code-composer

MSP430 assembly language: variable allocation error


Learning MSP430 Launchpad assembly language in class. The current assignment is to do stepwise multiplication and division (i.e. simulating them with recursive addition and subtraction).

I went over how to declare variables in assembly language with the professor, but the attempt threw errors when I tried to compile.

; Initialization Operations
Init:
            mov.b   m, R4   ;store m in R4
            mov.b   M, R5   ;store M in R5
            mov.w   #0, R6  ;store 0 in R6

for:
            add.w   R4, R6  ;add contents of R4 to P
            dec.w   R5      ;decrement R5
            jnz     for     ;jump to R4 until R5 is zero
exitFor:
            mov.w   R6, P   ;store R6 in P
            jmp     exitFor ;infinite loop
            nop             ; end program

; Variables for multiplication
            .data
m:          .byte   #40     ; multiplicand
M:          .byte   #5      ; multiplier
P:          .short          ; product

The errors are all below the .data directive. The m and M lines threw [E0200] Bad term in expression and [E0000] Commas must separate directive elements, and the P line threw [E0005] Operand missing. I'm having similar problems with the division version of the program.


Solution

  • From comment by Fuz:

    Note that assembly is assembled, not compiled. The error is that you have a leading # sign. This is wrong for directives. Directives do not have addressing modes and just take their arguments without decoration, e.g. .byte 40. For the .short directive, you forgot to give an initial value. Add that and it should work. (src)

    Well, that did it.

                .data
    m:          .byte   40      ; multiplicand
    M:          .byte   5       ; multiplier
    P:          .short  0       ; product
    

    Also I didn't originally initialize P because the lab instructions said to define but not initialize it. I didn't understand I needed to use .space or .bss to handle that, so strictly speaking the "correct" solution should be:

                .data
    m:          .byte   40      ; multiplicand
    M:          .byte   5       ; multiplier
    P:          .space  2       ; product