gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

ASM > Dealing with structures

#11573 - poslundc - Sat Oct 11, 2003 4:25 pm

I'm writing some code that gets passed a pointer to a struct from a C function.

I can easily index the necessary amount into memory to get the field I'm looking for, but I'm apprehensive about doing so in case the struct gets modified in the future.

Is there a simple strategy for dealing with C structs in ASM?

Thanks,

Dan.

#11574 - tepples - Sat Oct 11, 2003 4:45 pm

The simple strategy I'd use is write your code in C, reserve some space in your structs for future expansion, and don't refactor the assembly language until your algorithms and data structures are well settled. This approach has seemed to work for developers of operating systems, who have had to maintain application binary interface (ABI) compatibility for years at a time.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#11575 - poslundc - Sat Oct 11, 2003 4:47 pm

tepples wrote:
The simple strategy I'd use is write your code in C, reserve some space in your structs for future expansion, and don't refactor the assembly language until your algorithms and data structures are well settled. This approach has seemed to work for developers of operating systems, who have had to maintain application binary interface (ABI) compatibility for years at a time.


OK, but how do you deal with poor planning on the kind of level I force onto myself, where I often end up reshuffling and deleting my structure members? ;)

Dan.

#11576 - sajiimori - Sat Oct 11, 2003 5:36 pm

I can't think of any way around the synchronization chores you'll have to do between the C and asm code, but one way to make it easier on yourself would be to define a constant for each element of the struct, the value of which is the offset into the struct.

Then you'd only have to change the constants when you reorganize your struct, as long as your asm code doesn't make any implicit assumptions about the relative locations of the entries.

#11583 - poslundc - Sat Oct 11, 2003 7:24 pm

During my crazy searches I managed to find a great FAQ on this exact subject, which suggests some methods for automating most (albeit not quite all) of struct management in ASM, which I hope others will find useful as well:

http://www.ifi.uio.no/~inf3150/tfaq2.html

(It's the last question on the page.)

Dan.