----- Ursprüngliche Nachricht -----
Von: Peter Bigot
Gesendet am: 07 Okt 2010 20:21:49


> Third time's the charm?  It's been so long since I've dealt with K&R C I've
> forgotten the rules.

> The behavior is correct.  char and short are upcast to int when no
> declaration is in scope.  Integral types that are larger than int are left
> as is.  That you're masking off all but the low byte does not change the
> type of the expression that's used as a parameter: it's a 32-bit int on a
> 16-bit microcontroller, and requires two registers to pass by value.

> No bug here.  Either explicitly cast to int, or make sure there's a
> declaration in scope so the compiler knows what to do.  I suggest the
> latter.

I always wondered why mspgcc does it this way.
It comes down to the little/big endian discussion.

The main advantage of little endianess is, that the first byte
contrains the LSB, no matter how large the datatype is.
So if you need the LSB only, just take the first byte and you're done.

Unfortunately, GCC was developed by people who obviously favorized
big endianess. And therefore R15 does not hold the lower word of a 
parameter, if the parameter exceeds 16 bit, it holds the upper 16 bits,
so the meaning of R15 changes and the callee may be hosed.

I wonder why a byte parameter is passed in the lower byte of R15 and not
the upper one by this logic. :)

My intuitive assumption was, that R15 would hold a short parameter as well as
the lower word of a long parameter and I was surprised to learn that id doesn't.
It makes passing return parameters from one funciton to another more
difficult (requiring moves when typecasting).

But well, it is as it is.

JMGross

------------------------------------------------------------------------------
Beautiful is writing same markup. Internet Explorer 9 supports
standards for HTML5, CSS3, SVG 1.1,  ECMAScript5, and DOM L2 & L3.
Spend less time writing and  rewriting code and more time creating great
experiences on the web. Be a part of the beta today.
http://p.sf.net/sfu/beautyoftheweb
_______________________________________________
Mspgcc-users mailing list
Mspgcc-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/mspgcc-users

Reply via email to