delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/01/17/03:38:00

Newsgroups: comp.os.msdos.djgpp
From: Peter Berdeklis <peter AT atmosp DOT physics DOT utoronto DOT ca>
Subject: Re: assembler and C structs - how do I interface them?
Message-ID: <Pine.SGI.3.91.970116105006.11003B-100000@chinook.physics.utoronto.ca>
Nntp-Posting-Host: chinook.physics.utoronto.ca
Sender: news AT info DOT physics DOT utoronto DOT ca (System Administrator)
Mime-Version: 1.0
Organization: University of Toronto - Dept. of Physics
In-Reply-To: <Pine.HPP.3.95.970114233606.14399A-100000@helios.usq.edu.au>
Date: Thu, 16 Jan 1997 15:59:49 GMT
References: <Pine DOT HPP DOT 3 DOT 95 DOT 970114233606 DOT 14399A-100000 AT helios DOT usq DOT edu DOT au>
Lines: 35
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

On Wed, 15 Jan 1997, Matthew Kennedy wrote:

> 
> I'm building a an experimental ISR in GAS and I would like to access
> various parts of the BIOS data area (segment 0x40 etc).
> 
> I know that conceptually, the assembler code should be like this:
> 
>   movw __go32_info_block.selector_for_linear_memory, %fs
	                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^

The assembler knows nothing about struct member names, only replaces
variable names with addresses.  The assembler thinks that
__go32_info_block.selector_for_linear_memory is a single address label. 
The compiler changes structure member names with offsets added to the
address of the variable address.  In this case it would replace
_go32_info_block.selector_for_linear_memory with __go32_info_block+26,
which the assembler understands as 26 bytes after the address labeled
__go32_info_block. 

Personally I find it much easier to let the compiler do this kind of work 
for me - it's much less error prone.  Write your ISR in C first, adding 
asm statements to do things like saving registers.  Then compile the C 
code using the -S option to output the assembler which you can then edit 
appropriately.

As for your concern about the struct layout changing in the future, 
you'ld have the same problem with C.  The compiler also outputs 
__go32_info_block+26, so if the offset changes you'd have to recompile 
all you sources anyway.

---------------
Peter Berdeklis
Dept. of Physics, Univ. of Toronto

- Raw text -


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