home .. forth .. misc mail list archive ..

Structures in MISC code


C code tends to be very structure heavy (by "structure" I mean a template
for a block of memory with defined fields--what's called a "record" in
Pascal).  Accessing structure elements is usually done with a
BASE_REGISTER+immediate_offset addressing mode.  The immediate offset is
free in some instruction sets, like MIPS and PowerPC (because the offset is
always part of the instruction--zero if not needed).

I'm curious how MISC programmers deal with this, as accessing elements of a
structure using the A register can be messy.  Part of the solution is to not
use structures when there are better alternatives.  Sometimes it is better
to use parallel arrays, APL style, because then you can linearly zip through
only the data you need in a cache friendly way.  But other times you really
need to do lots of structure manipulation, and it can result in bulky code.
Maybe the bulk is not so bad; maybe it just looks bulky compared to a
reg+offset addressing mode?

(Simple structures can be handled with the autoincrementing A register.  For
example, an array of X,Y pairs can be processed linearly, first X, then Y,
rather than viewing it as an array of structures where Y is at the base
address+1.  The latter is the C view.)

I'm working on a vaguely Machine Forth-like language for the x86.  I am
trying to resist adding reg+offset style addressing, but I may cave in.

What techniques have MISC programmers developed for avoiding and/or dealing
with structures?

James