We can guess, we can observe, and we can generalize. In the end, however, it is up to a C compiler (not the assembler) to determine how members are placed in a structure. In order to make assembly language programs access structures consistently, it is best to make a C program to print out those offsets.
For example, our structure can generate the following C code for this purpose:
When this program runs, it prints out all the symbol definitions to stdout. The output can be redirected to x.inc, which becomes the include file of assembly language source files. For example, an assembly language source file that needs to access struct X may start with the following line:
Any assembly language source file that has #include needs to be pre-processed. As such, it should end with an extension of .S instead of .s (upper case instead of lower case). A properly constructed Makefile should take care of this. See 0041 for more details.
Note that additional rules should be explicitly included in the Makefile to generate x.inc:
This also means that x_struct.c should be listed in CSRC (so that its dependency file can be automatically generated), but it should not be included in the dependency of the “normal” target. This can be done by explicitly listing the .o files needed by the “normal” target.