简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM