Example

Listing: Header file: a.h


#pragma CREATE_ASM_LISTING ON
typedef struct {

  short i;

  short j;

} Struct;

Struct Var;

void f(void);

#pragma CREATE_ASM_LISTING OFF

When the compiler reads this header file with the -La=a.inc a.h option, it generates the following:

Listing: a.inc file


Struct_SIZE         EQU $4
Struct_i           EQU $0

Struct_j           EQU $2

                XREF Var

Var_i              EQU Var + $0

Var_j              EQU Var + $2

                XREF f

You can now use the assembler INCLUDE directive to include this file into any assembler file. The content of the C variable, Var_i, can also be accessed from the assembler without any uncertain assumptions about the alignment used by the compiler. Also, whenever a field is added to the structure Struct, the assembler code must not be altered. You must, however, regenerate the a.inc file with a make tool.

Usually the assembler include file is not created every time the compiler reads the header file. It is only created in a separate pass when the header file has changed significantly. The -La option is only specified when the compiler must generate a.inc. If -La is always present, a.inc is always generated. A make tool will always restart the assembler because the assembler files depend on a.inc. Such a makefile might be similar to:

Listing: Sample makefile


a.inc : a.h
  $(CC) -La=a.inc a.h

a_c.o  : a_c.c a.h

  $(CC) a_c.c

a_asm.o : a_asm.asm a.inc

  $(ASM) a_asm.asm

The order of elements in the header file is the same as the order of the elements in the created file, except that comments may be inside of elements in the C file. In this case, the comments may be before or after the whole element.

The order of defines does not matter for the compiler. The order of EQU directives matters for the assembler. If the assembler has problems with the order of EQU directives in a generated file, the corresponding header file must be changed accordingly.