Mail Archives: djgpp/1997/01/16/22:50:52
Matthew Kennedy writes:
>I know that conceptually, the assembler code should be like this:
>
> movw __go32_info_block.selector_for_linear_memory, %fs
>
>
>This would assemble but fails upon linkage with an "undefined reference
>__go32_info_block.selector_for_linear_memory" message.
>
>I suspect that the assembler can't interpret fields of structures. In
>this case I'll have to use __go32_info_block+26 as the memory reference -
>which works. But thats harder to read as a program and the relative
>address (+26) might change in future versions. ANY IDEAS?
The problem is that as has no way of understanding C structure
definitions, so it can't know the offset. But there are workarounds...
If you compile your asm files with a capital .S extension, or use the -x
assembler-with-cpp flag to gcc, they get run through the C preprocessor
before they are sent to as, so you can use #include and #define
statements. You can't include C headers, but you can
#define SELECTOR_FOR_LINEAR_MEMORY 26
in a header, and then write:
movw __go32_info_block+SELECTOR_FOR_LINEAR_MEMORY, %fs
This still requires you to enter the offset in the header, but for the
asm code in Allegro I came up with another trick. Write a little C
program (look at the asmdef.c in Allegro), which includes all the
headers you need, understands the structure definitions so it knows all
the offsets, and then writes these offsets into an H file. Include this
H file in your asm code, and there you have it! If you set up the
makefile correctly, this header will get rebuilt whenever you change any
of the structure definitions it refers to, so it is nearly as good as AS
understanding C structures directly...
/*
* Shawn Hargreaves - shawn AT talula DOT demon DOT co DOT uk - http://www.talula.demon.co.uk/
* Ghoti: 'gh' as in 'enough', 'o' as in 'women', and 'ti' as in 'nation'.
*/
- Raw text -