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.
Hello,
I just wanted to know if there is a way to declare an array in the assembly language. I am working on MSP430G2553 if it matters.
If you want to define an object that is accessible from C as an extern array, the answer is yes.
If you want to use array-like syntax in the assembler, the answer is no.
Can you be more specific on what exactly you are trying to do?
I saw this program in the Internet:
#include "msp430.h" ; #define controlled include file
NAME main ; module name
PUBLIC main ; make the main label vissible
; outside this module
ORG 0FFFEh
DC16 init ; set reset vector to 'init' label
RSEG CSTACK ; pre-declaration of segment
RSEG CODE ; place program in 'CODE' segment
init: MOV #SFE(CSTACK), SP ; set up stack
main: NOP ; main program
MOV.W #WDTPW+WDTHOLD,&WDTCTL ; Stop watchdog timer
BIS.B #0xFF,&P1DIR ; configure P1.x as output
BIS.B #0xFF,&P2DIR ; configure P2.x as output
BIS.B #0xFF,&P3DIR ; configure P3.x as output
BIS.B #0xFF,&P4DIR ; configure P4.x as output
MOV.W #arr1, R4 ; load the starting address of the array1 into the
register R4
MOV.W #arr2, R5 ; load the starting address of the array1 into the
register R4
; Sum arr1 and display
CLR R7 ; Holds the sum
MOV #8, R10 ; number of elements in arr1
lnext1: ADD @R4+, R7 ; get next element
DEC R10
JNZ lnext1
MOV.B R7, P1OUT ; display sum of arr1
SWPB R7
MOV.B R7, P2OUT
; Sum arr2 and display
CLR R7 ; Holds the sum
MOV #7, R10 ; number of elements in arr2
lnext2: ADD @R5+, R7 ; get next element
DEC R10
JNZ lnext2
MOV.B R7, P3OUT ; display sum of arr1
SWPB R7
MOV.B R7, P4OUT
JMP $
arr1 DC16 1, 2, 3, 4, 1, 2, 3, 4 ; the first array
arr2 DC16 1, 1, 1, 1, -1, -1, -1 ; the second array
END
But in this point I am just trying to do what he did in the last lines - arr1, arr2.
Thank you.
That's IAR assembly language, which TI doesn't support. You can declare the same arrays in TI assembly language like so:
arr1 .word 1, 2, 3, 4, 1, 2, 3, 4 ; the first array arr2 .word 1, 1, 1, 1, -1, -1, -1 ; the second array