register unions
Johnson Noise
noise at eneevax.UUCP
Sun Feb 14 10:37:52 AEST 1988
In article <6831 at ccv.bbn.COM> kgregory at ccv.bbn.com (Keith D. Gregory) writes:
>In article <1229 at eneevax.UUCP> noise at eneevax.umd.edu.UUCP
>(Johnson Noise) writes:
>> [code examples deleted]
>>
>
>struct mystruct {
> char field1, field2, field3, field4;
> };
>
>union myunion {
> int field1;
> char field2[2];
> };
>
>
>The first example of course, would fail on the 68000 right away - you
>can't arbitrarily split a register into 4 bytes. The second is simply
>more of the same, and the key point is that structures and unions are
>manipulated using pointer arithmetic (to access the fields therein), and
>pointers to registers can not exist.
>
I understand now, but for slightly different reasons. In the
code examples I gave in my previous posting, pointer arithmetic was
not necessary to access the different fields. The problem is with
most/least significant byte/word.
move.b _blah, d0 /* and */
move.w _blah, d0
move data into the least significant part of the register. Where
move.b _blah, _there /* and */
move.w _blah, _there
move data into the most significant part of _there (assuming _there is
aligned to a longword address). This is obviously inconsistent. So
what about address registers (pointers)? Pointers and adresses are always
32 bits and occupy the same position whether in memory or registers.
Some examples:
68k assembly C source
movea _i, a0 a0.l = &i; i must be long
movea _j, a0 a0.w = &j; j must be short or long
movea _k, a0 a0.b = &k; k may be char, short, or long
move.b (a0)+, (a1)+ *a1.b++ = *a0.b++;
move.l -(a0), -(a1) *--a1.w = *--a0.w;
etc. Again, comments, flames?
More information about the Comp.lang.c
mailing list