www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/01/16/22:50:52

From: Shawn Hargreaves <Shawn AT talula DOT demon DOT co DOT uk>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: assembler and C structs - how do I interface them?
Date: Thu, 16 Jan 1997 20:12:44 +0000
Organization: None
Lines: 42
Distribution: world
Message-ID: <$2ls62A8uo3yEwNM@talula.demon.co.uk>
References: <Pine DOT HPP DOT 3 DOT 95 DOT 970114233606 DOT 14399A-100000 AT helios DOT usq DOT edu DOT au>
NNTP-Posting-Host: talula.demon.co.uk
MIME-Version: 1.0
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

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 -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019