Path: utzoo!utgpu!water!watmath!clyde!rutgers!cmcl2!brl-adm!umd5!eneevax!noise From: noise@eneevax.UUCP (Johnson Noise) Newsgroups: comp.lang.c Subject: Re: register unions Keywords: registers unions structures Message-ID: <1231@eneevax.UUCP> Date: 14 Feb 88 00:37:52 GMT References: <1229@eneevax.UUCP> <6831@ccv.bbn.COM> Reply-To: noise@eneevax.umd.edu.UUCP (Johnson Noise) Distribution: comp.lang.c Organization: Elec. Eng. Dept., U of Maryland, College Park, MD 20742 Lines: 52 In article <6831@ccv.bbn.COM> kgregory@ccv.bbn.com (Keith D. Gregory) writes: >In article <1229@eneevax.UUCP> noise@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?