FAQ:Compile

From GNU 68HC11/HC12
Revision as of 23:51, 25 January 2006 by Stephane.Carrez (Talk | contribs)
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?

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