FAQ:Compile

From GNU 68HC11/HC12
(Difference between revisions)
Jump to: navigation, search
(How can I inline assembly in C?)
(How can I access to the BSS start symbol?)
Line 29: Line 29:
  
 
===How can I access to the BSS start symbol?===
 
===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?===
 
===How can I put a function or global variable in my own section?===

Revision as of 23:51, 25 January 2006

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?

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

Optimizations

Personal tools