EmbeddedRelated.com
Forums
The 2024 Embedded Online Conference

size of a byte and int?

Started by Neo January 25, 2005
Watch out, a byte is not always 8 bits.
In general, DSPs do not support 8 bit fetch modes like general purpose
processors do.
Most DSPs will only fetch multiples of the bus width.
The TI C54 is not capable of fetching an 8 bit word from memory.  It
can only fetch (or write) a 16 bit word from (or to) memory.
Because of that, the compiler for most DSPs define types so that any
type traditionally smaller then the bus width is the the size of the
bus width.

On a 32 bit DSP (such as the C3X), a byte, short int, and int are all
defined as 32 bits.

"Mark A. Odell" wrote:
> > bastian42@yahoo.com (42Bastian Schick) wrote in > news:41f61067.102320849@news.individual.de: > > >>Bytes or bits, depending on whether you want size or width. > >> > >>sizeof(char) is 1, by definition. > > > > Could be 2 on some DSPs (IIRC TI's). > > No, but maybe you're thinking of CHAR_BITS?
No, but maybe he's thinking of CHAR_BIT.
On Tue, 25 Jan 2005 18:25:26 GMT, the renowned Mike Harrison
<mike@whitewing.co.uk> wrote:

>On 25 Jan 2005 15:38:47 GMT, Grant Edwards <grante@visi.com> wrote: > >>On 2005-01-25, 42Bastian Schick <bastian42@yahoo.com> wrote: >>> On Tue, 25 Jan 2005 13:11:04 +0530, "Neo" >>><timeless_illusion@yahoo.com> wrote: >>> >>>>Hi All, >>>> >>>>Is that true that size of a byte not necessarily 8-bit? >>> >>> I think common sense is that a byte is nowadays 8 bit. >> >>Common sense is often wrong. As yours seems to be in this >>case. I've worked on architectures where a byte (a-la "C") was >>32 bits. >> >>> That's it, they speak of words avoiding the term byte. >> >>The OP is asking about C. In C, 'byte' has a very specific >>definition. > >A byte is ALWAYS 8 bits.
Actually, it's defined in C as "addressable unit of data storage large enough to hold any member of the basic character set of the execution environment". It goes on to say that the bits must be contiguous and that the number of bits are implementation-defined. It must be *at least* 8 bits (CHAR_BIT).
>A word is usually the larger of 16 or whatever the width of the processor bus.
I don't think "word" is defined in C. An "int" must be able to represent any signed number from -32767 to +32767 (inclusive), which means that it must have at least 16 bits. Best regards, Spehro Pefhany -- "it's the network..." "The Journey is the reward" speff@interlog.com Info for manufacturers: http://www.trexon.com Embedded software/hardware/analog Info for designers: http://www.speff.com
Grant Edwards <grante@visi.com> wrote in news:41f69625$0$2355$a1866201
@visi.com:

> On 2005-01-25, Mike Harrison <mike@whitewing.co.uk> wrote: >> On 25 Jan 2005 15:38:47 GMT, Grant Edwards <grante@visi.com> wrote: > >>>>>Is that true that size of a byte not necessarily 8-bit? >>>> >>>> I think common sense is that a byte is nowadays 8 bit. >>> >>>Common sense is often wrong. As yours seems to be in this >>>case. I've worked on architectures where a byte (a-la "C") was >>>32 bits. >>> >>>> That's it, they speak of words avoiding the term byte. >>> >>>The OP is asking about C. In C, 'byte' has a very specific >>>definition. >> >> A byte is ALWAYS 8 bits. > > Not in C. In C, a byte is the smallest addressible unit of > memory.
So, in a bit addressable processor, it's 1 bit? Certainly not in any implementation I've seen. -- Richard
On 2005-01-25, Richard <RichardRapier@netscape.net> wrote:

>>>>The OP is asking about C. In C, 'byte' has a very specific >>>>definition. >>> >>> A byte is ALWAYS 8 bits. >> >> Not in C. In C, a byte is the smallest addressible unit of >> memory. > > So, in a bit addressable processor, it's 1 bit? Certainly not in any > implementation I've seen.
I forgot to qualify my statement. IIRC, the spec says a byte has to be at least 8 bits. A compiler designer may be allowed to choose a byte size larger than an octet even if memory is adderssable in octets. He'd be a bit daft, IMO, but it may be legal... -- Grant Edwards grante Yow! I want to so HAPPY, at the VEINS in my neck STAND visi.com OUT!!
"Neo" <timeless_illusion@yahoo.com> wrote in message 
news:35mbgiF4pcd1dU1@individual.net...
> Hi All, > > Is that true that size of a byte not necessarily 8-bit?
veering off topic a bit.... Anybody else old enough to have worked on a machine with a 24 bit word and a 6 bit char? The first machine I learned assembler on was like that. With only 6 bits something had to give, and so it couldn't use lower case letters. Fortunately, they were all scrapped before they got around to implementing C on them. Peter
On 25 Jan 2005 15:38:47 GMT, Grant Edwards <grante@visi.com> wrote:

>Common sense is often wrong. As yours seems to be in this >case. I've worked on architectures where a byte (a-la "C") was >32 bits.
To up this, think PDP-10. 36 bits, unless using very special pointers to packed structures of five 7-bit ASCII, with a spare bit in the word. But that doesn't fit too well with C. Jon
Mike Harrison wrote:
> > A word is usually the larger of 16 or whatever the width of the
processor bus. It's easy to find exceptions to that rule (PDP-8, for instance). As stated in another recent thread, I think a better definition of word is register (GPR) width.
On 2005-01-25, Peter <moocowmoo@newprovidence.demon.co.uk> wrote:

> Anybody else old enough to have worked on a machine with a 24 > bit word and a 6 bit char?
No, but I did some homework assignments on a machine with a 60 bit word and a 6 bit char. -- Grant Edwards grante Yow! BRILL CREAM is at CREAM O' WHEAT in another visi.com DIMENSION...
<jkirwan@easystreet.com> wrote:
> <grante@visi.com> wrote: >>Common sense is often wrong. As yours seems to be in this >>case. I've worked on architectures where a byte (a-la "C") was >>32 bits. >To up this, think PDP-10. 36 bits, unless using very special pointers to packed >structures of five 7-bit ASCII, with a spare bit in the word. But that doesn't >fit too well with C.
( Or 4 9-bit characters. Doesn't fit the "all bytes are flat and 8 bits" theory either...) As other pointed out, many DSPs can access memory only one word at a time, and the word width is not necessarily a multiple of 8 bits. Plus: * CDC-6600 mainframes: 60 bit words. You could pack 10 6-bit bytes in each word, but they were not directly addressable. (6 bit was enough for a capital-letters-only reduced character set. FORTRAN and Pascal did not need more.) * Early HP-1000 mini-computers, 16 bit words, only word addressable. (I believe the same applies to early Nova minis) * PDP-8 minis (and Intersil 6100 copies) - 12 bit words, only word addressable. I once ported the original Small-C compiler to an HP-2113 mini. (May not be the right model number.) This one was an "advanced model", it had a couple of index registers and could address individual bytes. (No stack pointer, of course) To keep it compatible with existing software, it used the original instruction set with 15 bit addresses for a 32 Kword address space, while a few new instruction took 16 bit addresses for byte operations. In other words, the word at address N contained the two bytes at addresses (N*2) and (N*2)+1. A first attempt to make the compiler use byte addressing was soon discarded. Each memory address or pointer had to be shifted right one bit when accessing words or left untouched for byte access. At the end I made the chars 16 bit wide and used the word addresses consistently across the system. Was there ever a C compiler for CDC-6600/7??? machines? Roberto Waltman. [ Please reply to the group, return address is invalid ]

The 2024 Embedded Online Conference