Search code examples
cassemblyexternc-stringsmsp430

Referencing an external msp430 assembly .string in a c extern


Programming the msp430, I have a string declared using the .string directive:

message:    .string "Hello World"

I want to reference that outside the module, so I .def'd it:

            .def    message
message:    .string "Hello World"

In C, I want to reference the string, but get the wrong character:

extern char* message;

int main(void) {
    char c = *message; // First character of message is listed as 'z'
}

Any ideas about what might cause this? It compiles fine, and there are several functions in the assembly that I reference without a problem.


Solution

  • Use extern char message[];. When you declare it as a pointer you're saying message is a value that only takes 2 bytes of memory and stores an address. When declare it as array of char you're saying that's a sequence of 1 byte characters, which is what a string is.