Re: RosAsm injects extra bytes into your data
- From: "Alex McDonald" <alex_mcd@xxxxxxxxxxxxxxx>
- Date: 27 Apr 2005 14:26:42 -0700
Betov wrote:
> "Alex McDonald" <alex_mcd@xxxxxxxxxxxxxxx> écrivait
> news:1114628472.109735.162400@xxxxxxxxxxxxxxxxxxxxxxxxxxxx:
>
> > Thank you. You wrote;
> >
> >> > The point of my "idea" is rather than injecting all these
padding
> > bytes
> >> > to align things, why not rearrange all the declarations to
> > *minimize*
> >> > the wasted space while maintaining the alignment the user
requests.
> >
> >> Because this would be unusable, for the Programmer.
> >
> >> (The ones who have already written a bit of Assembly
> >> will probably understand without explanations... :)
> >
> > I still don't understand this statement. Can you explain?
>
> As the sense of humour might vary from culture
> to culture, and as, maybe, some beginner would
> also not understand, here is a trivial example:
>
> [MyFirstData: DwordData: D§ ?]
> ;...
> ;...
> [WordData: W§ ? ?]
> ;...
> ;...
> [ByteData: B§ ? ? ? ? ? ? ? MyLastData: D§ ?]
> ;...
> ;...
>
> ; Clear My Data from 'MyFirstData' to 'MyLastData':
>
> mov eax 0, edi MyFirstData
> While edi < MyLastData | stosd | End_While
>
> :)
>
> Betov.
>
> < http://rosasm.org >
As a coding style, this is pretty ropey. There are several assumptions
the novice programmer that wrote this has made in the above code. A
sense of humour is required when reading it, that's for sure.
In no particular order;
.. The label MyLastData points to the _start_ of 4 bytes at the end of
the structure, not the end. MyLastData - MyFirstData is 4 bytes short
of the length.
.. The while end_while depends on a less-than test. The last four bytes
will not be cleared.
.. OK, so fix the two problems above (and I'm not sure that you can in
RosAsm because of a lack of equate support). Now the structure must be
a multiple of dwords in length if you use stosd, otherwise you'll
overrun the structure. Unless I'm missing something, your structure is
a byte short of dword alignment; there are 7 bytes prior to MyLastData.
MyLastData is not dword aligned.
.. As this isn't properly a structure (it has no enforced coherence;
it's a collection of structures), moving anything out from between the
MyFirstData and MyLastData won't get cleared and the programmer will
not get a warning. Why would anyone do that? Because it's not clear
this is a single structure.
.. Clearing unrelated structures and values by blitting like this is bad
practise. Believe me, I've dug through enough cruddy code like this to
know. What if some of the labels in this mess of data were floats?
Initialisation is done infrequently. Do it properly.
.. All the data must be in a single section (or does RosAsm only support
a single data section?).
A lot of the problems in this code boil down to RosAsm not properly
supporting structures, a lack of an equate type statement (as in
MyLastData equ * ), a lack of an automatically calculated length for
the structure, and poor programming style.
You're right when you say "Because this would be unusable, for the
Programmer". If the programmer's using RosAsm it's difficult to see how
to make it usable. Beginners beware.
--
Regards
Alex McDonald
.
- Follow-Ups:
- Re: RosAsm injects extra bytes into your data
- From: Betov
- Re: RosAsm injects extra bytes into your data
- From: \\\\o//annabee
- Re: RosAsm injects extra bytes into your data
- References:
- HLA v1.76 is now available
- From: randyhyde
- Re: HLA v1.76 is now available
- From: Betov
- Re: HLA v1.76 is now available
- From: randyhyde
- Re: HLA v1.76 is now available
- From: Betov
- RosAsm injects extra bytes into your data
- From: randyhyde
- Re: RosAsm injects extra bytes into your data
- From: Betov
- Re: RosAsm injects extra bytes into your data
- From: Alex McDonald
- Re: RosAsm injects extra bytes into your data
- From: Betov
- Re: RosAsm injects extra bytes into your data
- From: Alex McDonald
- Re: RosAsm injects extra bytes into your data
- From: Betov
- Re: RosAsm injects extra bytes into your data
- From: Alex McDonald
- Re: RosAsm injects extra bytes into your data
- From: Betov
- HLA v1.76 is now available
- Prev by Date: Re: Optimizing Static Variable Layout
- Next by Date: Re: RosAsm injects extra bytes into your data
- Previous by thread: Re: RosAsm injects extra bytes into your data
- Next by thread: Re: RosAsm injects extra bytes into your data
- Index(es):
Relevant Pages
|