简体   繁体   English

在AC外部引用外部MSP430程序集.string

[英]Referencing an external msp430 assembly .string in a c extern

Programming the msp430, I have a string declared using the .string directive: 对msp430进行编程时,我使用.string指令声明了一个字符串:

message:    .string "Hello World"

I want to reference that outside the module, so I .def 'd it: 我想引用模块外,所以我.def倒是它:

            .def    message
message:    .string "Hello World"

In C, I want to reference the string, but get the wrong character: 在C语言中,我想引用字符串,但是得到错误的字符:

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[]; 使用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. 当您将其声明为指针时,是说message是一个仅占用2个字节内存并存储一个地址的值。 When declare it as array of char you're saying that's a sequence of 1 byte characters, which is what a string is. 当将其声明为char数组时,您要说的是一个1字节字符的序列,这就是字符串。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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