We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
How to define the following constant to an absolute address at 0x1000?
unsigned char code index[] = { 0x3, 0x5, 0x6 } ; //a constant mem in a file
The assembler provides the facility for locating objects at absolute addresses and optionally making those addresses public so your C program can use them by name. There is a template.a51 file in the c51/asm/ directory that provides much of the framework for you. You would use the "DB" (define byte) assembler directive to initialize code memory with 8-bit values. It's all described in your A51 and C51 manuals.
Or use the Linker to fix the address - that is, after all, the Linker's job!
Thanks for the hints. I know how to set an absolute address to a subroutine, a segment, or a variable. But for this constant ARRAY of CODE type, I just cannot make it work. Could any one give me an detailed example?
"I know how to set an absolute address to a subroutine, a segment, or a variable." Excellent! Not much of a stretch for you then. "But for this constant ARRAY of CODE type, I just cannot make it work." OK. Show us your examples, so we know what you are working from. "Could any one give me an detailed example?" Well, you have not told us which approach you are taking. For example, if you are going the assembler route an using its absolute addressing facility, I would thing if you merely took a look at the template.a51 (already mentioned), the c51/examples/asm/*.a51 files, c51/lib/init.a51, and start900.a51 to name a few, you would have some nice examples.
I think you need to create an ASM file and use the following code,
CSEG AT 0x1000 DB 0x03, 0x05, 0x06 END
Thanks for the suggestions. But what I need is using C language. I can define a code constant to an absolute address in C, using _at_ or cword micro. But for an ARRAY of CODE I can not find a way.
Create a separate source file for your array, for example "myarray.c". Under the "LX51 Locate" tab in the target options dialog put "?CO?MYARRAY(C:0x1234)" in the "User segments" box. Substitute your desired address where I put "0x1234". It's a real pity one can't just use the _at_ keyword with initialisers, isn't it? Stefan
Thanks, Stefan, it is working!