Re: Passing an address to a #define in C

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Gus,

I need to put an specific machine code in any part of the memory. This code
is for some hardware module that can understand it. Of course, gcc will not
understand it, so I need to use .word 0xfc to create that code.

Now, I would like to create a pseudo assembler for my module, in following
way:

#define       LOAD         asm(".word 0xFC \n\t");
#define       INSTRUCTION2   asm(.word  0x4b \n\t");
#define       GOTO(label)         asm(".word " #label " \n\t");

Yes, this will not work this way. #label will stringify the input and will not produce an address.

Please do also keep in mind that .word might have different size depending on the target architecture the assembler is configured for.

void mycode(void) {

   LOAD
Label1:
   INSTRUCTION2
   GOTO(Label1)
}

It is generally possible to do use the asm() instruction for this purpose, but I'm not sure if this is the best approach.

I would possibly try to separate this code from the code generated by the compiler for the underlying CPU e.g. by putting these artificial instructions into a separate section and make this section executable by a linker script if executable permissions are required or to put this into the data segment if only read permissions are required.

The only benefit using the asm() to me is to put the data into an executable section, but the handling might be complex for your purpose since you don't use assembly mnemonics beside .word.



Hope that helps,
Andi


[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux