[A83] Re: Structs in asm


[Prev][Next][Index][Thread]

[A83] Re: Structs in asm




This is true in some cases.  However, using index registers uses a lot of
space.  Loading to A from HL, DE or BC takes one byte, as does a load into
any 8 bit register from HL.  Loading from an index register takes three
bytes.  That adds up very quickly.  You are much better off very carfully
analyzing exactly how you are using your data, and arrange it in the order
than you need to read and write to it.  For example, (x,y) coords usually go
as high and low bytes, respectively, of a 16 bit register.  Because these
are reversed in memory, you want to store y first, so that you can read it
as a 16 bit value and have it still be correct.

You make assembly code readable through the use of comments and descriptive
labels, not through the code.  When I program in high level languages, I
only comment function headers and data types, usually not the actual code
(unless it's for a university course, don't want to lose points to ignorant
and inexperienced TA's).  Well written code can document itself, if the
reader knows the overall goal of the code and the role of the data.
Assembly is completely different.  The goal is either speed, size or a
combination of the two, and usually writing readable code will get you
neither.  Take a look at the assembly code generated by any optimizing
compiler.  It is very doubtful that it is at all readable, probably less
than hand written assembly (which is why you always disable optimizations
when debugging).

> As Mr. Weiss suggested... loading into ix and using an offset is more
> efficient if you are planning on ever reading something other than
> everything in order of the data... and much more readable:

[snip]

> is much better than inc hl, and then dec hl... and that is on a very
simple
> a trivial data type.






References: