FAQ:Compile

From GNU 68HC11/HC12
Jump to: navigation, search

Contents


Programming

How can I use the 68HC11/68HC12 IO ports?

The 68HC11 and 68HC12 IO ports are mapped in memory. This means that you don't need any special instruction to read or write to them. GEL defines the IO ports as follows:

 extern volatile unsigned char _io_ports[];

This defines an external unsigned char array which is mapped at the IO port addresses (0x1000 for 68HC11).

How can I inline assembly in C?

Gcc allows you to inline assembly within C source code. The assembly instruction can have input and output parameters to interact with the C code. An inline assembly without arguments is written as follows:

 asm volatile ("cli");

The volatile keyword is optional. It tells Gcc not to optimize the instruction by not removing or changing its place within the code. It is more than recommended to use it.

Input and output parameters are specified by constraints. The constraint is a string that indicates the characteristics of the operand in terms of constant, register, memory and so on. The output operands are listed first and introduced by =. The following instruction:

 asm volatile ("tpa\n\tsei" : "=d"(mask));

defines an output operand that is read from register d and put in the local variable named mask.

A more complete description about the asm mechanisms is presented in the following sections:

How can I access to the BSS start symbol?

The BSS start symbol (as well as some others) is defined by the linker. You can define it like this (char or unsigned char as you wish):

 extern char __bss_start[];

Then you are able to access the bss and get bss start address:

   char c = __bss_start[0];
   char* p = &__bss_start[0];

How can I put a function or global variable in my own section?

You can put a global variable or a function in your own section by using the gcc attribute specification.

For the variable you will do the following:

 char __attribute__ ((section (".page0"))) value;

and the value global variable will be defined within the .page0

Should I use 'extern inline' or 'static inline' in C?

Optimizations

How can I remove the frame pointer?

The frame pointer is removed by the following options:

 -Os -fomit-frame-pointer

The frame pointer can be removed in most cases. However, in some cases the compiler cannot remove it (this behavior is common to all processors supported by gcc).

In the following example:

 int get(int size)
 {
   int table[size];

   bar (table, size); 
   return table[0];
 }

the size of the array 'table' is not known at compile time but at run time. The table is allocated on the stack. Since it is necessary to restore the stack before the return, the frame pointer is kept and used for that.

How can gcc generate bset instructions?

I have this piece of code:

 unsigned char var;

 void foo() { var |= 4; }

and want to have a bset generated. How can I do that?

The compiler can generate bset instructions if you pass it the -mrelax option. In that case you must pass -mrelax for compiling and for linking. The instructions are then optimized during the link, if it turns out that the global variable is in page0.

Try compiling:

 unsigned char __attribute__((section ("page0"))) var;

 int main() { var |= 4; return 0; }

with -Os -mshort -fomit-frame-pointer -mrelax And do the m6811-elf-objdump -d on the final executable. You'll see that the global var is set using bset.

Personal tools