Newsgroups: comp.os.msdos.djgpp From: Peter Berdeklis Subject: Re: assembler and C structs - how do I interface them? Message-ID: Nntp-Posting-Host: chinook.physics.utoronto.ca Sender: news AT info DOT physics DOT utoronto DOT ca (System Administrator) Mime-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Organization: University of Toronto - Dept. of Physics In-Reply-To: Date: Thu, 16 Jan 1997 15:59:49 GMT References: 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